计一个小型公司的信息管理系统,内容如下。 某小型公司主要有4类人:经理、兼职技术人员、销售经理、兼职销售员,这些人具有以下属性: 经理:姓名、编号、级别、固定工资、当月薪水、计算月薪、显示信息。 兼职技术人员:姓名、编号、级别、工作小时、每小时工资额、当月薪水、计算月薪、显示信息。 兼职销售员:姓名、编号、级别、销售额、销售额提成、当月薪水、计算月薪、显示信息。 销售经理:姓名、编号、级别、固定工资、销售额、销售额提成、当月薪水、计算月薪、显示信息。 要求: 1、 人员编号要求基数为1000,每输入一个人员信息编号顺序加1; 2、 要有主函数,在主函数里定义不同类的对象,实现人员信息的输出。 3、月薪计算办法: 经理固定月薪8000元;兼职技术人员按100元/小时领取月薪;兼职推销员按当月销售额的4%提成;销售经理固定月薪5000,销售提成为所管辖部门当月销售总额的千分之五。 c++实现
时间: 2023-08-10 20:04:17 浏览: 87
以下是一个简单的C++实现,包含了所述的类和要求的功能:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee(string name, int level) : name(name), level(level), id(nextId++) {}
virtual void displayInfo() const = 0;
virtual void calculateSalary() = 0;
protected:
string name;
int level;
int id;
double salary;
static int nextId;
};
int Employee::nextId = 1000;
class Manager : public Employee {
public:
Manager(string name, int level) : Employee(name, level), fixedSalary(8000) {}
void displayInfo() const override {
cout << "Manager " << name << ", ID " << id << ", level " << level << endl;
cout << "Fixed salary: " << fixedSalary << ", current month salary: " << salary << endl;
}
void calculateSalary() override {
salary = fixedSalary;
}
private:
double fixedSalary;
};
class PartTimeTechnician : public Employee {
public:
PartTimeTechnician(string name, int level, double hourlySalary) : Employee(name, level), hourlySalary(hourlySalary) {}
void displayInfo() const override {
cout << "Part-time technician " << name << ", ID " << id << ", level " << level << endl;
cout << "Hourly salary: " << hourlySalary << ", worked hours: " << workedHours << ", current month salary: " << salary << endl;
}
void calculateSalary() override {
salary = hourlySalary * workedHours;
}
void setWorkedHours(double hours) {
workedHours = hours;
}
private:
double hourlySalary;
double workedHours;
};
class PartTimeSales : public Employee {
public:
PartTimeSales(string name, int level, double commissionRate) : Employee(name, level), commissionRate(commissionRate) {}
void displayInfo() const override {
cout << "Part-time sales " << name << ", ID " << id << ", level " << level << endl;
cout << "Sales amount: " << salesAmount << ", commission rate: " << commissionRate << ", current month salary: " << salary << endl;
}
void calculateSalary() override {
salary = salesAmount * commissionRate;
}
void setSalesAmount(double amount) {
salesAmount = amount;
}
private:
double commissionRate;
double salesAmount;
};
class SalesManager : public Employee {
public:
SalesManager(string name, int level, double fixedSalary, double commissionRate) : Employee(name, level), fixedSalary(fixedSalary), commissionRate(commissionRate) {}
void displayInfo() const override {
cout << "Sales manager " << name << ", ID " << id << ", level " << level << endl;
cout << "Fixed salary: " << fixedSalary << ", sales amount: " << salesAmount << ", commission rate: " << commissionRate << ", current month salary: " << salary << endl;
}
void calculateSalary() override {
salary = fixedSalary + salesAmount * commissionRate;
}
void addSalesAmount(double amount) {
salesAmount += amount;
}
private:
double fixedSalary;
double commissionRate;
double salesAmount = 0;
};
int main() {
Manager manager("John", 2);
manager.calculateSalary();
manager.displayInfo();
PartTimeTechnician technician("Mike", 1, 100);
technician.setWorkedHours(80);
technician.calculateSalary();
technician.displayInfo();
PartTimeSales sales("Alice", 1, 0.04);
sales.setSalesAmount(50000);
sales.calculateSalary();
sales.displayInfo();
SalesManager salesManager("Bob", 3, 5000, 0.005);
salesManager.addSalesAmount(100000);
salesManager.calculateSalary();
salesManager.displayInfo();
return 0;
}
```
在这个程序中,我们定义了一个`Employee`基类,它包含了所有员工共有的属性和方法,如姓名、级别、编号、当月薪水等。然后,我们派生出了4个子类,分别对应经理、兼职技术人员、兼职销售员和销售经理。
每个子类都覆盖了`displayInfo`和`calculateSalary`方法,前者用于输出员工信息,后者用于计算当月薪水。其中,兼职技术人员和兼职销售员还增加了一个`setWorkedHours`和`setSalesAmount`方法,用于设置他们的工作小时数和销售额。
在主函数中,我们定义了不同类型的员工,设置他们的属性,并调用他们的`calculateSalary`和`displayInfo`方法,输出他们的当月薪水和信息。
需要注意的是,这里的实现只是一个简单的示例,可能还有很多需要完善的地方,例如输入员工信息、处理异常情况等等。
阅读全文