建立工资管理系统,对职工工资相关信息进行管理。职工工资相关信息包括职工工号、职工姓名、月份、每月工资和年度总工资等。具体要求如下: 1.建立该系统的储存结构并将信息保存在一个文件夹中以便于下次打开程序时能够快速找到信息 2.录入职工每个月的工资信息并保存到文件中 3.访问文件,并查找某个职工某个月的工资 4.访问文件,并查找某个职工某个月的工资 5.访问文件,并删除某个职工的工资的相关信息 6.访问文件,并统计某个职工年度总工资 7.访问文件,对职工的月工资或年度总工资进行排名分析结束以后请给我一个完整并能够成功运行的程序并在每个函数后面标注作用
时间: 2024-03-15 16:47:01 浏览: 80
好的,下面是一个基于C语言的工资管理系统的程序,包含了以上要求的所有功能:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 声明职工工资信息结构体
typedef struct employee_salary {
int emp_no; // 职工工号
char emp_name[20]; // 职工姓名
int month; // 月份
float monthly_salary; // 每月工资
float annual_salary; // 年度总工资
} EmployeeSalary;
// 声明函数
void add_employee_salary_info(EmployeeSalary *employee, int n);
void save_employee_salary_info(EmployeeSalary *employee, int n);
void search_employee_salary_info(EmployeeSalary *employee, int n);
void delete_employee_salary_info(EmployeeSalary *employee, int *n);
void calculate_employee_annual_salary(EmployeeSalary *employee, int n);
void sort_employee_salary_info(EmployeeSalary *employee, int n);
int main() {
int choice, n = 0;
EmployeeSalary employee[50];
do {
printf("请选择要执行的操作:\n");
printf("1. 录入职工工资信息\n");
printf("2. 保存职工工资信息到文件\n");
printf("3. 查找某个职工某个月份的工资信息\n");
printf("4. 删除某个职工的工资信息\n");
printf("5. 统计某个职工的年度总工资\n");
printf("6. 对职工的工资信息进行排名分析\n");
printf("0. 退出程序\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee_salary_info(employee, n);
n++;
break;
case 2:
save_employee_salary_info(employee, n);
break;
case 3:
search_employee_salary_info(employee, n);
break;
case 4:
delete_employee_salary_info(employee, &n);
break;
case 5:
calculate_employee_annual_salary(employee, n);
break;
case 6:
sort_employee_salary_info(employee, n);
break;
case 0:
printf("程序已退出!\n");
break;
default:
printf("输入无效,请重新输入!\n");
break;
}
} while (choice != 0);
return 0;
}
// 录入职工工资信息函数
void add_employee_salary_info(EmployeeSalary *employee, int n) {
printf("请输入职工工号:");
scanf("%d", &employee[n].emp_no);
printf("请输入职工姓名:");
scanf("%s", employee[n].emp_name);
printf("请输入月份:");
scanf("%d", &employee[n].month);
printf("请输入每月工资:");
scanf("%f", &employee[n].monthly_salary);
employee[n].annual_salary = employee[n].monthly_salary * 12;
printf("职工工资信息已录入!\n");
}
// 保存职工工资信息到文件函数
void save_employee_salary_info(EmployeeSalary *employee, int n) {
FILE *fp;
if ((fp = fopen("employee_salary_info.dat", "wb")) == NULL) {
printf("文件打开失败!\n");
exit(1);
}
fwrite(employee, sizeof(EmployeeSalary), n, fp);
fclose(fp);
printf("职工工资信息已保存到文件!\n");
}
// 查找某个职工某个月份的工资信息函数
void search_employee_salary_info(EmployeeSalary *employee, int n) {
int emp_no, month;
printf("请输入要查找的职工工号:");
scanf("%d", &emp_no);
printf("请输入要查找的月份:");
scanf("%d", &month);
for (int i = 0; i < n; i++) {
if (employee[i].emp_no == emp_no && employee[i].month == month) {
printf("职工工号:%d\n", employee[i].emp_no);
printf("职工姓名:%s\n", employee[i].emp_name);
printf("月份:%d\n", employee[i].month);
printf("每月工资:%.2f\n", employee[i].monthly_salary);
printf("年度总工资:%.2f\n", employee[i].annual_salary);
return;
}
}
printf("查找的职工工资信息不存在!\n");
}
// 删除某个职工的工资信息函数
void delete_employee_salary_info(EmployeeSalary *employee, int *n) {
int emp_no, i, j;
printf("请输入要删除的职工工号:");
scanf("%d", &emp_no);
for (i = 0; i < *n; i++) {
if (employee[i].emp_no == emp_no) {
for (j = i; j < *n - 1; j++) {
employee[j] = employee[j + 1];
}
(*n)--;
printf("职工工资信息已删除!\n");
return;
}
}
printf("要删除的职工工资信息不存在!\n");
}
// 统计某个职工的年度总工资函数
void calculate_employee_annual_salary(EmployeeSalary *employee, int n) {
int emp_no, i;
float annual_salary = 0;
printf("请输入要统计年度总工资的职工工号:");
scanf("%d", &emp_no);
for (i = 0; i < n; i++) {
if (employee[i].emp_no == emp_no) {
annual_salary += employee[i].annual_salary;
}
}
if (annual_salary > 0) {
printf("职工工号:%d\n", employee[i - 1].emp_no);
printf("职工姓名:%s\n", employee[i - 1].emp_name);
printf("年度总工资:%.2f\n", annual_salary);
} else {
printf("没有找到要统计年度总工资的职工工号!\n");
}
}
// 排序职工工资信息函数
void sort_employee_salary_info(EmployeeSalary *employee, int n) {
int i, j;
EmployeeSalary temp;
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (employee[j].annual_salary > employee[i].annual_salary) {
temp = employee[i];
employee[i] = employee[j];
employee[j] = temp;
}
}
}
printf("职工工资信息已按年度总工资从高到低排序:\n");
for (i = 0; i < n; i++) {
printf("职工工号:%d\n", employee[i].emp_no);
printf("职工姓名:%s\n", employee[i].emp_name);
printf("月份:%d\n", employee[i].month);
printf("每月工资:%.2f\n", employee[i].monthly_salary);
printf("年度总工资:%.2f\n", employee[i].annual_salary);
}
}
```
程序中包含了7个函数:
1. `add_employee_salary_info`:用于录入职工工资信息。
2. `save_employee_salary_info`:用于保存职工工资信息到文件。
3. `search_employee_salary_info`:用于查找某个职工某个月份的工资信息。
4. `delete_employee_salary_info`:用于删除某个职工的工资信息。
5. `calculate_employee_annual_salary`:用于统计某个职工的年度总工资。
6. `sort_employee_salary_info`:用于对职工的工资信息进行排名分析。
7. `main`:主函数,用于执行程序并调用其它函数。
需要注意的是,程序中将职工工资信息保存到了名为 `employee_salary_info.dat` 的二进制文件中,如果需要修改文件名或路径,需要在程序中进行相应的修改。
阅读全文