.编写一个小型公司人员工资管理程序,要求设计合理的基类和派生类,实现工资管理任务。下表是公司经理,兼职人员,销售经理和销售人员当月工资计算方法。
这是工资管理中很简单的程序,在此基础上可以做很多的完善。
人员类别 固定工资/元 | 计时工资(元/时) 月销售总额提成 |
---|---|
公司经理 15000 | 无 无 |
兼职人员 无 | 180 无 |
– | – |
销售经理 5000 | 无 1% |
销售员 无 | 无 6% |
– | – |
代码如下:
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person(int f, int h, double c);
~Person()
{
cout << "析构执行成功!" << endl;
}
double wage_calculation(int t, float ts);
private:
int fixed_wage;
int hourly_wage;
double commission;
int hour;
float Total_Sales;
};
Person::Person(int f, int h, double c)
{
fixed_wage = f;
hourly_wage = h;
commission = c;
}
double Person::wage_calculation(int t, float ts)
{
double total;
total = fixed_wage + hourly_wage * t + commission * ts;
return(total);
}
class Company_manager :public Person
{
public:
Company_manager(int f, int h, double c) :Person(f, h, c) {}
};
class partime_staff :public Person
{
public:
partime_staff(int f, int h, double c) :Person(f, h, c) {}
};
class Sales_manager :public Person
{
public:
Sales_manager(int f, int h, double c) :Person(f, h, c) {}
};
class saleperson :public Person
{
public:
saleperson(int f, int h, double c) :Person(f, h, c) {}
};
int main()
{
string title;
int hour;
float Total_Sales;
cout << "Please enter the 销售总额:"; cin >> Total_Sales;
cout << endl;
cout << "Please choose the 职位:"; cin >> title;
cout << endl;
//职位的选择和总额的输入
if (title == "公司经理")
{
Company_manager cm(15000, 0, 0);
cout << "公司经理本月的工资:" << cm.wage_calculation(0, Total_Sales) << endl;
}
else if (title == "兼职人员")
{
cout << "Please enter the working hours:";
cin >> hour;
partime_staff ps(0, 180, 0);
cout << "兼职人员本月的工资:" << ps.wage_calculation(hour, Total_Sales) << endl;
// 按每小时180元计费,工作了几天,每天几个小时
}
else if (title == "销售经理")
{
Sales_manager sm(5000, 0, 0.01);
cout << "销售经理本月的工资:" << sm.wage_calculation(0, Total_Sales) << endl;
}
else if (title == "销售员")
{
saleperson se(0, 0, 0.06);
cout << "销售员本月的工资:" << se.wage_calculation(0, Total_Sales) << endl;
}
return 0;
}
输出示例如下: