写一个餐厅管理系统,包括管理店员的c语言代码
时间: 2024-03-25 13:39:52 浏览: 57
餐厅管理系统(c语言)
3星 · 编辑精心推荐
好的,以下是一个基于C语言的简单餐厅管理系统,包括管理店员的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100
typedef struct {
char name[20];
char position[20];
float salary;
} Employee;
typedef struct {
Employee employees[MAX_EMPLOYEES];
int num_employees;
} StaffManagement;
void add_employee(StaffManagement *staff_management, Employee employee) {
if (staff_management->num_employees >= MAX_EMPLOYEES) {
printf("员工人数已达上限!\n");
return;
}
staff_management->employees[staff_management->num_employees++] = employee;
printf("员工添加成功!\n");
}
void remove_employee(StaffManagement *staff_management, char *employee_name) {
int i;
for (i = 0; i < staff_management->num_employees; i++) {
if (strcmp(staff_management->employees[i].name, employee_name) == 0) {
int j;
for (j = i; j < staff_management->num_employees - 1; j++) {
staff_management->employees[j] = staff_management->employees[j+1];
}
staff_management->num_employees--;
printf("员工删除成功!\n");
return;
}
}
printf("员工不存在!\n");
}
void update_employee(StaffManagement *staff_management, char *employee_name, char *new_position, float new_salary) {
int i;
for (i = 0; i < staff_management->num_employees; i++) {
if (strcmp(staff_management->employees[i].name, employee_name) == 0) {
strcpy(staff_management->employees[i].position, new_position);
staff_management->employees[i].salary = new_salary;
printf("员工信息修改成功!\n");
return;
}
}
printf("员工不存在!\n");
}
void get_all_employees(StaffManagement staff_management) {
int i;
for (i = 0; i < staff_management.num_employees; i++) {
printf("员工姓名:%s,职位:%s,薪资:%.2f\n", staff_management.employees[i].name, staff_management.employees[i].position, staff_management.employees[i].salary);
}
}
int main() {
StaffManagement staff_management = { .num_employees = 0 };
// 添加员工
add_employee(&staff_management, (Employee){ "张三", "服务员", 3000 });
add_employee(&staff_management, (Employee){ "李四", "厨师", 5000 });
add_employee(&staff_management, (Employee){ "王五", "经理", 8000 });
// 获取所有员工信息
get_all_employees(staff_management);
// 修改员工信息
update_employee(&staff_management, "张三", "主管", 4000);
// 删除员工
remove_employee(&staff_management, "王五");
// 再次获取所有员工信息
get_all_employees(staff_management);
return 0;
}
```
以上代码实现了一个员工管理功能,包括添加、删除、修改、获取所有员工信息等操作。您可以根据实际需要进行扩展。
阅读全文