``定义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
#include
using namespace std;
class Staff{
private:
int num;
char name[18];
double rateofattend;
int basicSal;
int prize;
public:
Staff(int number,char nm[],double c,int d,int e):num(number),rateofattend( c ),basicSal(d),prize(e){
strcpy(name,nm);
}
void Output(){
cout <<"编号:"<< num << endl<< "姓名:"<<name << endl <<"出勤率:"<< rateofattend <<endl<<"基本工资;"<< basicSal <<endl<<"奖金:"<< prize << endl;
}
void display(){
cout<<"----------分割线---------"<<endl;
cout<<"<<职员>>"<<endl;}
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(){
cout<<"----------分割线---------"<<endl;
cout<<"<<销售员>>"<<endl;
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 nm[],double c,int d,int e,double f,double g):Staff(a,nm,c,d,e),totalDeductRate(f),totalAmount(g){};
void Output(){
cout<<"----------分割线---------"<<endl;
cout<<"<<经理>>"<<endl;
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 nm[],double c,int d,int e,double f,double g,double h,double i):Salemen(a,nm,c,d,e,f,g),Manager(a,nm,c,d,e,h,i),Staff(a,nm,c,d,e){}
void Output(){
cout<<"----------分割线---------"<<endl;
cout<<"<<销售经理>>"<<endl;
Staff::Output();
Salemen::display();
cout<<endl;
Manager::display();
}
double OutputWage(){
return (Salemen::OutputWage()+Manager::OutputWage()-Staff::OutputWage());
}
};
main()
{
Staff sta1(10086,"LBW",0.9,2000,3000);
sta1.display();
sta1.Output();
sta1.OutputWage();
cout << endl ;
Salemen sal1(9418,"white",0.9,3000,4000,0.1,10000);
sal1.Output();
sal1.OutputWage();
cout << endl ;
Manager man1(96291,"55",0.9,4000,5000,0.1,20000);
man1.Output();
man1.OutputWage();
cout << endl ;
SaleManager salm1(55,"NB",1,5000,6000,0.1,10000,0.05,40000);
salm1.Output();
salm1.OutputWage();
cout << endl;
return 0;
//This code was written by gfh in SCMZU.
}