定义一个学生类:成员-->姓名、年龄、成绩以及相关函数
#include <iostream>
#include <string>
using namespace std;
class man
{
public:
man(){}
man(int a):age(a){}
protected:
int age;
};
class student:virtual public man
{
public:
student(){}
student(string s,int a,int sc):man(a),name(s),score(sc){}
protected:
string name;
int score;
};
class teacher:virtual public man
{
public:
teacher(){}
teacher(int a,string s):man(a),title(s){}
protected:
string title;
};
class postgraduate:public student,public teacher
{
public:
postgraduate(){}
postgraduate(string name,int a,int sc,string title,string gender):\
student(name,a,sc),teacher(a,title),man(a),gender(gender){}
void show()
{
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<gender<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"职称:"<<title<<endl;
cout<<"成绩:"<<score<<endl;
}
protected:
string gender;
};
int main()
{
postgraduate p1("张三",24,114,"研究生","男");
p1.show();
return 0;
}