C语言职工信息管理系统
时间: 2024-01-04 12:04:27 浏览: 89
C语言职工信息管理系统可以通过使用结构体和文件操作来实现。以下是一个简单的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100
// 定义职工结构体
typedef struct {
int id;
char name[20];
char gender[10];
int age;
char education[20];
float salary;
char address[50];
char phone[20];
} Employee;
// 菜单函数
void menu() {
printf("********** 职工信息管理系统 **********\n"); printf("1. 录入职工信息\n");
printf("2. 浏览职工信息\n"); printf("3. 查询职工信息\n");
printf("4. 删除职工信息\n");
printf("5. 修改职工信息\n");
printf("0. 退出系统\n");
printf("************************************\n");
}
// 录入职工信息函数
void input(Employee *employees, int *count) {
printf("请输入职工信息:\n");
printf("职工号:");
scanf("%d", &(employees[*count].id));
printf("姓名:");
scanf("%s", employees[*count].name);
printf("性别:");
scanf("%s", employees[*count].gender);
printf("年龄:");
scanf("%d", &(employees[*count].age));
printf("学历:");
scanf("%s", employees[*count].education);
printf("工资:");
scanf("%f", &(employees[*count].salary));
printf("住址:");
scanf("%s", employees[*count].address);
printf("电话:");
scanf("%s", employees[*count].phone);
(*count)++;
printf("录入成功!\n");
}
// 浏览职工信息函数
void browse(Employee *employees, int count) {
printf("职工信息如下:\n");
for (int i = 0; i < count; i++) {
printf("职工号:%d\n", employees[i].id);
printf("姓名:%s\n", employees[i].name);
printf("性别:%s\n", employees[i].gender);
printf("年龄:%d\n", employees[i].age);
printf("学历:%s\n", employees[i].education);
printf("工资:%.2f\n", employees[i].salary);
printf("住址:%s\n", employees[i].address);
printf("电话:%s\n", employees[i].phone); printf("--\n");
}
}
// 查询职工信息函数
void query(Employee *employees, int count) {
int choice;
printf("请选择查询方式:\n");
printf("1. 按学历查询\n");
printf("2. 按职工号查询\n");
scanf("%d", &choice);
if (choice == 1) {
char education[20];
printf("请输入学历:");
scanf("%s", education);
printf("查询结果如下:\n");
for (int i = 0; i < count; i++) {
if (strcmp(employees[i].education, education) == 0) {
printf("职工号:%d\n", employees[i].id);
printf("姓名:%s\n", employees[i].name);
printf("性别:%s\n", employees[i].gender);
printf("年龄:%d\n", employees[i].age);
printf("学历:%s\n", employees[i].education);
printf("工资:%.2f\n", employees[i].salary);
printf("住址:%s\n", employees[i].address);
printf("电话:%s\n", employees[i].phone);
printf("--\n");
}
}
} else if (choice == 2) {
int id;
printf("请输入职工号:");
scanf("%d", &id);
printf("查询结果如下:\n");
for (int i = 0; i < count; i++) {
if (employees[i].id == id) {
printf("职工号:%d\n", employees[i].id);
printf("姓名:%s\n", employees[i].name);
printf("性别:%s\n", employees[i].gender);
printf("年龄:%d\n", employees[i].age);
printf("学历:%s\n", employees[i].education);
printf("工资:%.2f\n", employees[i].salary);
printf("住址:%s\n", employees[i].address);
printf("电话:%s\n", employees[i].phone);
printf("--\n");
}
}
} else {
printf("输入有误!\n");
}
}
// 删除职工信息函数
void delete(Employee *employees, int *count) {
int id;
printf("请输入要删除的职工号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < *count; i++) {
if (employees[i].id == id) {
index = i;
break;
}
}
if (index != -1) {
for (int i = index; i < *count - 1; i++) {
employees[i] = employees[i + 1];
}
(*count)--;
printf("删除成功!\n");
} else {
printf("未找到该职工号!\n");
}
}
// 修改职工信息函数
void modify(Employee *employees, int count) {
int id;
printf("请输入要修改的职工号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < count; i++) {
if (employees[i].id == id) {
index = i;
break;
}
}
if (index != -1) {
printf("请输入新的职工信息:\n");
printf("姓名:");
scanf("%s", employees[index].name);
printf("性别:");
scanf("%s", employees[index].gender);
printf("年龄:");
scanf("%d", &(employees[index].age));
printf("学历:");
scanf("%s", employees[index].education);
printf("工资:");
scanf("%f", &(employees[index].salary));
printf("住址:");
scanf("%s", employees[index].address);
printf("电话:");
scanf("%s", employees[index].phone);
printf("修改成功!\n");
} else {
printf("未找到该职工号!\n");
}
}
int main() {
Employee employees[MAX_SIZE];
int count = 0;
int choice;
while (1) {
menu();
printf("请输入选项:");
scanf("%d", &choice);
switch (choice) {
case 1:
input(employees, &count);
break;
case 2:
browse(employees, count);
break;
case 3:
query(employees, count);
break;
case 4:
delete(employees, &count);
break;
case 5:
modify(employees, count);
break;
case 0:
printf("退出系统!\n");
exit(0);
default:
printf("输入有误!\n");
break;
}
}
return 0;
}
```
阅读全文