C语言编写的员工管理系统
时间: 2024-05-12 12:15:14 浏览: 17
员工管理系统是一个比较典型的管理信息系统,它可以用来管理公司或组织中的员工信息,包括员工的基本信息、工作经历、薪资福利等方面。下面是一个简单的员工管理系统的C语言实现,供参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100 // 最大员工数
// 员工结构体
typedef struct {
char name[20]; // 姓名
char gender[5]; // 性别
int age; // 年龄
char position[20]; // 职位
int salary; // 工资
} Employee;
// 全局变量
Employee employees[MAX_EMPLOYEES]; // 员工数组
int num_employees = 0; // 员工数量
// 函数声明
void add_employee();
void delete_employee();
void print_employees();
void search_employee();
// 主函数
int main() {
int choice;
do {
printf("\n员工管理系统\n");
printf("1. 添加员工\n");
printf("2. 删除员工\n");
printf("3. 查看所有员工信息\n");
printf("4. 查找员工\n");
printf("5. 退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee();
break;
case 2:
delete_employee();
break;
case 3:
print_employees();
break;
case 4:
search_employee();
break;
case 5:
printf("谢谢使用!\n");
break;
default:
printf("无效的操作!\n");
break;
}
} while (choice != 5);
return 0;
}
// 添加员工
void add_employee() {
if (num_employees >= MAX_EMPLOYEES) {
printf("员工数量已达上限,无法添加新员工!\n");
return;
}
Employee employee;
printf("请输入员工姓名:");
scanf("%s", employee.name);
printf("请输入员工性别:");
scanf("%s", employee.gender);
printf("请输入员工年龄:");
scanf("%d", &employee.age);
printf("请输入员工职位:");
scanf("%s", employee.position);
printf("请输入员工工资:");
scanf("%d", &employee.salary);
employees[num_employees] = employee;
num_employees++;
printf("员工添加成功!\n");
}
// 删除员工
void delete_employee() {
if (num_employees == 0) {
printf("没有员工信息,无法删除!\n");
return;
}
char name[20];
printf("请输入要删除的员工姓名:");
scanf("%s", name);
int i, j;
for (i = 0; i < num_employees; i++) {
if (strcmp(employees[i].name, name) == 0) {
for (j = i; j < num_employees - 1; j++) {
employees[j] = employees[j + 1];
}
num_employees--;
printf("员工删除成功!\n");
return;
}
}
printf("没有找到该员工信息!\n");
}
// 查看所有员工信息
void print_employees() {
if (num_employees == 0) {
printf("没有员工信息!\n");
return;
}
printf("所有员工信息如下:\n");
printf("姓名\t性别\t年龄\t职位\t工资\n");
int i;
for (i = 0; i < num_employees; i++) {
printf("%s\t%s\t%d\t%s\t%d\n", employees[i].name, employees[i].gender, employees[i].age, employees[i].position, employees[i].salary);
}
}
// 查找员工
void search_employee() {
if (num_employees == 0) {
printf("没有员工信息,无法查找!\n");
return;
}
char name[20];
printf("请输入要查找的员工姓名:");
scanf("%s", name);
int i;
for (i = 0; i < num_employees; i++) {
if (strcmp(employees[i].name, name) == 0) {
printf("员工信息如下:\n");
printf("姓名\t性别\t年龄\t职位\t工资\n");
printf("%s\t%s\t%d\t%s\t%d\n", employees[i].name, employees[i].gender, employees[i].age, employees[i].position, employees[i].salary);
return;
}
}
printf("没有找到该员工信息!\n");
}
```
该员工管理系统可以实现添加员工、删除员工、查看所有员工信息和查找员工等功能。其中,使用了结构体来存储员工信息,使用数组来存储所有员工,通过循环实现员工的查找和删除。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)