“姓名”和“性别”是教师、学生共有的属性,“职称”和“工资”是教师特有的属性, “班级”和“成绩”是学生特有的。 请用类模拟

#include <iostream>
using namespace std;

class person 
{
    public:
        person(string a,string b)
        {
            name = a;
            sex = b;
            cout << __func__ << ":" << __LINE__ << endl;
        }
        ~person()
        {
            cout << __func__ << ":" << __LINE__ << endl;
        }
        void get_show()
        {
            cout<<"姓名:"<<name<<endl;

            cout<<"性别:"<<sex<<endl;
        }
    private:
        string name;
        string sex;
};

class teacher:public person
{
    public:
        teacher(string a,string b,int sa,string ra):person(a,b)
        {
            salary = sa;
            rank = ra;
            cout << __func__ << ":" << __LINE__ << endl;
        }
        ~teacher()
        {
            cout << __func__ << ":" << __LINE__ << endl;
        }
        void get_show1()
        {
            cout<<"教师:"<<endl;

            get_show();

            cout<<"职称:"<<rank<<endl;

            cout<<"工资:"<<salary<<endl;

            cout<<endl;
        }

    private:
        int salary;
        string rank;

};

class student:public person
{
    public:
        student(string a,string b,string c,float s):person(a,b)
        {
            score = s;
            stu_cla = c;
            cout << __func__ << ":" << __LINE__ << endl;
        }
        ~student()
        {
            cout << __func__ << ":" << __LINE__ << endl;
        }

        void get_show2()
        {
            cout<<"学生:"<<endl;

            get_show();

            cout<<"班级:"<<stu_cla<<endl;

            cout<<"成绩:"<<score<<endl;

            cout<<endl;
        }
    private:
        int score;
        string stu_cla;
};

int main()
{
    teacher tea("周sir","男",5000,"教师");

    tea.get_show1();

    student stu("张三","男","19-1",99);

    stu.get_show2();
    return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值