C语言写一个员工管理系统
时间: 2023-03-20 12:00:20 浏览: 128
好的,以下是一个简单的C语言员工管理系统的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100 // 员工数量上限
struct Employee {
int id; // 员工编号
char name[50]; // 员工姓名
int age; // 员工年龄
float salary; // 员工薪资
};
struct Employee employees[MAX_EMPLOYEES]; // 员工数组
int num_employees = 0; // 当前员工数量
// 添加员工
void add_employee() {
if (num_employees >= MAX_EMPLOYEES) {
printf("员工数量已达上限!\n");
return;
}
struct Employee new_employee;
printf("请输入员工编号:");
scanf("%d", &new_employee.id);
printf("请输入员工姓名:");
scanf("%s", new_employee.name);
printf("请输入员工年龄:");
scanf("%d", &new_employee.age);
printf("请输入员工薪资:");
scanf("%f", &new_employee.salary);
employees[num_employees] = new_employee;
num_employees++;
printf("成功添加员工!\n");
}
// 显示所有员工
void list_employees() {
if (num_employees == 0) {
printf("当前无员工!\n");
return;
}
printf("编号\t姓名\t年龄\t薪资\n");
for (int i = 0; i < num_employees; i++) {
struct Employee employee = employees[i];
printf("%d\t%s\t%d\t%.2f\n", employee.id, employee.name, employee.age, employee.salary);
}
}
// 查找员工
void find_employee() {
int id;
printf("请输入要查找的员工编号:");
scanf("%d", &id);
for (int i = 0; i < num_employees; i++) {
struct Employee employee = employees[i];
if (employee.id == id) {
printf("编号\t姓名\t年龄\t薪资\n");
printf("%d\t%s\t%d\t%.2f\n", employee.id, employee.name, employee.age, employee.salary);
return;
}
}
printf("找不到该员工!\n");
}
// 删除员工
void delete_employee() {
int id;
printf("请输入要删除的员工编号:");
scanf("%d", &id);
for (int i = 0; i < num_employees; i++) {
struct Employee employee = employees[i];
if (employee.id == id) {
for (int j = i; j < num_employees - 1; j++) {
employees[j] = employees[j+1];
}
num_employees--;
printf("成功删除员工!\n");
return;
}
}
printf("找不到该员工!\n");
}
// 主函数
int main() {
while (1) {
printf("请输入数字选择要进行的操作:\n");
printf("1. 添加员工\n");
printf("2. 显示所有员工\n");
printf("3. 查找员工\n");
printf("4
阅读全文
相关推荐
















