#include<iostream>
#include<string>
using namespace std;
class Person//定义一个基类
{
protected:
string name;
int age;
char sex;
string address;
long telephone;
public:
Person(const string a, int b, char s, const string add, long tel);
};
Person::Person(const string a, int b, char s, const string add, long tel) :name(a), age(b), sex(s), address(add), telephone(tel) {}
class Teacher :virtual public Person//教师类
{
public:
string title;//职称
Teacher(const string a, int b, char s, const string add, long tel, const string tit);
void display();
};
Teacher::Teacher(const string a, int b, char s, const string add, long tel, const string tit) :Person(a, b, s, add, tel), title(tit) {}
void Teacher::display()
{
cout << "姓名为:" << name << endl;
cout << "年龄为:" << age << endl;
cout << "性别为:" << sex << endl;
cout << "地址为:" << address << endl;
cout << "电话为:" << telephone << endl;
cout << "职称为:" << title << endl;
}
class Cadre :virtual public Person//干部类
{
public:
string post;//职务
Cadre(const string a, int b, char s,const string add,const long tel, string post);
void display();
};
Cadre::Cadre(const string a, int b, char s, const string add, long tel, const string post) :Person(a, b, s, add, tel), post(post) {}
void Cadre::display()
{
cout << "姓名为:" << name << endl;
cout << "年龄为:" << age << endl;
cout << "性别为:" << sex << endl;
cout << "地址为:" << address << endl;
cout << "电话为:" << telephone << endl;
cout << "职务为:" << post << endl;
}
class Teacher_Cadre :public Teacher, public Cadre//教师兼干部类
{
public:
int wages;//工资
Teacher_Cadre(const string a, int b, char s, const string add, long tel, const string tit, const string post, int w);
void show();
};
Teacher_Cadre::Teacher_Cadre(const string a, int b, char s, const string add, long tel, const string tit, const string post, int w) :Person(a, b, s, add, tel), Teacher(a, b, s, add, tel, tit), Cadre(a, b, s, add, tel, post), wages(w) {}
void Teacher_Cadre::show()
{
Teacher::display();
cout << "工资为:" << wages << endl;
}
int main()
{
Teacher_Cadre m("李华", 36, "男", "湖北大学教工处", 123456, "英语老师", "教导主任", 6000);
m.show();
system("pause");
return 0;
}
代码如上