c++教室工资管理系统
时间: 2023-11-24 13:52:17 浏览: 77
C++实现工资管理系统.zip
5星 · 资源好评率100%
以下是一个简单的C++教室工资管理系统的示例,其中包括添加教师、删除教师、显示教师信息和计算教师工资等功能:
```c++
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Teacher {
public:
Teacher(string name, int age, int salary) {
this->name = name;
this->age = age;
this->salary = salary;
}
string getName() {
return name;
}
int getAge() {
return age;
}
int getSalary() {
return salary;
}
private:
string name;
int age;
int salary;
};
class TeacherManagement {
public:
void addTeacher(Teacher teacher) {
teachers.push_back(teacher);
}
void deleteTeacher(string name) {
for (vector<Teacher>::iterator it = teachers.begin(); it != teachers.end(); it++) {
if (it->getName() == name) {
teachers.erase(it);
break;
}
}
}
void showTeachers() {
for (vector<Teacher>::iterator it = teachers.begin(); it != teachers.end(); it++) {
cout << "Name: " << it->getName() << ", Age: " << it->getAge() << ", Salary: " << it->getSalary() << endl;
}
}
int calculateSalary() {
int totalSalary = 0;
for (vector<Teacher>::iterator it = teachers.begin(); it != teachers.end(); it++) {
totalSalary += it->getSalary();
}
return totalSalary;
}
private:
vector<Teacher> teachers;
};
int main() {
TeacherManagement tm;
Teacher t1("Tom", 30, 5000);
Teacher t2("Jerry", 35, 6000);
tm.addTeacher(t1);
tm.addTeacher(t2);
tm.showTeachers();
cout << "Total Salary: " << tm.calculateSalary() << endl;
tm.deleteTeacher("Tom");
tm.showTeachers();
cout << "Total Salary: " << tm.calculateSalary() << endl;
return 0;
}
```
阅读全文