要求:
(1)在Staff类中包含的数据成员有编号(num)、姓名(name)、出勤率(rateOfAttend)、基本工资(basicSal)和奖金(prize)。在Saleman类中还包含数据成员销售员提成比例(deductRate)和个人销售额(personAmount),在Manager类中还包含数据成员经理提成比例(totalDeductRate)和总销售额(totalAmount)。在SaleManager类中不包含其它数据成员。
(2)各类人员的实发工资公式如下:
员工实发工资 = 基本工资 + 奖金 * 出勤率
销售员实发工资 = 基本工资 + 奖金 * 出勤率+ 个人销售额 * 销售员提成比例
经理实发工资 = 基本工资 + 奖金 * 出勤率+ 总销售额 * 经理提成比例
销售经理实发工资 =基本工资 + 奖金 * 出勤率+ 个人销售额 * 销售员提成比例+ 总销售额 * 经理提成比例
(3)每个类都有构造函数、输出基本信息函数(Output)和输出实发工资函数(OutputWage)。
#include"iostream" using namespace std; class Staff{ private: int num; char name[18]; double rateofattend; int basicSal; int prize; public: Staff(int a,char *b,double c,int d,int e):num(a),rateofattend(c),basicSal(d),prize(e){ strcpy(name,b); } void Output(){ cout << num << " " << name << " " << rateofattend << " " << basicSal << " " << prize << " "; } double OutputWage(){ return (basicSal+prize*rateofattend); } }; class Salemen:virtual public Staff{ private: double deductRate; double personAmount; public: Salemen(int a,char *b,double c,int d,int e,double f,double g):Staff(a,b,c,d,e),deductRate(f),personAmount(g){}; void Output(){ Staff::Output(); cout << deductRate << " " << personAmount << " " ; } void display(){ cout << deductRate << " " << personAmount << " " ; } double OutputWage(){ return (Staff::OutputWage()+deductRate*personAmount); } }; class Manager:virtual public Staff{ private: double totalDeductRate; double totalAmount; public: Manager(int a,char *b,double c,int d,int e,double f,double g):Staff(a,b,c,d,e),totalDeductRate(f),totalAmount(g){}; void Output(){ Staff::Output(); cout << totalDeductRate << " " << totalAmount << " " ; } void display(){ cout << totalDeductRate << " " << totalAmount << " " ; } double OutputWage(){ return (Staff::OutputWage()+totalDeductRate*totalAmount); } }; class SaleManager:public Salemen,public Manager { public: SaleManager(int a,char *b,double c,int d,int e,double f,double g,double h,double i):Salemen(a,b,c,d,e,h,i),Manager(a,b,c,d,e,f,g),Staff(a,b,c,d,e){} void Output(){ Staff::Output(); Salemen::display(); Manager::display(); } double OutputWage(){ return (Salemen::OutputWage()+Manager::OutputWage()-Staff::OutputWage()); } }; void main() { Staff a(1,"liu",1,1000,500); a.Output(); a.OutputWage(); cout << endl ; Salemen b(2,"l",0.5,1000,500,5000,0.5); b.Output(); b.OutputWage(); cout << endl ; Manager c(3,"pp",0.5,1000,500,5000,0.5); c.Output(); c.OutputWage(); cout << endl ; SaleManager d(4,"p",0.5,1000,500,0.5,10000,0.5,3000); d.Output(); d.OutputWage(); cout << endl ; }