文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C++程序习题-多重继承[5.9]

C++程序习题-多重继承[5.9]

时间:2010-11-25  来源:chengxiaopeng

#include <iostream>
using namespace std;

class Teacher
{
    public:
    Teacher(string,int,char,string,string,string);
    void display();
    
    private:
    string name;
    int age;
    char sex;
    string address;
    string phone;
    string title;
};
Teacher::Teacher(string name,int age,char sex,string address,string phone,string titile)
:name(name),age(age),sex(sex),address(address),phone(phone),title(title){}
void Teacher::display()
{
    cout << name << endl;
    cout << age << endl;
    cout << sex << endl;
    cout << address << endl;
    cout << phone << endl;
    cout << title << endl;
}

class Cadre
{
    public:
    Cadre(string name,int age,char sex,string address,string phone,string post);
    void display();
    
    private:
    string name;
    int age;
    char sex;
    string address;
    string phone;
    protected:
    string post;
};

Cadre::Cadre(string name,int age,char sex,string address,string phone,string post)
:name(name),age(age),sex(sex),address(address),phone(phone),post(post){}
void Cadre::display()
{
    cout << name << endl;
    cout << age << endl;
    cout << sex << endl;
    cout << address << endl;
    cout << phone << endl;
    cout << post << endl;
}

class Teacher_Cadre:public Teacher,public Cadre
{
   public:
   Teacher_Cadre(string name,int age,char sex,string address,string phone,string post,string title,int wages):
                        Teacher(name,age,sex,address,phone,title),
                        Cadre(name,age,sex,address,phone,post),wages(wages)
                        {}
   void show();
   private:
   int wages;
};

void Teacher_Cadre::show()
{
    Teacher::display();
    cout << "post:" << Cadre::post<< "wages:" << wages << endl;
}
int main()
{
    Teacher_Cadre tc("xiaopeng",26,'M',"zhengzhou","13526568417","ceo","teacher",2300);
    tc.show();
    system("pause");
    return 0;
}


    上面的代码,编译时没有错误。但在执行时,dos窗口自动关闭。一直查不清原因。愿高手刚我调试,并告诉我原因。谢谢了。
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载