职工管理系统是一种用于管理公司员工信息的软件。它可以帮助管理员高效地添加、修改、删除和查询员工信息。以下是一个简单的C++实现的职工管理系统:
```cpp
#include
#include
#include
using namespace std;
class Employee {
public:
string name;
int id;
int age;
// 构造函数
Employee(string n, int i, int a) : name(n), id(i), age(a) {}
// 重载<<运算符,方便输出
friend ostream& operator<<(ostream& os, const Employee& e) {
os << "姓名:" << e.name << ",ID:" << e.id << ",年龄:" << e.age;
return os;
}
};
class EmployeeManager {
private:
vector
public:
// 添加员工
void addEmployee(string n, int i, int a) {
employees.push_back(Employee(n, i, a));
}
// 修改员工信息
void modifyEmployee(int id, string newName, int newAge) {
for (auto it = employees.begin(); it != employees.end(); ++it) {
if (it->id == id) {
it->name = newName;
it->age = newAge;
break;
}
}
}
// 删除员工
void deleteEmployee(int id) {
for (auto it = employees.begin(); it != employees.end(); ++it) {
if (it->id == id) {
employees.erase(it);
break;
}
}
}
// 查询员工信息
void queryEmployee(int id) {
for (auto it = employees.begin(); it != employees.end(); ++it) {
if (it->id == id) {
cout << it->name << " " << it->id << " " << it->age << endl;
return;
}
}
cout << "未找到该员工" << endl;
}
};
int main() {
EmployeeManager manager;
manager.addEmployee("张三", 1, 25);
manager.addEmployee("李四", 2, 30);
manager.queryEmployee(1);
manager.modifyEmployee(1, "张三", 30);
manager.queryEmployee(1);
manager.deleteEmployee(1);
manager.queryEmployee(1);
return 0;
}
```
这个程序实现了一个简单的职工管理系统,包括添加、修改、删除和查询员工信息的功能。在main函数中,我们创建了一个EmployeeManager对象,并使用它来添加、修改、查询和删除员工信息。