4.编写职工工资管理程序,用结构体实现以下功能。 (1)建立职工工资表,其中含有职工工号、职工姓名、年龄、基本工资、业绩工资、应发工资、扣除保险费、扣除水电费和实发工资。 (2)计算每一个职工的应发工资和实发工资。 (3)打印职工工资表。 (4)将以上(2)、(3)两项功能分别用子函数实现,编写主函数,调用相应的子函数。
时间: 2023-06-11 12:05:33 浏览: 132
非常感谢您的提问!以下是对您的问题的回答:
对于您的问题,我可以为您提供一些帮助。首先,建立一个职工工资表可以使用结构体来实现,结构体中包含职工工号、职工姓名、年龄、基本工资、业绩工资、应发工资、扣除保险费、扣除水电费和实发工资等属性。例如:
```
struct Employee {
int id; // 职工工号
char name[20]; // 职工姓名
int age; // 年龄
float baseSalary; // 基本工资
float performanceSalary; // 业绩工资
float shouldSalary; // 应发工资
float insurance; // 扣除保险费
float utilities; // 扣除水电费
float actualSalary; // 实发工资
};
```
然后可以编写一个函数来输入职工工资表的信息,利用指针传递需要输入的结构体数组的地址,实现职工工资表的建立:
```
void createEmployee(Employee* employees, int n) {
for (int i = 0; i < n; i++) {
printf("请输入第%d个职工的信息:\n", i + 1);
printf("职工工号:");
scanf("%d", &(employees[i].id));
printf("职工姓名:");
scanf("%s", employees[i].name);
printf("年龄:");
scanf("%d", &(employees[i].age));
printf("基本工资:");
scanf("%f", &(employees[i].baseSalary));
printf("业绩工资:");
scanf("%f", &(employees[i].performanceSalary));
employees[i].shouldSalary = employees[i].baseSalary + employees[i].performanceSalary;
printf("保险费:");
scanf("%f", &(employees[i].insurance));
printf("水电费:");
scanf("%f", &(employees[i].utilities));
employees[i].actualSalary = employees[i].shouldSalary - employees[i].insurance - employees[i].utilities;
}
}
```
接下来可以编写一个函数来计算每个职工的应发工资和实发工资。同样利用指针传递需要计算的结构体数组的地址,实现应发工资和实发工资的计算:
```
void calculateSalary(Employee* employees, int n) {
for (int i = 0; i < n; i++) {
employees[i].shouldSalary = employees[i].baseSalary + employees[i].performanceSalary;
employees[i].actualSalary = employees[i].shouldSalary - employees[i].insurance - employees[i].utilities;
}
}
```
最后,可以编写一个函数来打印职工工资表的信息,同样利用指针传递需要打印的结构体数组的地址,实现职工工资表的打印:
```
void printEmployee(Employee* employees, int n) {
printf("%-10s %-20s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n", "职工工号", "职工姓名", "年龄", "基本工资", "业绩工资", "应发工资", "扣除保险费", "扣除水电费", "实发工资");
for (int i = 0; i < n; i++) {
printf("%-10d %-20s %-10d %-10.2f %-10.2f %-10.2f %-10.2f %-10.2f %-10.2f\n", employees[i].id, employees[i].name, employees[i].age, employees[i].baseSalary, employees[i].performanceSalary, employees[i].shouldSalary, employees[i].insurance, employees[i].utilities, employees[i].actualSalary);
}
}
```
最后,在主函数中可以调用相应的子函数来实现职工工资管理程序:
```
int main() {
int n;
printf("请输入职工人数:");
scanf("%d", &n);
Employee employees[n];
// 建立职工工资表
createEmployee(employees, n);
// 计算每个职工的应发工资和实发工资
calculateSalary(employees, n);
// 打印职工工资表信息
printEmployee(employees, n);
return 0;
}
```
希望上述代码能够对您有所帮助!如有其他问题欢迎继续咨询。
阅读全文