12-2 教师兼干部

来源:互联网 发布:如何重新注册淘宝账号 编辑:程序博客网 时间:2024/06/08 09:03
/** 作    者: 霍雨佳* 完成日期:2014 年5月13日* 版 本 号:v1.0* 问题描述:分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。* 样例输入:* 样例输出:* 项目要求:*(1)在两个基类中都包含姓名、年龄、性别、地址、电话等数据成员。*(2)在Teacher类中还包含数据成员title(职称),在Cadre类中还包含数据成员post(职务),在Teacher_Cadre类中还包含数据成员wages(工资)。*(3)对两个基类中的姓名、年龄、性别、地址、电话等数据成员用相同的名字,在引用这些数据成员时,指定作用域。*(4)在类体中声明成员函数,在类外定义成员函数。*(5)在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数,输出姓名、年龄、性别、职称、地址、电话,然后再用cout语句输出职务与工资。*/#include <iostream>using namespace std;class Teacher   //教师类{    protected:    string name;    int age;    int sex;//0 表示女,1 表示男    string addr;    string phone;    string title;//职称    public:    Teacher(string nam,int ag,int se,string id,string ph,string titl):name(nam),age(ag),sex(se),addr(id),phone(ph),title(titl){}    void display();};class Cadre  //(干部)类{     protected:    string name;    int age;    int sex;//0 表示女,1 表示男    string addr;    string phone;    string post;//职务    public:    Cadre(string nam,int ag,int se,string id,string ph,string pos):name(nam),age(ag),sex(se),addr(id),phone(ph),post(pos){}    void show();};class Teacher_Cadre:public Teacher,public Cadre{    private:    int wages;//(工资)    public:    Teacher_Cadre(string nam,int ag,int se,string id,string ph,string titl,string pos,int wage):Teacher(nam,ag,se,id,ph,titl),Cadre(nam,ag,se,id,ph,pos),wages(wage){}    void show1();};void Teacher::display(){    cout<<"name:                "<<name<<endl;    cout<<"age:                 "<<age<<endl;    cout<<"sex(0:women,1:man):  "<<sex<<endl;    cout<<"addr:                "<<addr<<endl;    cout<<"phone:               "<<phone<<endl;    cout<<"title:               "<<title<<endl;}void Cadre::show(){    cout<<"name:                "<<name<<endl;    cout<<"age:                 "<<age<<endl;    cout<<"sex(0:women,1:man):  "<<sex<<endl;    cout<<"addr:                "<<addr<<endl;    cout<<"phone:               "<<phone<<endl;    cout<<"post:                "<<post<<endl;}void Teacher_Cadre::show1(){    display();    cout<<"post:                "<<post<<endl;    cout<<"wages:               "<<wages<<endl;}int main(){    Teacher_Cadre T("霍霍",21,0,"linyi","188*****","student","student",8000);    T.show1();    return 0;}


运行结果:

 

没有做不到的,加油!!!

 

 

 

0 0