职工工资管理系统代码
时间: 2024-06-11 13:02:08 浏览: 27
职工工资管理系统代码主要涉及到计算职工工资、查询职工信息、修改职工信息等功能。以下是一个简单的示例代码:
```c
#include <stdio.h>
#include <string.h>
#define MAX_EMPLOYEE_NUM 100
struct Employee {
int id;
char name[20];
float salary;
};
struct Employee employees[MAX_EMPLOYEE_NUM];
int employeeNum = 0;
void addEmployee() {
if (employeeNum >= MAX_EMPLOYEE_NUM) {
printf("员工数量已达到上限,无法添加新员工\n");
return;
}
struct Employee e;
printf("请输入员工id:");
scanf("%d", &e.id);
printf("请输入员工姓名:");
scanf("%s", e.name);
printf("请输入员工薪资:");
scanf("%f", &e.salary);
employees[employeeNum++] = e;
printf("成功添加员工\n");
}
void showEmployeeInfo(struct Employee e) {
printf("id: %d, 姓名: %s, 薪资: %.2f\n", e.id, e.name, e.salary);
}
void queryEmployeeInfo() {
int id;
printf("请输入要查询的员工id:");
scanf("%d", &id);
int i;
for (i = 0; i < employeeNum; i++) {
if (employees[i].id == id) {
showEmployeeInfo(employees[i]);
return;
}
}
printf("找不到该员工\n");
}
void modifyEmployeeInfo() {
int id;
printf("请输入要修改的员工id:");
scanf("%d", &id);
int i;
for (i = 0; i < employeeNum; i++) {
if (employees[i].id == id) {
struct Employee e = employees[i];
printf("请输入新的员工姓名:");
scanf("%s", e.name);
printf("请输入新的员工薪资:");
scanf("%f", &e.salary);
employees[i] = e;
printf("成功修改员工信息\n");
return;
}
}
printf("找不到该员工\n");
}
float calculateSalary(struct Employee e) {
return e.salary - e.salary * 0.1; // 扣除个人所得税
}
void showAllEmployeeInfo() {
int i;
for (i = 0; i < employeeNum; i++) {
struct Employee e = employees[i];
printf("第%d个员工信息:\n", i + 1);
showEmployeeInfo(e);
printf("税后薪资: %.2f\n", calculateSalary(e));
}
}
int main() {
int choice;
do {
printf("请选择功能:\n");
printf("1. 添加员工\n");
printf("2. 查询员工信息\n");
printf("3. 修改员工信息\n");
printf("4. 显示所有员工信息\n");
printf("5. 退出程序\n");
scanf("%d", &choice);
switch (choice) {
case 1:
addEmployee();
break;
case 2:
queryEmployeeInfo();
break;
case 3:
modifyEmployeeInfo();
break;
case 4:
showAllEmployeeInfo();
break;
case 5:
printf("感谢使用职工工资管理系统,再见!\n");
break;
default:
printf("无效的选项,请重新选择\n");
break;
}
} while (choice != 5);
return 0;
}
```