c++多重继承

#include <iostream>

using namespace std;
class teacher
{
public:
    teacher(){}
    teacher(int a,string s):age(a),job(s){}
    void show()
    {
        cout<<age<<'\t'<<job<<endl;
    }

protected:
    int age;
    string job;
};
class student
{
public:
    student(){}
    student(string n,int a,int s):name(n),age(a),score(s){}
    void show()
    {
        cout<<name<<'\t'<<age<<'\t'<<score<<endl;
    }

protected:
    string name;
    int age;
    int score;
};
class Graduate:public student,public teacher
{
public:
    Graduate(){}
    Graduate(int b,string s,string n,int a,string l):teacher(b,s),student(n,b,a),sex(l){}
    void show()
    {
        cout<<name<<'\t'<<teacher::age<<'\t'<<sex<<'\t'<<job<<'\t'<<score<<endl;
    }
private:
    string sex;
};

int main()
{
    Graduate g1(18,"doctor","zhangsan",100,"m");
    g1.show();
    cout << "Hello World!" << endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值