用C++写出公司人事管理系统中的员工类employee:protected数据成员包括:个人编号individualEmpNo、姓名name、级别grade、月薪accumPay;public成员函数包括:设置姓名SetName(char *)、升级promote(int)、设置月薪SetAccumPay (float pa)、获取个人编号GetindividualEmpNo()、获取姓名GetName()、获取级别Getgrade()、获取月薪GetAccumPay()、计算薪资pay()、显示人员信息showInfo()。 公司员工分为:技术人员technician、销售人员salesman、管理人员manager、销售经理salesmanager。
时间: 2023-07-04 10:10:20 浏览: 124
下面是用C++编写的员工类employee以及其派生类的代码:
```c++
#include <iostream>
#include <cstring>
using namespace std;
class employee {
protected:
int individualEmpNo; // 个人编号
char name[20]; // 姓名
int grade; // 级别
float accumPay; // 月薪
public:
void SetName(char *n) {
strcpy(name, n);
}
void promote(int g) {
grade += g;
}
void SetAccumPay(float pa) {
accumPay = pa;
}
int GetindividualEmpNo() {
return individualEmpNo;
}
char* GetName() {
return name;
}
int Getgrade() {
return grade;
}
float GetAccumPay() {
return accumPay;
}
virtual float pay() { // 计算薪资
return accumPay;
}
virtual void showInfo() { // 显示人员信息
cout << "个人编号:" << individualEmpNo << endl;
cout << "姓名:" << name << endl;
cout << "级别:" << grade << endl;
cout << "月薪:" << accumPay << endl;
}
};
class technician : public employee {
public:
technician(int no) {
individualEmpNo = no;
grade = 1;
accumPay = 2000;
}
float pay() {
return accumPay;
}
void showInfo() {
cout << "技术人员信息:" << endl;
employee::showInfo();
}
};
class salesman : public employee {
protected:
float commission; // 销售提成比例
public:
salesman(int no) {
individualEmpNo = no;
grade = 1;
accumPay = 2000;
commission = 0.05;
}
float pay() {
return accumPay + commission * accumPay;
}
void showInfo() {
cout << "销售人员信息:" << endl;
employee::showInfo();
cout << "销售提成比例:" << commission << endl;
}
};
class manager : public employee {
protected:
float bonus; // 绩效奖金
public:
manager(int no) {
individualEmpNo = no;
grade = 2;
accumPay = 4000;
bonus = 1000;
}
float pay() {
return accumPay + bonus;
}
void showInfo() {
cout << "管理人员信息:" << endl;
employee::showInfo();
cout << "绩效奖金:" << bonus << endl;
}
};
class salesmanager : public salesman, public manager {
public:
salesmanager(int no) : salesman(no), manager(no) {
individualEmpNo = no;
grade = 3;
accumPay = 5000;
commission = 0.1;
bonus = 2000;
}
float pay() {
return accumPay + commission * accumPay + bonus;
}
void showInfo() {
cout << "销售经理信息:" << endl;
employee::showInfo();
cout << "销售提成比例:" << commission << endl;
cout << "绩效奖金:" << bonus << endl;
}
};
int main() {
technician t(1001);
t.SetName("张三");
t.promote(2);
cout << "姓名:" << t.GetName() << ",薪资:" << t.pay() << endl;
t.showInfo();
salesman s(2001);
s.SetName("李四");
s.promote(3);
cout << "姓名:" << s.GetName() << ",薪资:" << s.pay() << endl;
s.showInfo();
manager m(3001);
m.SetName("王五");
m.promote(4);
cout << "姓名:" << m.GetName() << ",薪资:" << m.pay() << endl;
m.showInfo();
salesmanager sm(4001);
sm.SetName("赵六");
sm.promote(5);
cout << "姓名:" << sm.GetName() << ",薪资:" << sm.pay() << endl;
sm.showInfo();
return 0;
}
```
在主函数中,我们创建了不同类型的员工对象,并对其进行了姓名、级别、月薪等属性的设置,同时调用了计算薪资和显示人员信息的函数。注意到销售经理类salesmanager继承了salesman和manager两个类,因此需要在构造函数中分别调用它们的构造函数来初始化数据成员。
阅读全文