#include
#include
using namespace std;
class Employee {
private:
int id;
string name;
double salary;
public:
Employee() {}
Employee(int i, string n, double s) {
id = i;
name = n;
salary = s;
}
void setId(int i) {
id = i;
}
int getId() {
return id;
}
void setName(string n) {
name = n;
}
string getName() {
return name;
}
void setSalary(double s) {
salary = s;
}
double getSalary() {
return salary;
}
};
int main() {
Employee emp[5];
int id;
string name;
double salary;
double totalSalary = 0;
for (int i = 0; i < 5; i++) {
cout << "请输入第" << i+1 << "个职工的编号、姓名和工资:" << endl;
cin >> id >> name >> salary;
emp[i].setId(id);
emp[i].setName(name);
emp[i].setSalary(salary);
totalSalary += salary;
}
cout << "职工信息如下:" << endl;
for (int i = 0; i < 5; i++) {
cout << "编号:" << emp[i].getId() << ",姓名:" << emp[i].getName() << ",工资:" << emp[i].getSalary() << endl;
}
cout << "工资总和为:" << totalSalary << endl;
return 0;
}
标签: