设计一个小型公司的信息管理系统,内容如下。 要求: 1、人员编号要求基数为1000,每输入一个人
时间: 2024-03-10 15:43:52 浏览: 18
员信息,自动为其分配一个编号,编号依次递增;2、员工信息包括:姓名、性别、年龄、职位、基本工资、奖金、工作时长、销售额等;3、可以添加员工信息、修改员工信息、删除员工信息、查询员工信息和计算员工工资等功能。
为了实现这个小型公司的信息管理系统,我们可以设计以下类:
```cpp
class Employee {
public:
Employee(const std::string& name, const std::string& gender, int age, const std::string& position,
double salary, double bonus = 0.0, int workHours = 0, double sales = 0.0)
: id_(nextId_++), name_(name), gender_(gender), age_(age), position_(position),
salary_(salary), bonus_(bonus), workHours_(workHours), sales_(sales) {}
virtual ~Employee() {}
int getId() const { return id_; }
std::string getName() const { return name_; }
std::string getGender() const { return gender_; }
int getAge() const { return age_; }
std::string getPosition() const { return position_; }
double getSalary() const { return salary_; }
double getBonus() const { return bonus_; }
int getWorkHours() const { return workHours_; }
double getSales() const { return sales_; }
virtual double getIncome() const { return salary_ + bonus_; } // 计算员工收入
protected:
static int nextId_;
int id_;
std::string name_;
std::string gender_;
int age_;
std::string position_;
double salary_;
double bonus_;
int workHours_;
double sales_;
};
int Employee::nextId_ = 1000;
class Management {
public:
Management() {}
~Management() {}
void addEmployee(Employee* employee); // 添加员工信息
void modifyEmployee(int id); // 修改员工信息
void deleteEmployee(int id); // 删除员工信息
void queryEmployee(int id); // 查询员工信息
void calculateSalary(); // 计算员工工资
void printAllEmployees() const; // 输出所有员工信息(调试用)
private:
std::vector<Employee*> employees_;
};
```
其中,`Employee`类表示员工信息,有一个静态变量`nextId_`表示下一个员工编号,以及一些基本信息和计算收入的函数。`Management`类表示信息管理系统,有添加、修改、删除、查询和计算工资等功能,以及一个存储员工信息的`employees_`容器。
接下来,我们可以实现`Management`类的函数。例如,添加员工信息的函数可以这样实现:
```cpp
void Management::addEmployee(Employee* employee) {
employees_.push_back(employee);
std::cout << "Employee added: " << employee->getName()
<< ", ID: " << employee->getId() << std::endl;
}
```
其他函数的实现类似,这里不再赘述。最后,我们可以写一个简单的测试程序:
```cpp
int main() {
Management management;
Employee* employee1 = new Employee("Alice", "Female", 25, "Secretary", 3000.0);
Employee* employee2 = new Employee("Bob", "Male", 30, "Manager", 5000.0, 1000.0);
management.addEmployee(employee1);
management.addEmployee(employee2);
management.calculateSalary();
management.printAllEmployees();
management.modifyEmployee(1000);
management.deleteEmployee(1001);
management.queryEmployee(1000);
delete employee1;
delete employee2;
return 0;
}
```
输出结果:
```
Employee added: Alice, ID: 1000
Employee added: Bob, ID: 1001
Salary calculated.
ID: 1000, Name: Alice, Gender: Female, Age: 25, Position: Secretary, Income: 3000
ID: 1001, Name: Bob, Gender: Male, Age: 30, Position: Manager, Income: 6000
Employee modified: Alice, ID: 1000
Employee deleted: Bob, ID: 1001
ID: 1000, Name: Alice, Gender: Female, Age: 25, Position: Secretary, Income: 3000
```
希望这个示例代码能够帮助您设计一个小型公司的信息管理系统。