• 实验9:Problem I: 学生干部虚基类


    注意看提示语句:注意使用虚基类使Student_Cadre只包含一份从Person类继承来的成员。

    课本中有类似的题目!

    Home Web Board ProblemSet Standing Status Statistics
     
    Problem I: 学生干部虚基类

    Problem I: 学生干部虚基类

    Time Limit: 1 Sec  Memory Limit: 2 MB
    Submit: 1296  Solved: 802
    [Submit][Status][Web Board]

    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

    [Submit][Status][Web Board]
    #include<iostream>
    using namespace std;
    class Person{
    public:
        string name;
        int age;
        char sex;
        string address;
        string phone;
    };
    class Student:virtual public Person{
    public:
        string major;
        void setAddr(string newAdd){address=newAdd;}
        void setTel(string newPhone){phone=newPhone;}
    };
    class Cadre:virtual public Person{
    public:
        string post;
        void setAddr(string newAdd){address=newAdd;}
        void setTel(string newPhone){phone=newPhone;}
    };
    class Student_Cadre:virtual public Student,virtual public Cadre{
    public:
        double wage;
    void setAddr(string newAdd){address=newAdd;}
        ///void setTel(string newPhone){phone=newPhone;}
    void display(){cout<<"name:"<<name<<endl<<"age"<<age<<endl<<"sex:"<<sex<<endl<<"address:"<<address<<endl<<"tel:"<<phone<<endl<<"major:"<<major<<endl<<"post:"<<post<<endl<<"wages:"<<wage<<endl;}
    Student_Cadre(string n,int a,char s,string add,string tel,string m,string pos,double w){name=n;age=a;sex=s;address=add;phone=tel;major=m;post=pos;wage=w;}
    };
    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;
    }
  • 相关阅读:
    你一定想知道的关于FPGA的那些事
    浅谈乘法器的用法
    “FPGA+云"助力高性能计算
    Lattice并购案&我国FPGA发展路径
    双口RAM,值得研究
    FPGA图像加速解决方案来了
    中断中需要面对的问题(二)
    中断中需要面对的问题(一)
    Spring MVC 笔记--配置基于JavaConfig
    Spring IOC/ AOP 笔记
  • 原文地址:https://www.cnblogs.com/auto1945837845/p/5447317.html
Copyright © 2020-2023  润新知