更新时间:2022-10-14 13:09:48
1.定义一个employee类(雇员类),包含了级别(grade)、月薪(accumPay)等保护数据成员,包含构造函数及成员函数pay(),实现月薪计算函数pay()(返回值为accumPay,accumPay=grade×30)。定义employee类的派生类:worker类(工人人员类)、salesman类(销售人员类)、manager类(管理人员类),并分别实现各派生类的构造函数及月薪计算函数pay()。各派生类月薪计算关系如下:
1)工人人员月薪总额【工龄工资+按小时计酬】:雇员类月薪(工龄工资)+100×workHours(当月工作时数)
2)推销人员月薪总额【工龄工资+按小时计酬+销售提成】:雇员类月薪(工龄工资)+100×workHours (当月工作时数)+sales(当月销售额)×0.01
3)管理人员月薪总额【工龄工资+固定月薪数】:雇员类月薪(工龄工资)+8000(固定月薪数)
各派生类对象初始化值如下:
基本雇员(级别:10)
工人人员(级别:2、 工作时数:10)
销售人员(级别:3、 工作时数:10、 销售额2000)
管理人员(级别:5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# include <iostream>
using namespace std;
class Employee{
public :
Employee( int Grade){
grade=Grade; cout<< "基础月薪:" <<pay()<<endl;
} int pay(){
int accumPay;
accumPay=grade* 30 ;
return accumPay;
} private :
int grade;
}; class worker: public Employee{
public :
worker( int Grade, int workHours):Employee(Grade){
hours=workHours; cout<< "工人月薪总额:" <<Pay()<<endl;
} int Pay(){
return pay()+hours* 100 ;
} private :
int hours;
}; class salesman: public Employee{
public :
salesman( int Grade, int workHours, int Sales):Employee(Grade){
hours=workHours; sales=Sales; cout<< "推销人员月薪总额:" <<Pay()<<endl;
} int Pay(){
return pay()+hours* 100 +sales* 0.01 ;
} private :
int hours,sales;
}; class manager: public Employee{
public :
manager( int Grade):Employee(Grade){
cout<< "管理人员月薪总额:" <<Pay()<<endl;
} int Pay(){
return pay()+ 8000 ;
} }; int main(){
Employee my_employee( 10 );
worker my_worker( 2 , 10 );
salesman my_salesman( 3 , 10 , 2000 );
manager my_manager( 5 );
return 0 ;
} |