C语言编写的员工管理系统
时间: 2024-05-03 19:19:49 浏览: 11
好的,员工管理系统是一个比较常见的应用程序,用于管理公司或组织中的员工信息。下面是一个简单的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("Maximum number of employees reached.\n");
return;
}
struct Employee new_employee;
printf("Enter employee ID: ");
scanf("%d", &new_employee.id);
printf("Enter employee name: ");
scanf("%s", new_employee.name);
printf("Enter employee age: ");
scanf("%d", &new_employee.age);
printf("Enter employee salary: ");
scanf("%f", &new_employee.salary);
employees[num_employees] = new_employee;
num_employees++;
printf("Employee added successfully.\n");
}
void list_employees() {
if (num_employees == 0) {
printf("There are no employees.\n");
return;
}
printf("%-5s %-20s %-5s %-10s\n", "ID", "Name", "Age", "Salary");
for (int i = 0; i < num_employees; i++) {
struct Employee employee = employees[i];
printf("%-5d %-20s %-5d $%-10.2f\n", employee.id, employee.name, employee.age, employee.salary);
}
}
void search_employee() {
if (num_employees == 0) {
printf("There are no employees.\n");
return;
}
int id;
printf("Enter employee ID to search: ");
scanf("%d", &id);
for (int i = 0; i < num_employees; i++) {
struct Employee employee = employees[i];
if (employee.id == id) {
printf("%-5s %-20s %-5s %-10s\n", "ID", "Name", "Age", "Salary");
printf("%-5d %-20s %-5d $%-10.2f\n", employee.id, employee.name, employee.age, employee.salary);
return;
}
}
printf("Employee with ID %d not found.\n", id);
}
void delete_employee() {
if (num_employees == 0) {
printf("There are no employees.\n");
return;
}
int id;
printf("Enter employee ID to delete: ");
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("Employee with ID %d deleted successfully.\n", id);
return;
}
}
printf("Employee with ID %d not found.\n", id);
}
int main() {
int choice;
while (1) {
printf("\n");
printf("1. Add employee\n");
printf("2. List employees\n");
printf("3. Search employee\n");
printf("4. Delete employee\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee();
break;
case 2:
list_employees();
break;
case 3:
search_employee();
break;
case 4:
delete_employee();
break;
case 5:
exit(0);
default:
printf("Invalid choice.\n");
}
}
return 0;
}
```
该程序使用结构体来存储员工信息,包括ID、姓名、年龄和薪水。它提供了一些基本操作,如添加、列出、搜索和删除员工。用户可以根据需要选择这些操作。
相关推荐
![](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)