C++编程:定义职工工资结构体类型定义某车间职 工工资结构体数组。编写四个函数分别用于: ①输入全车间职工的工号、姓名、基本工 资、岗位工资、医疗住房基金与税金。 ②计算每一个职工实发工资,计算公式: 实发工资=基本工资+岗位工资-医疗住房基金 税金。 ③按实发工资降序排序。 ④输出全车间职工的工号、姓名、基本工资、岗位工资、医疗住房基金、税金与实发工资。 在主函数中定义职工工资数组,调用四个函数完成输入、计算实发工资、排序、输出工作。
时间: 2023-05-11 19:04:36 浏览: 102
好的,以下是我的回答:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_WORKERS 100
typedef struct {
int id;
char name[20];
float base_salary;
float position_salary;
float medical_fund;
float housing_fund;
float tax;
float actual_salary;
} Worker;
void inputWorkers(Worker workers[], int n) {
for (int i = 0; i < n; i++) {
printf("请输入第%d个职工的信息:\n", i + 1);
printf("工号:");
scanf("%d", &workers[i].id);
printf("姓名:");
scanf("%s", workers[i].name);
printf("基本工资:");
scanf("%f", &workers[i].base_salary);
printf("岗位工资:");
scanf("%f", &workers[i].position_salary);
printf("医疗基金:");
scanf("%f", &workers[i].medical_fund);
printf("住房基金:");
scanf("%f", &workers[i].housing_fund);
printf("税金:");
scanf("%f", &workers[i].tax);
printf("\n");
}
}
void calculateActualSalary(Worker workers[], int n) {
for (int i = 0; i < n; i++) {
workers[i].actual_salary = workers[i].base_salary + workers[i].position_salary - workers[i].medical_fund - workers[i].tax;
}
}
void sortWorkersByActualSalary(Worker workers[], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (workers[j].actual_salary < workers[j + 1].actual_salary) {
Worker temp = workers[j];
workers[j] = workers[j + 1];
workers[j + 1] = temp;
}
}
}
}
void outputWorkers(Worker workers[], int n) {
printf("工号\t姓名\t基本工资\t岗位工资\t医疗基金\t住房基金\t税金\t实发工资\n");
for (int i = 0; i < n; i++) {
printf("%d\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t%.2f\n", workers[i].id, workers[i].name, workers[i].base_salary, workers[i].position_salary, workers[i].medical_fund, workers[i].housing_fund, workers[i].tax, workers[i].actual_salary);
}
}
int main() {
Worker workers[MAX_WORKERS];
int n;
printf("请输入职工人数:");
scanf("%d", &n);
inputWorkers(workers, n);
calculateActualSalary(workers, n);
sortWorkersByActualSalary(workers, n);
outputWorkers(workers, n);
return 0;
}
```
希望我的回答能够帮到你!
阅读全文