人事管理系统 C语言,人事管理系统----C语言设计
时间: 2023-10-14 16:05:38 浏览: 78
人事管理系统是一种管理企业内部员工信息的系统,主要包括员工个人信息、薪资、考勤、福利等方面。在C语言中设计一个人事管理系统,可以采用结构体和文件操作等方法实现,以下是一个简单的示例:
1. 定义员工信息结构体
```c
typedef struct employee {
char name[20]; // 姓名
int age; // 年龄
char gender[5]; // 性别
char id[20]; // 身份证号
char phone[20]; // 电话号码
float salary; // 基本工资
float bonus; // 奖金
} Employee;
```
2. 实现文件读写操作
```c
// 文件读取
void read_file(Employee employees[], int *n) {
FILE *fp = fopen("employees.txt", "r");
if (fp == NULL) {
printf("文件打开失败!");
exit(1);
}
while (fscanf(fp, "%s%d%s%s%s%f%f", employees[*n].name, &employees[*n].age,
employees[*n].gender, employees[*n].id, employees[*n].phone,
&employees[*n].salary, &employees[*n].bonus) != EOF) {
(*n)++;
}
fclose(fp);
}
// 文件写入
void write_file(Employee employees[], int n) {
FILE *fp = fopen("employees.txt", "w");
if (fp == NULL) {
printf("文件打开失败!");
exit(1);
}
for (int i = 0; i < n; i++) {
fprintf(fp, "%s %d %s %s %s %.2f %.2f\n", employees[i].name, employees[i].age,
employees[i].gender, employees[i].id, employees[i].phone,
employees[i].salary, employees[i].bonus);
}
fclose(fp);
}
```
3. 实现基本功能,如添加、查找、修改、删除等
```c
// 添加员工信息
void add_employee(Employee employees[], int *n) {
printf("请输入员工信息:\n");
printf("姓名:");
scanf("%s", employees[*n].name);
printf("年龄:");
scanf("%d", &employees[*n].age);
printf("性别:");
scanf("%s", employees[*n].gender);
printf("身份证号:");
scanf("%s", employees[*n].id);
printf("电话号码:");
scanf("%s", employees[*n].phone);
printf("基本工资:");
scanf("%f", &employees[*n].salary);
printf("奖金:");
scanf("%f", &employees[*n].bonus);
(*n)++;
}
// 查找员工信息
void find_employee(Employee employees[], int n) {
char name[20];
printf("请输入要查找的员工姓名:");
scanf("%s", name);
for (int i = 0; i < n; i++) {
if (strcmp(name, employees[i].name) == 0) {
printf("姓名:%s\n", employees[i].name);
printf("年龄:%d\n", employees[i].age);
printf("性别:%s\n", employees[i].gender);
printf("身份证号:%s\n", employees[i].id);
printf("电话号码:%s\n", employees[i].phone);
printf("基本工资:%.2f\n", employees[i].salary);
printf("奖金:%.2f\n", employees[i].bonus);
return;
}
}
printf("未找到该员工信息!\n");
}
// 修改员工信息
void modify_employee(Employee employees[], int n) {
char name[20];
printf("请输入要修改的员工姓名:");
scanf("%s", name);
for (int i = 0; i < n; i++) {
if (strcmp(name, employees[i].name) == 0) {
printf("请输入修改后的员工信息:\n");
printf("姓名:");
scanf("%s", employees[i].name);
printf("年龄:");
scanf("%d", &employees[i].age);
printf("性别:");
scanf("%s", employees[i].gender);
printf("身份证号:");
scanf("%s", employees[i].id);
printf("电话号码:");
scanf("%s", employees[i].phone);
printf("基本工资:");
scanf("%f", &employees[i].salary);
printf("奖金:");
scanf("%f", &employees[i].bonus);
printf("修改成功!\n");
return;
}
}
printf("未找到该员工信息!\n");
}
// 删除员工信息
void delete_employee(Employee employees[], int *n) {
char name[20];
printf("请输入要删除的员工姓名:");
scanf("%s", name);
for (int i = 0; i < *n; i++) {
if (strcmp(name, employees[i].name) == 0) {
for (int j = i; j < *n - 1; j++) {
employees[j] = employees[j + 1];
}
(*n)--;
printf("删除成功!\n");
return;
}
}
printf("未找到该员工信息!\n");
}
```
4. 主函数调用上述函数,实现人事管理系统的完整功能
```c
int main() {
Employee employees[100];
int n = 0;
read_file(employees, &n);
int choice;
while (1) {
printf("\n请选择操作:\n");
printf("1. 添加员工信息\n");
printf("2. 查找员工信息\n");
printf("3. 修改员工信息\n");
printf("4. 删除员工信息\n");
printf("5. 显示所有员工信息\n");
printf("6. 退出\n");
printf("请输入操作编号:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee(employees, &n);
write_file(employees, n);
break;
case 2:
find_employee(employees, n);
break;
case 3:
modify_employee(employees, n);
write_file(employees, n);
break;
case 4:
delete_employee(employees, &n);
write_file(employees, n);
break;
case 5:
printf("所有员工信息如下:\n");
for (int i = 0; i < n; i++) {
printf("%s %d %s %s %s %.2f %.2f\n", employees[i].name, employees[i].age,
employees[i].gender, employees[i].id, employees[i].phone,
employees[i].salary, employees[i].bonus);
}
break;
case 6:
printf("欢迎下次使用!\n");
exit(0);
default:
printf("输入错误,请重新输入!\n");
break;
}
}
return 0;
}
```
以上就是一个简单的C语言人事管理系统的设计实现,可以根据需要进行修改和扩展。
阅读全文