定义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//在Staff类中包含的数据成员有编号(num)、姓名(name)、出勤率(rateOfAttend)、基本工资(basicSal)和奖金(prize)。
{
public:
Staff(int a,string n,float b,int c,int d):num(a),rateOfAttend(b),basicSal(c),prize(d)
{
name=n;
}
void Output();
void OutputWage();
protected:
int num;
string name;
float rateOfAttend;
int basicSal;
int prize;
int truePay;
};
void Staff::Output()
{
cout<<"编号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"出勤率:"<<rateOfAttend<<endl;
cout<<"基本工资:"<<basicSal<<endl;
cout<<"奖金:"<<prize<<endl;
}
void Staff::OutputWage()
{
truePay=basicSal+prize*rateOfAttend;
cout<<"实发工资:"<<truePay<<endl;
}
//====================================================================
class Saleman:virtual public Staff//在Saleman类中还包含数据成员销售员提成比例(deductRate)和个人销售额(personAmount)
{
protected:
float deductRate;
int personAmount;
public:
Saleman(int,string,float,int,int,float,int);
void Output();
void OutputWage();
};
Saleman::Saleman(int a,string n,float b,int c,int d,float e,int f):Staff(a,n,b,c,d)
{
deductRate=e;
personAmount=f;
}
void Saleman::Output()
{
cout<<"编号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"出勤率:"<<rateOfAttend<<endl;
cout<<"基本工资:"<<basicSal<<endl;
cout<<"奖金:"<<prize<<endl;
cout<<"销售员提成比例:"<<deductRate<<endl;
cout<<"个人销售额:"<<personAmount<<endl;
}
void Saleman::OutputWage()
{
truePay=basicSal+prize*rateOfAttend+personAmount*deductRate;//销售员实发工资 = 基本工资 + 奖金 * 出勤率 + 个人销售额 * 销售员提成比例;
cout<<"实发工资:"<<truePay<<endl;
}
//================================================================
class Manager:virtual public Staff//在Manager类中还包含数据成员经理提成比例(totalDeductRate)和总销售额(totalAmount)
{
protected:
float totalDeductRate;
int totalAmount;
public:
Manager(int,string,float,int,int,float,int);
void Output();
void OutputWage();
};
Manager::Manager(int a,string n,float b,int c,int d,float e,int f):Staff(a,n,b,c,d)
{
totalDeductRate=e;
totalAmount=f;
}
void Manager::Output()
{
cout<<"编号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"出勤率:"<<rateOfAttend<<endl;
cout<<"基本工资:"<<basicSal<<endl;
cout<<"奖金:"<<prize<<endl;
cout<<"经理提成比例:"<<totalDeductRate<<endl;
cout<<"总销售额:"<<totalAmount<<endl;
}
void Manager::OutputWage()
{
truePay=basicSal+prize*rateOfAttend+totalAmount*totalDeductRate;//销售员实发工资 = 基本工资 + 奖金 * 出勤率 + 个人销售额 * 销售员提成比例;
cout<<"实发工资:"<<truePay<<endl;
}
//=========================================================
class SaleManager:public Saleman,public Manager//在SaleManager类中不包含其它数据成员。
{
private:
public:
SaleManager(int a,string n,float b,int c,int d,float e,int f,float g,int h);
void Output();
void OutputWage();
};
SaleManager::SaleManager(int a,string n,float b,int c,int d,float e,int f,float g,int h):Saleman(a,n,b,c,d,e,f)
,Manager(a,n,b,c,d,g,h),Staff(a,n,b,c,d)
{
deductRate=e;
personAmount=f;
totalDeductRate=g;
totalAmount=h;
}
void SaleManager::Output()
{
cout<<"编号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"出勤率:"<<rateOfAttend<<endl;
cout<<"基本工资:"<<basicSal<<endl;
cout<<"奖金:"<<prize<<endl;
cout<<"销售员提成比例:"<<deductRate<<endl;
cout<<"个人销售额:"<<personAmount<<endl;
cout<<"经理提成比例:"<<totalDeductRate<<endl;
cout<<"总销售额:"<<totalAmount<<endl;
}
void SaleManager::OutputWage()
{
truePay=basicSal+prize*rateOfAttend+totalAmount*totalDeductRate+personAmount*deductRate;//销售员实发工资 = 基本工资 + 奖金 * 出勤率 + 个人销售额 * 销售员提成比例;
cout<<"实发工资:"<<truePay<<endl;
}
//=========================================================
int main(){
cout<<"---------------------------------------"<<endl;
Staff Bob(2938572,"Bob",0.5,2000,1000);
Bob.Output();
Bob.OutputWage();
cout<<"---------------------------------------"<<endl;
Saleman Angle(23523626,"Angle",0.8,4000,2000,0.7,3000);
Angle.Output();
Angle.OutputWage();
cout<<"---------------------------------------"<<endl;
Manager Frank(24523462,"Frank",0.6,5000,3400,0.3,7000);
Frank.Output();
Frank.OutputWage();
cout<<"---------------------------------------"<<endl;
SaleManager Boss(200035,"Boss",0.7,4000,3000,0.5,6000,0.8,1000);
Boss.Output();
Boss.OutputWage();
cout<<"---------------------------------------"<<endl;
return 0;
}
运行结果:
---------------------------------------
编号:2938572
姓名:Bob
出勤率:0.5
基本工资:2000
奖金:1000
实发工资:2500
---------------------------------------
编号:23523626
姓名:Angle
出勤率:0.8
基本工资:4000
奖金:2000
销售员提成比例:0.7
个人销售额:3000
实发工资:7700
---------------------------------------
编号:24523462
姓名:Frank
出勤率:0.6
基本工资:5000
奖金:3400
经理提成比例:0.3
总销售额:7000
实发工资:9140
---------------------------------------
编号:200035
姓名:Boss
出勤率:0.7
基本工资:4000
奖金:3000
销售员提成比例:0.5
个人销售额:6000
经理提成比例:0.8
总销售额:1000
实发工资:9900
---------------------------------------