c语言程序设计职工考勤系统代码
时间: 2023-08-04 17:09:18 浏览: 103
以下是一个简单的职工考勤系统的 C 语言程序设计代码,仅供参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100
typedef struct {
char name[50];
int hours_worked;
float wage;
} Employee;
void add_employee(Employee employees[], int *num_employees) {
if (*num_employees == MAX_EMPLOYEES) {
printf("Max employees reached.\n");
return;
}
Employee new_employee;
printf("Enter employee name: ");
scanf("%s", new_employee.name);
printf("Enter hours worked: ");
scanf("%d", &new_employee.hours_worked);
printf("Enter wage: ");
scanf("%f", &new_employee.wage);
employees[*num_employees] = new_employee;
(*num_employees)++;
}
void print_employees(Employee employees[], int num_employees) {
printf("%-20s%-20s%-20s\n", "Name", "Hours Worked", "Wage");
for (int i = 0; i < num_employees; i++) {
printf("%-20s%-20d%-20.2f\n", employees[i].name, employees[i].hours_worked, employees[i].wage);
}
}
float calculate_pay(Employee employee) {
float pay = employee.hours_worked * employee.wage;
if (employee.hours_worked > 40) {
pay += (employee.hours_worked - 40) * employee.wage * 0.5;
}
return pay;
}
void print_payroll(Employee employees[], int num_employees) {
printf("%-20s%-20s\n", "Name", "Pay");
for (int i = 0; i < num_employees; i++) {
printf("%-20s%-20.2f\n", employees[i].name, calculate_pay(employees[i]));
}
}
int main() {
Employee employees[MAX_EMPLOYEES];
int num_employees = 0;
int choice;
do {
printf("\n1. Add employee\n");
printf("2. Print employees\n");
printf("3. Print payroll\n");
printf("4. Quit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee(employees, &num_employees);
break;
case 2:
print_employees(employees, num_employees);
break;
case 3:
print_payroll(employees, num_employees);
break;
case 4:
printf("Goodbye.\n");
break;
default:
printf("Invalid choice.\n");
break;
}
} while (choice != 4);
return 0;
}
```
该程序使用结构体存储每个员工的姓名、工作时间和时薪等信息,并提供添加员工、打印员工列表和计算工资单等功能。
阅读全文