📄 p394 11.9 多重继承.cpp
字号:
#include<iostream>
#include<string>
using namespace std;
class Teacher
{
protected:
string name;
int age;
char sex;
string address;
int telephone;
string title;
public:
Teacher(string n,int a,char s,string add,int tele,string tit)
:name(n),age(a),sex(s),address(add),telephone(tele),title(tit){}
virtual void display();
};
void Teacher::display()
{
// cout<<"the information of the teacher: "<<endl;
cout<<"the name: "<<name<<endl;
cout<<"the age: "<<age<<endl;
cout<<"the sex: "<<sex<<endl;
cout<<"the address: "<<address<<endl;
cout<<"the telephone: "<<telephone<<endl;
cout<<"the title: "<<title<<endl;
}
class Cadre
{
protected:
string name;
int age;
char sex;
string address;
int telephone;
string post;
public:
Cadre(string n,int a,char s,string add,int tele,string p)
:name(n),age(a),sex(s),address(add),telephone(tele),post(p){}
void display();
};
void Cadre::display()
{
// cout<<"the information of the Cadre: "<<endl;
cout<<"the name: "<<name<<endl;
cout<<"the age: "<<age<<endl;
cout<<"the sex: "<<sex<<endl;
cout<<"the address: "<<address<<endl;
cout<<"the telephone: "<<telephone<<endl;
cout<<"the position: "<<post<<endl;
}
class Teacher_Codre: public Teacher,public Cadre
{
private:
float wages;
public:
Teacher_Codre(string n,int a,char s,string add,int tele,string p,string tit,float w)
:Teacher(n,a,s,add,tele,tit),Cadre(n,a,s,add,tele,p),wages(w){}
virtual void display();
};
void Teacher_Codre::display()
{
Teacher::display();
cout<<"the position: "<<post<<endl;
cout<<"the wages: "<<wages<<endl;
}
int main()
{
Teacher t("wangli",56,'f',"lin nan road 343 ",123950395,"professor");
Teacher_Codre mix("wangli",56,'f',"lin nan road 343 ",123950395,"monitor","professor",30493);
Teacher *p=&t;
p->display();
cout<<endl;
p=&mix;
p->display();
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -