请用C++帮我写一个员工薪资管理系统
时间: 2023-11-09 20:06:46 浏览: 36
好的,下面是一个简单的员工薪资管理系统的C++代码示例:
```c++
#include <iostream>
#include <string>
using namespace std;
// 员工类
class Employee {
public:
Employee(string name, int id, int salary) {
this->name = name;
this->id = id;
this->salary = salary;
}
string getName() {
return name;
}
int getId() {
return id;
}
int getSalary() {
return salary;
}
private:
string name; // 姓名
int id; // 工号
int salary; // 薪资
};
// 员工薪资管理系统类
class EmployeeManagementSystem {
public:
// 添加员工
void addEmployee(Employee emp) {
employees[numEmployees++] = emp;
}
// 根据工号查询员工
Employee findEmployeeById(int id) {
for (int i = 0; i < numEmployees; i++) {
if (employees[i].getId() == id) {
return employees[i];
}
}
// 没有找到员工
return Employee("", -1, -1);
}
// 打印所有员工信息
void printAllEmployees() {
cout << "所有员工信息:" << endl;
for (int i = 0; i < numEmployees; i++) {
Employee emp = employees[i];
cout << "姓名:" << emp.getName() << ",工号:" << emp.getId() << ",薪资:" << emp.getSalary() << endl;
}
}
private:
Employee employees[100]; // 员工数组
int numEmployees = 0; // 员工人数
};
int main() {
EmployeeManagementSystem ems;
// 添加员工
ems.addEmployee(Employee("张三", 1001, 5000));
ems.addEmployee(Employee("李四", 1002, 6000));
ems.addEmployee(Employee("王五", 1003, 7000));
// 查询员工
Employee emp = ems.findEmployeeById(1002);
cout << "查询到员工:" << emp.getName() << ",工号:" << emp.getId() << ",薪资:" << emp.getSalary() << endl;
// 打印所有员工信息
ems.printAllEmployees();
return 0;
}
```
这个员工薪资管理系统包括Employee(员工)和EmployeeManagementSystem(员工薪资管理系统)两个类,其中Employee类用于存储员工的姓名、工号和薪资,EmployeeManagementSystem类用于管理员工,包括添加员工、根据工号查询员工和打印所有员工信息等功能。