实验目的:多重继承
* 程序头部注释开始
* 程序的版权和版本声明部分
* 烟台大学计算机学院学生
* 文件名称:
* 作
* 完成日期:
* 版本号:
#include <iostream>
#include<string>
using namespace std;
class Teacher
{
public:
Teacher(string nam,int a ,char s,string ad, int te,string t)
{
name = nam;
age = a;
sex = s;
add = ad;
tel = te;
title = t;
}
~Teacher(){};
void display();
protected:
string name;
int age;
char sex;
string add;
int tel;
string title;
};
class Cadre
{
public:
Cadre(string nam,int a ,char s,string ad, int te,string p)
{
name = nam;
age = a;
sex = s;
add = ad;
tel = te;
post = p;
}
~Cadre(){};
protected:
string name;
int age;
char sex;
string add;
int tel;
string post;
};
class Teacher_Cadre:public Teacher,public Cadre
{
public:
Teacher_Cadre(string nam,int a ,char s,string ad, int te,string t,string p,float w):Teacher(nam,a,s,ad,te,t),Cadre(nam,a,s,ad,te,p),wages(w){}
void show();
private:
float wages;
};
int main()
{
Teacher_Cadre T_C("hubin", 20, 'm', "yantaidaxue", 182531," tejijiaoshi"," gongwuyuan", 5000);
T_C.show();
system("pause");
return 0;
}
void Teacher::display()
{
cout<<"mane:"<<Teacher::name<<endl;
cout<<"age:"<<Teacher::age<<endl;
cout<<"sex:"<<Teacher::sex<<endl;
cout<<"add:"<<Teacher::add<<endl;
cout<<"tel:"<<Teacher::tel<<endl;
cout<<"title:"<<Teacher::title<<endl;
}
void Teacher_Cadre::show()
{
Teacher::display();
cout<<"post:";
cout<<post<<endl;
cout<<"wages:"<<wages<<endl;
}
截图:
mane:hubin
age:20
sex:m
add:yantaidaxue
tel:182531
title: tejijiaoshi
post: gongwuyuan
wages:5000
请按任意键继续. . .
继承多了,虽然有点不适应,但功能还是挺大的。