12.2多重继承

#include <iostream>

using namespace std;
class Teacher
{
    public:
    Teacher(string nam,int a,string se,string adr,string te,string tit)
    {
        name=nam;
        age=a;
        sex=se;
        adress=adr;
        tel=te;
        title=tit;
    }
    void show();
    private:
    string name;
    int age;
    string sex;
    string adress;
    string tel;
    string title;
};
void Teacher::show()
{
    cout<<"姓名:"<<name<<"年龄:"<<age<<"性别:"<<sex<<"住址:"<<adress<<"电话:"<<tel;
    cout<<"职称:"<<title<<endl;
}
class Cadre
{
   public :
   Cadre(string nam,int a,string se,string adr,string te,string pos)
    {
        name=nam;
        age=a;
        sex=se;
        adress=adr;
        tel=te;
       post=pos;
    }
   void show1();
   private:
    string name;
    int age;
    string sex;
    string adress;
    string tel;
    string post;
};
 void Cadre::show1()
 {
     cout<<"姓名:"<<name<<"年龄:"<<age<<"性别:"<<sex<<"住址:"<<adress<<"电话:"<<tel;
    cout<<"职务:"<<post<<endl;
 }
class Teacher_Cadre: public Teacher,public Cadre
{
    public:
    Teacher_Cadre (string nam,int a,string se,string adr,string te,string pos,int wag):Teacher(nam,a,se,adr,te,pos),Cadre(nam,a,se,adr,te,pos)
    {
        wages=wag;
    }
    void show2();
   private:
   int wages;
};
void Teacher_Cadre::show2()
{
    show();
    show1();
    cout<<"工资:"<<wages<<endl;
}
int main()
{
    Teacher ter("wangying",20,"women","weifang","199873543","CEO");
    ter.show();
    Teacher_Cadre tea("wangfei",20,"women","weifang","199873543","monitor",500);
    tea.show2();
    return 0;
}

你可能感兴趣的:(C++,类,对象,Class)