您的位置:首页 > 编程语言 > C语言/C++

c++第五次上机实验第二题

2016-05-06 11:40 471 查看
#include<iostream>

#include<string>

using namespace std;

class Person

{
string name;
int age;
string sex;

public:  

    Person() {}  

    void setname(string na)  

    {  

        name=na;  

    }  

    void setage(int a)  

    {  

        age=a;  

    }  

    string getname()  

    {  

        return name;  

    }  

    int getage()

    {  

        return age;  

    }  

    void setsex(string a)

    {  

        sex=a;

    } 
string getsex()

    {  

        return sex;

    } 

};

class Teacher: virtual public Person

{
string title;

public:

  void settitle(string a)

    {  

        title=a;

    } 
string gettitle()

    {  

        return title;

    } 

};

class Cadre:virtual public Person

{
string post;

public:

  void setpost(string pt)

    {  

        post=pt;

    } 
string getpost()

    {  

        return post;

    } 

};

class Teacher_Cadre: public Teacher,public Cadre

{

   int waves;

   public:

  void setwaves(int    a)

    {  

        waves=a;

    } 
int getwaves()

    {  

        return waves;

    } 

};

int main()

{

    Teacher_Cadre c;
c.setname("曾辉");

    c.setage(42);

    c.setsex("男");

    c.setpost("副教授");

    c.setwaves(1540);

 cout<<c.getname()<<endl<<c.getage()<<endl<<c.getsex()<<endl<<c.getpost()<<endl<<c.getwaves()<<endl;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: