c++第六次实验

来源:互联网 发布:5ghz网络设置 编辑:程序博客网 时间:2024/05/20 11:23

一、问题及代码

/*文件名称:sss.cpp         * 作    者:谭皓文         * 完成日期:2016年 5月13日         * 版 本 号:v1.0         * 对任务及求解方法的描述部分:分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部) * 程序输出:略       * 问题分析;略       */    #include<iostream>      #include<string>       using namespace std;     class Teacher    {    public:        Teacher(string n, int a, char s, string add, long int te, string ti);        void display();    protected:        string name;        int age;        char sex;        string address;        long int tel;        string title;  //职称  };      class Cadre    {    public:        Cadre(string n, int a, char s, string add, long int t, string p);        void display();    protected:        string name;        int age;        char sex;        string address;        long int tel;        string post;  //职务  };      class Teacher_Cadre:public Teacher, public Cadre  //声明多重继承的Teacher_Cadre类   {    public:        Teacher_Cadre(string n, int a, char s, string add, long int t, string ti, string p,double w);        void show();    protected:        double wages;    };      Teacher::Teacher(string n, int a, char s, string add, long int te, string ti)    {        name = n;        age = a;        sex = s;         address = add;        tel = te;        title = ti;    }      Cadre::Cadre(string n, int a, char s, string add, long int t, string p)    {        name = n;        age = a;        sex = s;         address = add;        tel = t;        post = p;    }      void Teacher::display()    {        cout << "name: " << name << endl;        cout << "age: " << age << endl;        cout << "sex: " << sex << endl;        cout << "address: " << address << endl;        cout << "tel: " << tel << endl;        cout << "title: " << title << endl;    }      void Cadre::display()    {        cout << "name: " << name << endl;        cout << "age: " << age << endl;        cout << "sex: " << sex << endl;        cout << "address: " << address << endl;        cout << "tel: " << tel << endl;        cout << "post: " << post << endl;    }      void Teacher_Cadre::show()  //在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数  {        Teacher::display();        cout << "post: " << Cadre::post << endl;  //对两个基类中的数据成员用相同的名字,在引用这些数据成员时,指定作用域      cout << "wages: " << wages << endl;    }      Teacher_Cadre::Teacher_Cadre(string n, int a, char s, string add, long int t, string ti, string p,double w):Teacher(n, a, s, add, t, ti),Cadre(n, a, s, add, t, p)    {        wages = w;    }


0 0