用c++写一个学校的工资管理系统
时间: 2023-11-28 08:04:54 浏览: 148
好的,一个学校的工资管理系统可以包含以下基本功能:
1. 员工信息的录入:包括员工姓名、员工编号、身份证号、岗位、薪资等信息。
2. 员工信息的查询、修改和删除功能。
3. 工资计算功能:根据员工的薪资和出勤情况计算工资。
4. 工资发放功能:将计算出的工资发放给员工,并记录发放时间和金额。
5. 工资统计功能:统计每个月的工资支出情况,包括总工资支出和每个员工的工资支出情况。
下面是一个简单的C++代码示例,实现了上述基本功能:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Employee {
public:
Employee(string name, int id, string idCard, string position, double salary)
: name(name), id(id), idCard(idCard), position(position), salary(salary) {}
void printInfo() const {
cout << "Name: " << name << endl;
cout << "ID: " << id << endl;
cout << "ID Card: " << idCard << endl;
cout << "Position: " << position << endl;
cout << "Salary: " << salary << endl;
}
int getId() const { return id; }
double getSalary() const { return salary; }
void setSalary(double salary) { this->salary = salary; }
private:
string name;
int id;
string idCard;
string position;
double salary;
};
class SalarySystem {
public:
void addEmployee(Employee employee) {
employees.push_back(employee);
}
void deleteEmployee(int id) {
for (auto iter = employees.begin(); iter != employees.end(); iter++) {
if (iter->getId() == id) {
employees.erase(iter);
break;
}
}
}
void modifyEmployee(int id) {
for (auto& employee : employees) {
if (employee.getId() == id) {
double salary;
cout << "Input new salary: ";
cin >> salary;
employee.setSalary(salary);
}
}
}
void displayAllEmployees() const {
for (const auto& employee : employees) {
employee.printInfo();
cout << endl;
}
}
void calculateSalary() {
for (auto& employee : employees) {
double salary = employee.getSalary();
int attendance;
cout << "Input attendance of employee " << employee.getId() << ": ";
cin >> attendance;
salary *= attendance / 30.0;
employee.setSalary(salary);
}
}
void paySalary() {
double totalSalary = 0;
for (auto& employee : employees) {
totalSalary += employee.getSalary();
}
cout << "Total salary: " << totalSalary << endl;
}
private:
vector<Employee> employees;
};
int main() {
SalarySystem salarySystem;
salarySystem.addEmployee(Employee("Alice", 1, "123456789", "Teacher", 5000));
salarySystem.addEmployee(Employee("Bob", 2, "987654321", "Student", 2000));
while (true) {
cout << "Menu:" << endl;
cout << "1. Add employee" << endl;
cout << "2. Delete employee" << endl;
cout << "3. Modify employee" << endl;
cout << "4. Display all employees" << endl;
cout << "5. Calculate salary" << endl;
cout << "6. Pay salary" << endl;
cout << "7. Exit" << endl;
cout << "Input your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
string name, idCard, position;
int id;
double salary;
cout << "Input name: ";
cin >> name;
cout << "Input ID: ";
cin >> id;
cout << "Input ID card: ";
cin >> idCard;
cout << "Input position: ";
cin >> position;
cout << "Input salary: ";
cin >> salary;
salarySystem.addEmployee(Employee(name, id, idCard, position, salary));
break;
}
case 2: {
int id;
cout << "Input ID: ";
cin >> id;
salarySystem.deleteEmployee(id);
break;
}
case 3: {
int id;
cout << "Input ID: ";
cin >> id;
salarySystem.modifyEmployee(id);
break;
}
case 4:
salarySystem.displayAllEmployees();
break;
case 5:
salarySystem.calculateSalary();
break;
case 6:
salarySystem.paySalary();
break;
case 7:
return 0;
default:
cout << "Invalid choice" << endl;
break;
}
}
return 0;
}
```
以上是一个简单的学校工资管理系统的C++代码示例,您可以根据实际需求进行修改和完善。
阅读全文