编写一个排班表系统需要考虑到很多因素,例如员工的班次、休息日、节假日等。以下是一个简单的排班表系统的示例代码,仅供参考:
#include <stdio.h>
#include <string.h>
#define MAX_EMPLOYEES 100
#define MAX_NAME_LENGTH 50
#define MAX_SHIFT_LENGTH 10
typedef struct {
char name[MAX_NAME_LENGTH];
char shift[MAX_SHIFT_LENGTH];
int workdays[5]; // Monday to Friday
} Employee;
void print_schedule(Employee employees[], int num_employees) {
for (int i = 0; i < num_employees; i++) {
printf("%s\t%s\t", employees[i].name, employees[i].shift);
for (int j = 0; j < 5; j++) {
if (employees[i].workdays[j] == 1) {
printf("%s ", (j == 4) ? "Weekend" : "Mon");
} else {
printf("- ");
}
}
printf("\n");
}
}
int main() {
Employee employees[MAX_EMPLOYEES];
int num_employees;
printf("Enter the number of employees: ");
scanf("%d", &num_employees);
for (int i = 0; i < num_employees; i++) {
printf("Enter name of employee %d: ", i + 1);
scanf("%s", employees[i].name);
printf("Enter shift of employee %d: ", i + 1);
scanf("%s", employees[i].shift);
for (int j = 0; j < 5; j++) {
printf("Enter workdays for employee %d (1 for workday, 0 for non-workday): ", i + 1);
scanf("%d", &employees[i].workdays[j]);
}
}
print_schedule(employees, num_employees);
return 0;
}
该程序首先定义了一个 Employee
结构体,用于存储员工的姓名、班次和每周的工作日。然后,程序通过 print_schedule
函数打印出排班表。在 main
函数中,程序首先要求用户输入员工的数量,然后依次输入每个员工的姓名、班次和每周的工作日。最后,程序调用 print_schedule
函数打印出排班表。