定义Staff(员工)类,由Staff分别派生出Saleman(销售员)类和Manager(经理)类,再由Saleman(销售员)类和Manager(经理)类采用多重继承方式派生出新类SaleManager(销售经理)类。
要求:
(1)在Staff类中包含的数据成员有编号(num)、姓名(name)、出勤率(rateOfAttend)、基本工资(basicSal)和奖金(prize)。在Saleman类中还包含数据成员销售员提成比例(deductRate)和个人销售额(personAmount),在Manager类中还包含数据成员经理提成比例(totalDeductRate)和总销售额(totalAmount)。在SaleManager类中不包含其它数据成员。
(2)各类人员的实发工资
销售经理实发工资 =基本工资 + 奖金 * 出勤率 + 个人销售额 * 销售员提成比例+ 总销售额 * 经理提成比例
(3)每个类都有构造函数、输出基本信息函数(Output)和输出实发工资函数(OutputWage)。
#include<iostream>
#include <string>
using namespace std;
class Staff
{
public:
Staff(int S_num,string S_name, double S_rateOfAttend, int S_basic, int S_Salprize);
void Output();
void OutputWage();
int prize;
private:
int num;
string name;
double rateOfAttend;
int basic;
int Salprize;
};
Staff::Staff(int S_num, string S_name, double S_rateOfAttend, int S_basic, int S_Salprize)
{
num = S_num;
name = S_name;
rateOfAttend = S_rateOfAttend;
basic = S_basic;
Salprize = S_Salprize;
prize = (int)(basic+ Salprize* rateOfAttend);
}
void Staff::Output()
{
cout << "员工编号:" << num << endl;
cout << "员工姓名:" << name << endl;
cout << "出勤率:" << rateOfAttend << endl;
cout << "基本工资:" << basic << endl;
cout << "奖金:" << Salprize << endl;
}
void Staff::OutputWage()
{
cout << "实际工资:" << prize << endl;
}
class Saleman:virtual public Staff
{
public:
Saleman(int S_num, string S_name, double S_rateOfAttend, int S_basic, int S_Salprize, double S_deductRate, int S_personAmount);
void Output();
void OutputWage();
double deductRate;
int personAmount;
};
Saleman::Saleman(int S_num, string S_name, double S_rateOfAttend, int S_basic, int S_Salprize, double S_deductRate, int S_personAmount):Staff(S_num,S_name,S_rateOfAttend, S_basic,S_Salprize)
{
deductRate = S_deductRate;
personAmount = S_personAmount;
prize = (int)(prize + deductRate * personAmount);
}
void Saleman::Output()
{
Staff::Output();
cout << "销售员提成比例:" << deductRate << endl;
cout << "个人销售额:" << personAmount << endl;
}
void Saleman::OutputWage()
{
cout << "实际工资:" << prize << endl;
}
class Manager:virtual public Staff
{
public:
Manager(int M_num, string M_name, double M_rateOfAttend, int M_basic, int M_Salprize, double M_totalDeductRate, int M_totalAmount);
void Output();
void OutputWage();
double totalDeductRate;
int totalAmount;
};
Manager::Manager(int M_num, string M_name, double M_rateOfAttend, int M_basic, int M_Salprize, double M_totalDeductRate, int M_totalAmount) :Staff(M_num, M_name, M_rateOfAttend, M_basic, M_Salprize)
{
totalDeductRate = M_totalDeductRate;
totalAmount = M_totalAmount;
prize = (int)(prize + totalDeductRate * totalAmount);
}
void Manager::Output()
{
Staff::Output();
cout << "经理提成比例:" << totalDeductRate << endl;
cout << "总销售额:" << totalAmount << endl;
}
void Manager::OutputWage()
{
cout << "实际工资:" << prize << endl;
}
class SaleManager:virtual public Saleman,public Manager
{
public:
SaleManager(int SM_num,string SM_name, double SM_rateOfAttend, int SM_basic, int SM_Salprize, double S_deductRate, int S_personAmount, double M_totalDeductRate, int M_totalAmount);
void Output();
void OutputWage();
};
SaleManager::SaleManager(int SM_num, string SM_name, double SM_rateOfAttend, int SM_basic, int SM_Salprize, double S_deductRate, int S_personAmount, double M_totalDeductRate, int M_totalAmount):Staff(SM_num, SM_name, SM_rateOfAttend, SM_basic, SM_Salprize),Saleman(SM_num, SM_name, SM_rateOfAttend, SM_basic, SM_Salprize,S_deductRate,S_personAmount ),Manager(SM_num, SM_name, SM_rateOfAttend, SM_basic, SM_Salprize, M_totalDeductRate, M_totalAmount)
{
prize = (int)(prize + totalDeductRate * totalAmount+ deductRate * personAmount);
}
void SaleManager::Output()
{
Staff::Output();
cout << "销售员提成比例:" << deductRate << endl;
cout << "个人销售额:" << personAmount << endl;
cout << "经理提成比例:" << totalDeductRate << endl;
cout << "总销售额:" << totalAmount << endl;
}
void SaleManager::OutputWage()
{
cout << "实际工资:" << prize << endl;
}
int main(void) {
Staff a(101, "Zhang", 0.9, 2000, 3000);
a.Output();
a.OutputWage();
cout << endl;
Saleman b(201, "Sun", 0.9, 3000, 4000, 0.1, 10000);
b.Output();
b.OutputWage();
cout << endl;
Manager c(301, "Li", 0.9, 4000, 5000, 0.1, 20000);
c.Output();
c.OutputWage();
cout << endl;
SaleManager d(401, "Wu", 1, 5000, 6000, 0.1, 10000, 0.05, 40000);
d.Output();
d.OutputWage();
return 0;
}