用c++写一个员工工资管理系统
时间: 2024-02-18 20:33:46 浏览: 225
好的,下面是一个简单的员工工资管理系统的C++代码:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Employee {
string name;
int id;
double salary;
};
vector<Employee> employees;
void addEmployee() {
Employee e;
cout << "Enter employee name: ";
cin >> e.name;
cout << "Enter employee ID: ";
cin >> e.id;
cout << "Enter employee salary: ";
cin >> e.salary;
employees.push_back(e);
}
void displayEmployees() {
cout << "Employees:\n";
for (Employee e : employees) {
cout << e.name << ", ID: " << e.id << ", Salary: $" << e.salary << endl;
}
}
int main() {
bool quit = false;
while (!quit) {
cout << "Menu:\n1. Add employee\n2. Display employees\n3. Quit\n";
int choice;
cin >> choice;
switch (choice) {
case 1:
addEmployee();
break;
case 2:
displayEmployees();
break;
case 3:
quit = true;
break;
default:
cout << "Invalid choice.\n";
break;
}
}
return 0;
}
```
这个程序使用了一个结构体来存储每个员工的姓名、ID和薪资,并将这些员工存储在一个vector中。主函数提供了一个菜单,让用户选择添加员工、显示员工或退出程序。如果用户选择添加员工,程序将提示用户输入员工的姓名、ID和薪资,并将这个员工添加到vector中。如果用户选择显示员工,程序将遍历vector,并显示每个员工的姓名、ID和薪资。如果用户选择退出程序,程序将设置一个标志,退出while循环,然后返回0表示程序成功结束。
阅读全文
相关推荐
















