- 教师干部类。 设计两个基类:教师类(Teacher)、干部类(Cadre),采用多重继承派生出新类:Teacher_Cadre
(a)两个基类都包含:姓名、年龄、性别、地址、电话; 在Teacher类中包含:title(职称),在Cadre类中包含:post(职务),在Teacher_Cadre中包含:wages(工资); (b)两个基类都包含:display()函数,分别输出本类中的成员信息; (c)在两个基类中的姓名、年龄、性别、地址和电话数据成员使用相同名字,在派生类中引用这些数据成员时,采用指定作用域的方式; (d)在派生类Teacher_Cadre的成员函数Show()中调用Teacher类中的display()函数,输出姓名、年龄、性别; (e)使用对象数组保存输入的对象;如建立工程命名为6_2,如建立一个源文件命名为6-2.cpp。[测试数据] (a)姓名:zhang 年龄:20 性别:male 地址:Build 305-503 电话:6081202 职称:tutor(助教) 职务:普通职工 (b)姓名:chen 年龄:38 性别:male 地址:Build 3A-302 电话:6088132 职称:associate professor(副教授) 职务:副院长 (c)姓名:fan 年龄:30 性别:female 地址:Build 2A-202 电话:6088099 职称:lectuer(讲师) 职务:教研室主任
#include
using namespace std;
class Teacher
{
protected:
string name;//姓名
int age;// 年龄
string sex;//性别
string address;//住址
int telephone;//电话
string title;//职称
public:
Teacher(string a=“zhang”, int b=20, string c=“male”, string d=“Build 305-503”, int e= 6081202, string f=“tutor”)
{
name = a; age = b; sex = c; address = d; telephone = e; title = f;
}
void display()
{
cout << name << “的年龄是:” << age << “,性别:” << sex << “,家庭住址:” << address << “,电话是:” << telephone
<< “,职称是:” << title << endl;
}
};
class Cadre
{
protected:
string name;//姓名
int age;// 年龄
string sex;//性别
string address;//住址
int telephone;//电话
string post;//职务
public:
Cadre(string a = “zhang”, int b = 20, string c = “male”, string d = “Build 305-503”, int e = 6081202,
string f = “associate professor”)
{
name = a; age = b; sex = c; address = d; telephone = e; post = f;
}
void display()
{
cout << name << “的年龄是:” << age << “,性别:” << sex << “,家庭住址:” << address << “,电话是:” << telephone
<< “,职务是:” << post << endl;
}
};
class Teacher1 : virtual public Teacher {};
class Cadre1 : virtual public Cadre {};
class Teacher_Cadre : public Teacher1, public Cadre1
{
int wages;//工资
public:
Teacher_Cadre(){};
void exchage(string a,int b,string c,string d,int e,string f,string g,int h)
{
Teacher::name=a;Teacher::age=b;Teacher::sex=c;Teacher::address=d;Teacher::telephone=e;Teacher::title=f;
Cadre::name=a;Cadre::age=b;Cadre::sex=c;Cadre::address=d;Cadre::telephone=e;Cadre::post=g;
wages=h;
}
void show()
{
Teacher::display();
}
};
int main()
{
Teacher_Cadre m[3];
string a[3],c[3],d[3],f[3],g[3];
int b[3],e[3],h[3];
for(int i=0;i<3;i++)
{
cin>>a[i]>>b[i]>>c[i]>>d[i]>>e[i]>>f[i]>>g[i]>>h[i];
}
for (int i = 0; i < 3; i++)
{
m[i].exchage(a[i],b[i],c[i],d[i],e[i],f[i],g[i],h[i]);
m[i].show();
}
system("pause");
return 0;
}
希望各位大佬能给点意见(_)ノ