目录
代码:
#include <iostream>
#include <string>
using namespace std;
class student
{
public:
student(){}
student(string n,int a,int sc):name(n),age(a),score(sc){}
void show()
{
cout<<"name:"<<name<<'\t'<<"age:"<<age<<
'\t'<<"score:"<<score<<endl;
}
protected:
string name;
int age;
int score;
};
class teacher
{
public:
teacher(){}
teacher(int a,string j):age(a),job(j){}
void show()
{
cout<<"age:"<<age<<'\t'<<"job:"<<job<<endl;
}
protected:
int age;
string job;
};
class graduate:public student,public teacher
{
public:
graduate(){}
graduate(string n,int a,int sc,string j,char s):student(n,a,sc),teacher(a,j),sex(s){}
void show()
{
cout<<"name:"<<student::name<<'\t'<<"age:"<<teacher::age<<'\t'
<<"sex:"<<sex<<endl;
}
private:
char sex;
};
int main()
{
graduate g1("zhangsan",24,98,"graduate",'F');
g1.show();
teacher t1(34,"math teacher");
t1.show();
student s1("lisi",20,89);
s1.show();
return 0;
}
执行结果: