能提供参考代码吗
时间: 2023-08-03 13:09:39 浏览: 72
AD7172的参考代码
5星 · 资源好评率100%
好的,以下是一个简单的企业工资管理系统的参考代码:
```c++
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
string name;
string gender;
string department;
int salary;
};
class Salary {
public:
int basicSalary;
int allowance;
int bonus;
int deduction;
};
const int MAX_EMPLOYEES = 100;
Employee employees[MAX_EMPLOYEES];
Salary salaries[MAX_EMPLOYEES];
int numEmployees = 0;
void addEmployee() {
if (numEmployees >= MAX_EMPLOYEES) {
cout << "The number of employees has reached the maximum!" << endl;
return;
}
cout << "Please enter the employee's name: ";
cin >> employees[numEmployees].name;
cout << "Please enter the employee's gender: ";
cin >> employees[numEmployees].gender;
cout << "Please enter the employee's department: ";
cin >> employees[numEmployees].department;
cout << "Please enter the employee's salary: ";
cin >> salaries[numEmployees].basicSalary;
numEmployees++;
cout << "The employee has been added successfully!" << endl;
}
void modifyEmployee() {
string name;
cout << "Please enter the employee's name: ";
cin >> name;
for (int i = 0; i < numEmployees; i++) {
if (employees[i].name == name) {
cout << "Please enter the employee's gender: ";
cin >> employees[i].gender;
cout << "Please enter the employee's department: ";
cin >> employees[i].department;
cout << "Please enter the employee's salary: ";
cin >> salaries[i].basicSalary;
cout << "The employee's information has been modified successfully!" << endl;
return;
}
}
cout << "The employee does not exist!" << endl;
}
void deleteEmployee() {
string name;
cout << "Please enter the employee's name: ";
cin >> name;
for (int i = 0; i < numEmployees; i++) {
if (employees[i].name == name) {
for (int j = i; j < numEmployees - 1; j++) {
employees[j] = employees[j + 1];
salaries[j] = salaries[j + 1];
}
numEmployees--;
cout << "The employee has been deleted successfully!" << endl;
return;
}
}
cout << "The employee does not exist!" << endl;
}
void queryEmployee() {
string name;
cout << "Please enter the employee's name: ";
cin >> name;
for (int i = 0; i < numEmployees; i++) {
if (employees[i].name == name) {
cout << "Name: " << employees[i].name << endl;
cout << "Gender: " << employees[i].gender << endl;
cout << "Department: " << employees[i].department << endl;
cout << "Basic Salary: " << salaries[i].basicSalary << endl;
cout << "Allowance: " << salaries[i].allowance << endl;
cout << "Bonus: " << salaries[i].bonus << endl;
cout << "Deduction: " << salaries[i].deduction << endl;
cout << "Total Salary: " << salaries[i].basicSalary + salaries[i].allowance + salaries[i].bonus - salaries[i].deduction << endl;
return;
}
}
cout << "The employee does not exist!" << endl;
}
void calculateSalary() {
for (int i = 0; i < numEmployees; i++) {
cout << "Please enter the allowance for " << employees[i].name << ": ";
cin >> salaries[i].allowance;
cout << "Please enter the bonus for " << employees[i].name << ": ";
cin >> salaries[i].bonus;
cout << "Please enter the deduction for " << employees[i].name << ": ";
cin >> salaries[i].deduction;
}
cout << "The salaries have been calculated successfully!" << endl;
}
void printSalaryTable() {
cout << "Name\tGender\tDepartment\tBasic Salary\tAllowance\tBonus\tDeduction\tTotal Salary" << endl;
for (int i = 0; i < numEmployees; i++) {
cout << employees[i].name << "\t" << employees[i].gender << "\t" << employees[i].department << "\t" << salaries[i].basicSalary << "\t" << salaries[i].allowance << "\t" << salaries[i].bonus << "\t" << salaries[i].deduction << "\t" << salaries[i].basicSalary + salaries[i].allowance + salaries[i].bonus - salaries[i].deduction << endl;
}
}
int main() {
int choice;
while (true) {
cout << "Please select an operation:" << endl;
cout << "1. Add employee" << endl;
cout << "2. Modify employee information" << endl;
cout << "3. Delete employee" << endl;
cout << "4. Query employee information" << endl;
cout << "5. Calculate salaries" << endl;
cout << "6. Print salary table" << endl;
cout << "7. Exit" << endl;
cin >> choice;
switch (choice) {
case 1:
addEmployee();
break;
case 2:
modifyEmployee();
break;
case 3:
deleteEmployee();
break;
case 4:
queryEmployee();
break;
case 5:
calculateSalary();
break;
case 6:
printSalaryTable();
break;
case 7:
return 0;
default:
cout << "Invalid choice!" << endl;
}
}
}
```
以上代码实现了添加职工、修改职工、删除职工、查询职工信息、计算工资、打印工资表等功能。需要注意的是,以上代码只是一个示例,实际编写时需要根据具体需求进行修改和完善。
阅读全文