Description
基于Student(学生)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Student_Cadre(学生兼干部)。
这两个基类均继承自Person类,包含姓名、年龄、性别、地址、电话等数据成员。在Student类中还包含数据成员major(专业),在Cadre类中还包含数据成员post(职务),
在Student_Cadre类中还包含数据成员wages(工资)。
注意使用虚基类使Student_Cadre只包含一份从Person类继承来的成员。
Input
学生干部的姓名,年龄,性别,专业,职位,地址,电话,薪水
修改该学生干部的新地址,新电话
Output
学生干部的信息
Sample Input
wangli
23
f
BeijingRoad
0532-61234567
software
president
1534.2
Taidonglu
0532-90827651
0531-28766143
Sample Output
name:wangli
age23
sex:f
address:BeijingRoad
tel:0532-61234567
major:software
post:president
wages:1534.2
name:wangli
age23
sex:f
address:Taidonglu
tel:0531-28766143
major:software
post:president
wages:1534.2
HINT
Append Code
int main( )
{
string name, major, post, addr, tel;
int age;
char sex;
float wage;
cin>>name>>age>>sex>>addr>>tel>>major>>post>>wage;
Student_Cadre st_ca(name, age, sex, addr, tel, major, post,wage);
st_ca.display( );
cout<<endl;
string newAddr, newTel1, newTel2;
cin>>newAddr>>newTel1>>newTel2;
st_ca.setAddr(newAddr);
st_ca.Student::setTel(newTel1);
st_ca.Cadre::setTel(newTel2);
st_ca.display( );
return 0;
}
#include<iostream>
#include <cstdio>
#include <cstring>
using namespace std;
class Person
{
private:
string name;
string tel;
int age;
string add;
char sex;
public:
Person(string _name,int _age,char _sex,string _add,string _tel):name(_name),age(_age),sex(_sex),tel(_tel),add(_add){}
~Person(){}
string getname(){return name;}
string gettel(){return tel;}
int getage(){return age;}
string getadd(){return add;}
char getsex(){return sex;}
void setname(string _n){name=_n;}
void setTel(string _t){tel=_t;}
void setage(int _a){age=_a;}
void setAddr(string _ad){add=_ad;}
void setsex(char _s){sex=_s;}
};
class Student:virtual public Person
{
private:
string major;
public:
Student(string _name,int _age,char _sex,string _add,string _tel,string _major):Person(_name,_age,_sex,_add,_tel),major(_major){}
~Student(){}
string getmajor(){return major;}
void setmajor(string _m){major=_m;}
};
class Cadre:virtual public Person
{
private:
string post;
public:
Cadre(string _name,int _age,char _sex,string _add,string _tel,string _post):Person(_name,_age,_sex,_add,_tel),post(_post){}
~Cadre(){}
string getpost(){return post;}
void setpost(string _p){post=_p;}
};
class Student_Cadre:virtual public Student,virtual public Cadre
{
private:
float wages;
public:
Student_Cadre(string _name,int _age,char _sex,string _add,string _tel,string _major,string _post,float _wage):Person(_name,_age,_sex,_add,_tel),Student(_name,_age,_sex,_add,_tel,_major),Cadre(_name,_age,_sex,_add,_tel,_post)
{
wages=_wage;
}
float getwages(){return wages;}
void setwages(float _w){wages=_w;}
void display()
{
cout<<"name:"<<getname()<<endl<<"age"<<getage()<<endl;
cout<<"sex:"<<getsex()<<endl<<"address:"<<getadd()<<endl;
cout<<"tel:"<<gettel()<<endl<<"major:"<<getmajor()<<endl;
cout<<"post:"<<getpost()<<endl<<"wages:"<<getwages()<<endl;
}
};