#include "iostream"
#include "string"
#include "list"
using namespace std;
class Student
{
protected:
string Name;
string Num;
string Major;
public:
Student(){}
Student(string Na, string Nu, string Ma)
:Name(Na), Num(Nu), Major(Ma)
{}
Student(Student const& st)
:Name(st.Name), Num(st.Num), Major(st.Major)
{}
virtual void display()
{
cout << "Name:" << Name << endl;
cout << "Num:" << Num << endl;
cout << "Major:" << Major << endl;
}
};
class UnderGrad : public Student
{
protected:
public:
UnderGrad(){}
UnderGrad(string Na, string Nu, string Ma)
:Student(Na, Nu, Ma)
{}
virtual void display()
{
cout << "本科生" << endl;
cout << "Name:" << Name << endl;
cout << "Num:" << Num << endl;
cout << "Major:" << Major << endl;
}
};
class Graduate : public Student
{
protected:
string Teacher;
public:
Graduate(){}
Graduate(string Na, string Nu, string Ma, string Te)
:Student(Na, Nu, Ma), Teacher(Te)
{}
virtual void display()
{
cout << "研究生" << endl;
cout << "Name:" << Name << endl;
cout << "Num:" << Num << endl;
cout << "Major:" << Major << endl;
cout << "Teacher:" << Teacher << endl;
}
};
void Create(list<Student*> &L)
{
cout << "输入创建数量" << endl;
int n = 0;
cin >> n;
char c = '0';
for(int i = 0; i < n; ++i)
{
cout << "1.本科生" << endl;
cout << "2.研究生" << endl;
cin >> c;
switch(c)
{
case '1' :
{
cout << "本科生" << endl;
cout << "姓名" << endl;
string Na;
cin >> Na;
cout << "学号" << endl;
string Nu;
cin >> Nu;
cout << "专业" << endl;
string Ma;
cin >> Ma;
Student* p = NULL;
p = new UnderGrad(Na, Nu, Ma);
L.push_back(p);
break;
}
case '2' :
{
cout << "研究生" << endl;
cout << "姓名" << endl;
string Na;
cin >> Na;
cout << "学号" << endl;
string Nu;
cin >> Nu;
cout << "专业" << endl;
string Ma;
cin >> Ma;
cout << "导师" << endl;
string Te;
cin >> Te;
Student* p = NULL;
p = new Graduate(Na, Nu, Ma, Te);
L.push_back(p);
break;
}
default:
{
cout << "输入错误" << endl;
break;
}
}
}
}
void Traveal(list<Student*> const &L)
{
for(auto i = L.begin(); i != L.end(); ++i)
{
(*i) -> display();
cout << endl;
}
}
int main(int argc, char const *argv[])
{
list<Student*> L;
Create(L);
Traveal(L);
L.clear();
return 0;
}