c语言工资管理系统代码
以下是一个简单的C语言工资管理系统的代码示例:
#include <stdio.h>
#include <stdlib.h>
#define MAX_EMPLOYEES 100
typedef struct {
char name[50];
int hoursWorked;
float hourlyRate;
float salary;
} Employee;
void calculateSalary(Employee *employee) {
employee->salary = employee->hoursWorked * employee->hourlyRate;
}
void printEmployee(Employee employee) {
printf("Name: %s\n", employee.name);
printf("Hours Worked: %d\n", employee.hoursWorked);
printf("Hourly Rate: %.2f\n", employee.hourlyRate);
printf("Salary: %.2f\n", employee.salary);
}
int main() {
Employee employees[MAX_EMPLOYEES];
int numEmployees;
printf("Enter the number of employees: ");
scanf("%d", &numEmployees);
if (numEmployees > MAX_EMPLOYEES) {
printf("Maximum number of employees exceeded.\n");
return 1;
}
for (int i = 0; i < numEmployees; i++) {
printf("Enter details for employee %d:\n", i + 1);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Hours Worked: ");
scanf("%d", &employees[i].hoursWorked);
printf("Hourly Rate: ");
scanf("%f", &employees[i].hourlyRate);
calculateSalary(&employees[i]);
}
printf("\nEmployee Details:\n");
for (int i = 0; i < numEmployees; i++) {
printf("Employee %d:\n", i + 1);
printEmployee(employees[i]);
printf("\n");
}
return 0;
}
这个代码示例中,定义了一个Employee
结构体,包含员工的姓名、工作小时数、每小时工资和工资。calculateSalary
函数用于计算员工的工资,printEmployee
函数用于打印员工的信息。
在main
函数中,首先要求用户输入员工的数量,并进行判断是否超过了最大数量。然后使用循环依次输入每个员工的信息,并调用calculateSalary
函数计算工资。最后,使用循环打印每个员工的信息。
请注意,这只是一个简单的示例代码,可能还有很多需要完善的地方,比如输入验证、错误处理等。具体的实现方式还需要根据实际需求进行调整。