工资发放核算系统代码实现,c语言
时间: 2024-02-26 11:04:50 浏览: 142
利用c语言来实现工资管理系统
以下是一个简单的工资发放核算系统的 C 语言代码实现,实现了基本的员工信息录入、工资计算和工资发放功能:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100 // 员工数量上限
typedef struct Employee {
char name[20];
int id;
int basic_salary;
int overtime_hours;
int overtime_pay;
int total_salary;
} Employee;
Employee employees[MAX_EMPLOYEES];
int num_employees = 0;
int get_employee_index(int id) {
for (int i = 0; i < num_employees; i++) {
if (employees[i].id == id) {
return i;
}
}
return -1;
}
void add_employee() {
if (num_employees >= MAX_EMPLOYEES) {
printf("员工数量已达上限,无法添加新员工。\n");
return;
}
Employee new_employee;
printf("请输入新员工的姓名:\n");
scanf("%s", new_employee.name);
printf("请输入新员工的编号:\n");
scanf("%d", &new_employee.id);
printf("请输入新员工的基本工资:\n");
scanf("%d", &new_employee.basic_salary);
new_employee.overtime_hours = 0;
new_employee.overtime_pay = 0;
new_employee.total_salary = new_employee.basic_salary;
employees[num_employees] = new_employee;
num_employees++;
printf("新员工 %s 添加成功!\n", new_employee.name);
}
void calculate_salary() {
int id;
printf("请输入要计算工资的员工编号:\n");
scanf("%d", &id);
int index = get_employee_index(id);
if (index == -1) {
printf("未找到编号为 %d 的员工。\n", id);
return;
}
Employee *employee = &employees[index];
printf("请输入 %s 的加班时数:\n", employee->name);
int overtime_hours;
scanf("%d", &overtime_hours);
employee->overtime_hours = overtime_hours;
employee->overtime_pay = overtime_hours * 50;
employee->total_salary = employee->basic_salary + employee->overtime_pay;
printf("%s 的工资已计算完成:\n", employee->name);
printf("基本工资: %d 元\n", employee->basic_salary);
printf("加班工资: %d 元\n", employee->overtime_pay);
printf("总工资: %d 元\n", employee->total_salary);
}
void pay_salary() {
printf("本月工资发放清单:\n");
for (int i = 0; i < num_employees; i++) {
Employee *employee = &employees[i];
printf("%s(编号:%d): %d 元\n", employee->name, employee->id, employee->total_salary);
employee->overtime_hours = 0;
employee->overtime_pay = 0;
employee->total_salary = employee->basic_salary;
}
}
int main() {
while (1) {
printf("---------------------------\n");
printf("请输入您要进行的操作:\n");
printf("1. 添加新员工\n");
printf("2. 计算员工工资\n");
printf("3. 发放本月工资\n");
printf("4. 退出程序\n");
printf("---------------------------\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee();
break;
case 2:
calculate_salary();
break;
case 3:
pay_salary();
break;
case 4:
printf("程序已退出。\n");
return 0;
default:
printf("无效的操作,请重新输入。\n");
break;
}
}
}
```
该程序使用了结构体来存储每个员工的信息,包括姓名、编号、基本工资、加班时数、加班工资和总工资。具体功能包括添加新员工、计算员工工资和发放本月工资。每次发放工资后,加班时数、加班工资和总工资都会被重置为零。
注意:该程序仅供参考,实现的功能较为简单,还有很多需要改进的地方。在实际开发中,需要根据具体需求进行完善。
阅读全文