企业员工管理系统c语言
时间: 2023-07-13 18:04:06 浏览: 77
企业员工管理系统是一个比较复杂的系统,需要涉及到数据库操作、用户界面设计等方面的知识。以下是一个简单的C语言代码示例,用于演示如何实现一个基本的员工管理系统。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 1000
struct Employee {
int id;
char name[20];
int age;
double salary;
};
struct Employee employees[MAX_SIZE];
int num_employees = 0;
void add_employee() {
if (num_employees >= MAX_SIZE) {
printf("The employee list is full.\n");
return;
}
struct Employee new_employee;
printf("Enter the employee ID: ");
scanf("%d", &new_employee.id);
printf("Enter the employee name: ");
scanf("%s", new_employee.name);
printf("Enter the employee age: ");
scanf("%d", &new_employee.age);
printf("Enter the employee salary: ");
scanf("%lf", &new_employee.salary);
employees[num_employees] = new_employee;
num_employees++;
printf("Employee added successfully.\n");
}
void list_employees() {
printf("ID\tName\tAge\tSalary\n");
for (int i = 0; i < num_employees; i++) {
printf("%d\t%s\t%d\t%.2lf\n",
employees[i].id,
employees[i].name,
employees[i].age,
employees[i].salary);
}
}
void search_employee() {
int id;
printf("Enter the employee ID to search: ");
scanf("%d", &id);
for (int i = 0; i < num_employees; i++) {
if (employees[i].id == id) {
printf("ID\tName\tAge\tSalary\n");
printf("%d\t%s\t%d\t%.2lf\n",
employees[i].id,
employees[i].name,
employees[i].age,
employees[i].salary);
return;
}
}
printf("Employee not found.\n");
}
void delete_employee() {
int id;
printf("Enter the employee ID to delete: ");
scanf("%d", &id);
for (int i = 0; i < num_employees; i++) {
if (employees[i].id == id) {
for (int j = i; j < num_employees - 1; j++) {
employees[j] = employees[j + 1];
}
num_employees--;
printf("Employee deleted successfully.\n");
return;
}
}
printf("Employee not found.\n");
}
int main() {
int choice;
while (1) {
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:
printf("Goodbye!\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
break;
}
}
return 0;
}
```
这个程序实现了以下功能:
- 添加员工信息
- 列出所有员工信息
- 搜索员工信息
- 删除员工信息
你可以根据自己的需求,对这个程序进行修改和扩展。
阅读全文