编程:定义职工工资结构体类型定义某车间职 工工资结构体数组。编写四个函数分别用于: ①输入全车间职工的工号、姓名、基本工 资、岗位工资、医疗住房基金与税金。 ②计算每一个职工实发工资,计算公式: 实发工资=基本工资+岗位工资-医疗住房基金 税金。 ③按实发工资降序排序。 ④输出全车间职工的工号、姓名、基本工资、岗位工资、医疗住房基金、税金与实发工资。 在主函数中定义职工工资数组,调用四个函数完成输入、计算实发工资、排序、输出工作。
时间: 2023-05-25 19:03:19 浏览: 69
#include <stdio.h>
#include <stdlib.h>
#define MAX_EMPLOYEES 100 // 最大职工人数
typedef struct {
int id; // 工号
char name[20]; // 姓名
float salary_base; // 基本工资
float salary_post; // 岗位工资
float fund_medical; // 医疗基金
float fund_housing; // 住房基金
float tax; // 税收
float salary_actual; // 实发工资
} Employee;
Employee employees[MAX_EMPLOYEES]; // 职工数组
int num_employees = 0; // 职工人数
// 输入职工信息
void inputEmployees() {
printf("请输入职工信息 (输入-1结束):\n");
while (num_employees < MAX_EMPLOYEES) {
printf("工号:");
scanf("%d", &employees[num_employees].id);
if (employees[num_employees].id == -1) {
break;
}
printf("姓名:");
scanf("%s", employees[num_employees].name);
printf("基本工资:");
scanf("%f", &employees[num_employees].salary_base);
printf("岗位工资:");
scanf("%f", &employees[num_employees].salary_post);
printf("医疗基金:");
scanf("%f", &employees[num_employees].fund_medical);
printf("住房基金:");
scanf("%f", &employees[num_employees].fund_housing);
printf("税收:");
scanf("%f", &employees[num_employees].tax);
num_employees++;
}
}
// 计算实发工资
void calculateSalaries() {
for (int i = 0; i < num_employees; i++) {
employees[i].salary_actual = employees[i].salary_base + employees[i].salary_post
- employees[i].fund_medical - employees[i].tax;
}
}
// 实发工资排序
void sortSalaries() {
for (int i = 0; i < num_employees - 1; i++) {
for (int j = i + 1; j < num_employees; j++) {
if (employees[i].salary_actual < employees[j].salary_actual) {
Employee temp = employees[i];
employees[i] = employees[j];
employees[j] = temp;
}
}
}
}
// 输出职工信息
void outputEmployees() {
printf("工号\t姓名\t基本工资\t岗位工资\t医疗基金\t住房基金\t税收\t实发工资\n");
for (int i = 0; i < num_employees; i++) {
printf("%d\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n",
employees[i].id, employees[i].name, employees[i].salary_base, employees[i].salary_post,
employees[i].fund_medical, employees[i].fund_housing, employees[i].tax, employees[i].salary_actual);
}
}
int main() {
inputEmployees();
calculateSalaries();
sortSalaries();
outputEmployees();
system("pause");
return 0;
}
阅读全文