Time Limit: 1 Sec Memory Limit: 2 MB
Submit: 1736 Solved: 1135
[Submit][Status][Web Board]
基于Student(学生)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Student_Cadre(学生兼干部)。
这两个基类均继承自Person类,包含姓名、年龄、性别、地址、电话等数据成员。在Student类中还包含数据成员major(专业),在Cadre类中还包含数据成员post(职务),
在Student_Cadre类中还包含数据成员wages(工资)。
注意使用虚基类使Student_Cadre只包含一份从Person类继承来的成员。
学生干部的姓名,年龄,性别,专业,职位,地址,电话,薪水
修改该学生干部的新地址,新电话
学生干部的信息
wangli
23
f
BeijingRoad
0532-61234567
software
president
1534.2
Taidonglu
0532-90827651
0531-28766143
name:wangli
age23
sex:f
address:BeijingRoad
tel:0532-61234567
major:software
post:president
wages:1534.2name:wangli
age23
sex:f
address:Taidonglu
tel:0531-28766143
major:software
post:president
wages:1534.2
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<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
#include
using namespace std;
class Person
{
public:
string name_(){return name;}
int age_(){return age;}
char sex_(){return sex;}
string address_(){return address;}
string tel_(){return tel;}
void getname(string a){name = a;}
void getage(int b){age = b;}
void getsex(char c){sex = c;}
void getaddress(string d){address = d;}
void gettel(string e){tel = e;}
public:
Person(string a,int b,char c,string d,string e){
getname(a);
getage(b);
getsex(c);
getaddress(d);
gettel(e);
}
private:
string name;
int age;
char sex;
string address;
string tel;
};
class Student:virtual public Person
{
public:
string major_(){return major;}
void getmajor(string f){major = f;}
public:
Student(string a,int b,char c,string d,string e,string f):Person(a,b,c,d,e){
getmajor(f);
}
public:
void setTel(string x){
gettel(x);
}
private:
string major;
};
class Cadre:virtual public Person
{
public:
string post_(){return post;}
void getpost(string g){post = g;}
public:
Cadre(string a,int b,char c,string d,string e,string g):Person(a,b,c,d,e){
getpost(g);
}
public:
void setTel(string x){
gettel(x);
}
private:
string post;
};
class Student_Cadre:public Student,public Cadre
{
public:
double wages_(){return wages;}
void getwages(double h){wages = h;}
public:
Student_Cadre(string a,int b,char c,string d,string e,string f,string g,double h):Person(a,b,c,d,e),Student(a,b,c,d,e,f),Cadre(a,b,c,d,e,g)
{
getwages(h);
}
public:
void setAddr(string x)
{
getaddress(x) ;
}
void display( )
{
cout<<"name:"<"age"<"sex:"<"address:"<"tel:"<"major:"<"post:"<"wages:"<private:
double wages;
};
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<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;
}