继承类的运用

来源:互联网 发布:软件接口的分类 编辑:程序博客网 时间:2024/05/16 05:24
#include<iostream>#include<string>using namespace std;typedef char strings[20];class employee{private:    strings mname;    double msalary;    strings mbirthday;public:    char* getname()    {        return mname;    }    void setname(strings name)    {        strcpy(mname, name);    }    double getsalary()    {        return msalary;    }    void setsalary(double salary)    {        msalary = salary;    }    char* getbirthday()    {        return mbirthday;    }    void setbirthday(strings birthday)    {        strcpy(mbirthday, birthday);    }};//继承类的函数class maneget :public employee{private:    double mbonus;public:    double getbonus()    {        return mbonus;    }    void setbonus(double bonus)    {        mbonus = bonus;    }};int main(){    employee employ;    employ.setname("张三");    employ.setsalary(1000);    employ.setbirthday("19910-4546");    maneget manager;    manager.setname("明日科技");    manager.setbirthday("2651*-545");    manager.setsalary(45465);    manager.setbonus(2999);    //输出员工的属性    cout << "员工的姓名" << employ.getname() << endl;    cout << "员工的姓名" << employ.getbirthday() << endl;    cout << "员工的姓名" << employ.getsalary() << endl;    cout << "员工的姓名" << manager.getname() << endl;    cout << "员工的姓名" << manager.getbirthday() << endl;    cout << "员工的姓名" << manager.getsalary() << endl;    cout << "员工的姓名" << manager.getbonus() << endl;    system("pause");    return 0;}
0 0
原创粉丝点击