设计一个小型公司的信息管理系统,内容如下。 某小型公司主要有4类人:经理、兼职技术人员、销售经理、兼职销售员,这些人具有以下属性: 经理:姓名、编号、级别、固定工资、当月薪水、计算月薪、显示信息。 兼职技术人员:姓名、编号、级别、工作小时、每小时工资额、当月薪水、计算月薪、显示信息。 兼职销售员:姓名、编号、级别、销售额、销售额提成、当月薪水、计算月薪、显示信息。 销售经理:姓名、编号、级别、固定工资、销售额、销售额提成、当月薪水、计算月薪、显示信息。 要求: 1、 人员编号要求基数为1000,每输入一个人员信息编号顺序加1; 2、 要有主函数,在主函数里定义不同类的对象,实现人员信息的输出。 3、月薪计算办法: 经理固定月薪8000元;兼职技术人员按100元/小时领取月薪;兼职推销员按当月销售额的4%提成;销售经理固定月薪5000,销售提成为所管辖部门当月销售总额的千分之五。 c++实现
时间: 2023-07-10 11:34:51 浏览: 64
以下是一个简单的C++实现,包括Person类和其子类Manager、PartTimeTech、PartTimeSales、SalesManager的定义和实现:
```c++
#include <iostream>
#include <string>
using namespace std;
class Person {
protected:
string name;
int id;
int level;
double monthlySalary;
public:
Person(string n, int l) : name(n), level(l) {
id = 1000 + l; // 每输入一个人员信息编号顺序加1
}
virtual void calculateMonthlySalary() = 0; // 纯虚函数
virtual void displayInfo() = 0; // 纯虚函数
};
class Manager : public Person {
private:
double fixedSalary;
public:
Manager(string n, int l, double f) : Person(n, l), fixedSalary(f) {}
void calculateMonthlySalary() {
monthlySalary = fixedSalary;
}
void displayInfo() {
cout << "姓名:" << name << endl;
cout << "编号:" << id << endl;
cout << "级别:" << level << endl;
cout << "当月薪水:" << monthlySalary << endl;
}
};
class PartTimeTech : public Person {
private:
int workHours;
double hourlyWage;
public:
PartTimeTech(string n, int l, int h, double w) : Person(n, l), workHours(h), hourlyWage(w) {}
void calculateMonthlySalary() {
monthlySalary = workHours * hourlyWage;
}
void displayInfo() {
cout << "姓名:" << name << endl;
cout << "编号:" << id << endl;
cout << "级别:" << level << endl;
cout << "当月薪水:" << monthlySalary << endl;
}
};
class PartTimeSales : public Person {
private:
double salesAmount;
double commissionRate;
public:
PartTimeSales(string n, int l, double a, double r) : Person(n, l), salesAmount(a), commissionRate(r) {}
void calculateMonthlySalary() {
monthlySalary = salesAmount * commissionRate;
}
void displayInfo() {
cout << "姓名:" << name << endl;
cout << "编号:" << id << endl;
cout << "级别:" << level << endl;
cout << "当月薪水:" << monthlySalary << endl;
}
};
class SalesManager : public Person {
private:
double fixedSalary;
double salesAmount;
double commissionRate;
public:
SalesManager(string n, int l, double f, double a, double r) : Person(n, l), fixedSalary(f), salesAmount(a), commissionRate(r) {}
void calculateMonthlySalary() {
monthlySalary = fixedSalary + salesAmount * commissionRate / 1000;
}
void displayInfo() {
cout << "姓名:" << name << endl;
cout << "编号:" << id << endl;
cout << "级别:" << level << endl;
cout << "当月薪水:" << monthlySalary << endl;
}
};
int main() {
// 定义不同类的对象
Manager m("张三", 1, 8000);
PartTimeTech ptt("李四", 2, 80, 100);
PartTimeSales pts("王五", 3, 50000, 0.04);
SalesManager sm("赵六", 4, 5000, 1000000, 0.005);
// 计算月薪
m.calculateMonthlySalary();
ptt.calculateMonthlySalary();
pts.calculateMonthlySalary();
sm.calculateMonthlySalary();
// 显示人员信息
m.displayInfo();
ptt.displayInfo();
pts.displayInfo();
sm.displayInfo();
return 0;
}
```
注意,这里使用了虚函数和纯虚函数,以及继承和多态的概念,能够更好地体现面向对象的思想。同时,为了保证编号的连续性,我们在Person类的构造函数中设置了编号的初始值为1000加上级别,以后每输入一个人员信息编号顺序加1。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)