C语言实现简单员工工资管理系统
简介
本文旨在介绍如何使用C语言实现一个简单的员工工资管理系统。该系统可以用于输入员工基本信息,录入工资数据和计算每个员工的工资。其主要功能模块包括:输入员工基本信息、录入工资数据、计算员工工资、显示员工工资信息。
基本功能
- 输入员工基本信息:包括员工的姓名、性别、年龄、工龄等信息。
示例代码:
```c
struct employee {
char name[20];
char gender[10];
int age;
int workExperience;
};
struct employee getEmployeeInfo() {
struct employee emp;
printf("请输入员工姓名:");
scanf("%s", emp.name);
printf("请输入员工性别:");
scanf("%s", emp.gender);
printf("请输入员工年龄:");
scanf("%d", &emp.age);
printf("请输入员工工龄:");
scanf("%d", &emp.workExperience);
return emp;
}
```
- 录入工资数据:针对每个月的具体情况,输入员工的基本工资、加班工资、津贴、罚款等数据。
示例代码:
```c
struct salary {
float basicSalary;
float overtimeSalary;
float allowance;
float fine;
};
struct salary getSalaryInfo() {
struct salary sal;
printf("请输入员工基本工资:");
scanf("%f", &sal.basicSalary);
printf("请输入员工加班工资:");
scanf("%f", &sal.overtimeSalary);
printf("请输入员工津贴:");
scanf("%f", &sal.allowance);
printf("请输入员工罚款:");
scanf("%f", &sal.fine);
return sal;
}
```
- 计算员工工资:根据录入的工资数据,计算员工的每月工资。
示例代码:
```c
struct employee_salary {
struct employee emp;
struct salary sal;
float totalSalary;
};
struct employee_salary calculateEmployeeSalary(struct employee emp, struct salary sal) {
struct employee_salary empSal;
empSal.emp = emp;
empSal.sal = sal;
empSal.totalSalary = sal.basicSalary + sal.overtimeSalary + sal.allowance - sal.fine;
return empSal;
}
```
- 显示员工工资信息:列出所有员工的工资信息。
示例代码:
c
void displayEmployeeSalary(struct employee_salary empSal) {
printf("员工姓名:%s\n", empSal.emp.name);
printf("员工性别:%s\n", empSal.emp.gender);
printf("员工年龄:%d\n", empSal.emp.age);
printf("员工工龄:%d\n", empSal.emp.workExperience);
printf("基本工资:%f\n", empSal.sal.basicSalary);
printf("加班工资:%f\n", empSal.sal.overtimeSalary);
printf("津贴:%f\n", empSal.sal.allowance);
printf("罚款:%f\n", empSal.sal.fine);
printf("总工资:%f\n", empSal.totalSalary);
}
流程
- 编写代码前,先确定系统的基本功能模块。
- 分别编写输入员工基本信息、录入工资数据、计算员工工资、显示员工工资信息的代码。
- 在主方法中实现四个模块的调用。
- 编译运行程序。
示例代码:
#include<stdio.h>
#include<string.h>
struct employee {
char name[20];
char gender[10];
int age;
int workExperience;
};
struct salary {
float basicSalary;
float overtimeSalary;
float allowance;
float fine;
};
struct employee_salary {
struct employee emp;
struct salary sal;
float totalSalary;
};
struct employee getEmployeeInfo() {
struct employee emp;
printf("请输入员工姓名:");
scanf("%s", emp.name);
printf("请输入员工性别:");
scanf("%s", emp.gender);
printf("请输入员工年龄:");
scanf("%d", &emp.age);
printf("请输入员工工龄:");
scanf("%d", &emp.workExperience);
return emp;
}
struct salary getSalaryInfo() {
struct salary sal;
printf("请输入员工基本工资:");
scanf("%f", &sal.basicSalary);
printf("请输入员工加班工资:");
scanf("%f", &sal.overtimeSalary);
printf("请输入员工津贴:");
scanf("%f", &sal.allowance);
printf("请输入员工罚款:");
scanf("%f", &sal.fine);
return sal;
}
struct employee_salary calculateEmployeeSalary(struct employee emp, struct salary sal) {
struct employee_salary empSal;
empSal.emp = emp;
empSal.sal = sal;
empSal.totalSalary = sal.basicSalary + sal.overtimeSalary + sal.allowance - sal.fine;
return empSal;
}
void displayEmployeeSalary(struct employee_salary empSal) {
printf("员工姓名:%s\n", empSal.emp.name);
printf("员工性别:%s\n", empSal.emp.gender);
printf("员工年龄:%d\n", empSal.emp.age);
printf("员工工龄:%d\n", empSal.emp.workExperience);
printf("基本工资:%f\n", empSal.sal.basicSalary);
printf("加班工资:%f\n", empSal.sal.overtimeSalary);
printf("津贴:%f\n", empSal.sal.allowance);
printf("罚款:%f\n", empSal.sal.fine);
printf("总工资:%f\n", empSal.totalSalary);
}
int main() {
int numberOfEmployees;
printf("请输入员工人数:");
scanf("%d", &numberOfEmployees);
struct employee_salary employeeSalaryArray[numberOfEmployees];
for (int i = 0; i < numberOfEmployees; i++) {
printf("请输入第 %d 个员工的信息:\n", i+1);
struct employee emp = getEmployeeInfo();
struct salary sal = getSalaryInfo();
employeeSalaryArray[i] = calculateEmployeeSalary(emp, sal);
}
printf("\n\n");
for (int i = 0; i < numberOfEmployees; i++) {
displayEmployeeSalary(employeeSalaryArray[i]);
printf("\n\n");
}
}
总结
本文简要介绍了如何使用C语言实现一个简单的员工工资管理系统,包括输入员工基本信息、录入工资数据、计算员工工资、显示员工工资信息四个模块。在实现过程中,需要注意数据类型的定义和函数模块的调用。当然,还有很多需要完善的地方,例如数据存储、多种计算方法等。
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:C语言实现简单员工工资管理系统 - Python技术站