#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;
}
继承类的运用
最新推荐文章于 2022-11-17 09:19:25 发布