The basic category of student cadres

Posted by SoreE yes on Fri, 15 Nov 2019 21:25:08 +0100

Problem D: the basic category of student cadres
Time Limit: 1 Sec Memory Limit: 2 MB
Submit: 2763 Solved: 1855
[Submit][Status]
Description
Based on the student class and the Cadre class, the new class student and Cadre (student and Cadre) is derived from these two classes by multiple inheritance.
These two base classes inherit from the Person class, including data members such as name, age, gender, address, phone, etc. The Student class also contains the data member major (Major), and the Cadre class contains the data member post (job),
The data member waves (wages) is also included in the student ABCD cadre class.
Note that the virtual base class is used to make student_ucadre contain only one member inherited from the Person class.
Input
Name, age, gender, major, position, address, telephone number and salary of student cadres

Change the new address and phone number of the student cadre

Output
Information of student cadres

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

#include <iostream>
#include <string>
using namespace std;
class Person
{
protected:
    string _name,_addr,_tel;
    int _age;
    char _sex;
public:
    Person(string n,int a,char s,string add,string t):_name(n),_age(a),_sex(s),_addr(add),_tel(t)
    {


    }
    ~Person()
    {}
};
class Student:virtual public Person
{
protected:
   string _major;
public:
    Student(string n,int a,char s,string add,string t,string m):Person(n,a,s,add,t),_major(m)
    {}
    void setTel(string newTel1)
    {
        _tel=newTel1;
    }
    ~Student()
    {}

};
class Cadre:virtual public Person
{
protected:
    string _post;

public:
    Cadre(string n,int a,char s,string add,string t,string p):Person(n,a,s,add,t),_post(p)
    {}
    void setTel(string newTel2)
    {
        _tel=newTel2;
    }
    ~Cadre()
    {}
};
class Student_Cadre:public Student,public Cadre
{
protected:
    float _wage;
public:
    Student_Cadre(string n,int a,char s,string add,string t,string m,string p,float w):Student(n,a,s,add,t,m),Cadre(n,a,s,add,t,p),Person(n,a,s,add,t),_wage(w)
    {}
    void display( )
    {
        cout<<"name:"<<_name<<endl;
        cout<<"age"<<_age<<endl<<"sex:"<<_sex<<endl<<"address:"<<_addr<<endl<<"tel:"<<_tel<<endl<<"major:"<<_major<<endl<<"post:"<<_post<<endl<<"wages:"<<_wage<<endl;
    }
    void setAddr(string newAddr)
    {
        _addr = newAddr;
    }
    void setTel(string newTel2)
    {
        _tel=newTel2;
    }
    ~Student_Cadre(){}

};

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;
}