编程:定义职工工资结构体类型定义某车间职工工资结构体数组。编写四个函数分别用于: ①输入全车间职工的工号、姓名、基本工资、岗位工资、医疗住房基金与税金。 ②计算每一个职工实发工资,计算公式:实发工资=基本工资+岗位工资-医疗住房基金-税金。 ③按实发工资降序排序。 ④输出全车间职工的工号、姓名、基本工资、岗位工资、医疗住房基金、税金与实发工资。 在主函数中定义职工工资数组,调用四个函数完成输入、计算实发工资、排序、输出工作。
时间: 2023-05-29 22:04:10 浏览: 62
#include <stdio.h>
#include <string.h>
//定义职工工资结构体类型
typedef struct {
char id[10]; //工号
char name[20]; //姓名
float basic_salary; //基本工资
float position_salary; //岗位工资
float medical_housing_fund; //医疗住房基金
float tax; //税金
float real_salary; //实发工资
} Employee;
//输入全车间职工信息
void input(Employee employees[], int n) {
for (int i = 0; i < n; i++) {
printf("请输入第%d个职工的信息:\n", i + 1);
printf("工号:");
scanf("%s", employees[i].id);
printf("姓名:");
scanf("%s", employees[i].name);
printf("基本工资:");
scanf("%f", &employees[i].basic_salary);
printf("岗位工资:");
scanf("%f", &employees[i].position_salary);
printf("医疗住房基金:");
scanf("%f", &employees[i].medical_housing_fund);
printf("税金:");
scanf("%f", &employees[i].tax);
}
}
//计算每个职工的实发工资
void calculate(Employee employees[], int n) {
for (int i = 0; i < n; i++) {
employees[i].real_salary = employees[i].basic_salary + employees[i].position_salary - employees[i].medical_housing_fund - employees[i].tax;
}
}
//按实发工资降序排序
void sort(Employee employees[], int n) {
Employee temp;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (employees[j].real_salary < employees[j + 1].real_salary) {
temp = employees[j];
employees[j] = employees[j + 1];
employees[j + 1] = temp;
}
}
}
}
//输出全车间职工信息
void output(Employee employees[], int n) {
printf("工号\t姓名\t基本工资\t岗位工资\t医疗住房基金\t税金\t实发工资\n");
for (int i = 0; i < n; i++) {
printf("%s\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t%.2f\n", employees[i].id, employees[i].name, employees[i].basic_salary, employees[i].position_salary, employees[i].medical_housing_fund, employees[i].tax, employees[i].real_salary);
}
}
int main() {
int n;
printf("请输入车间职工人数:");
scanf("%d", &n);
Employee employees[n];
input(employees, n);
calculate(employees, n);
sort(employees, n);
output(employees, n);
return 0;
}
阅读全文