C语言员工管理系统,包括,编号,姓名,性别,出生年月,电话,地址,完成查询,更新,插入,删除 所需头文件
时间: 2024-03-15 22:47:22 浏览: 22
实现一个员工管理系统需要使用到以下几个头文件:
```c
#include <stdio.h> // 标准输入输出库,用于读取用户输入和向控制台输出信息
#include <string.h> // 字符串操作库,用于复制、连接、比较字符串等操作
#include <stdlib.h> // 标准库,用于动态分配内存等操作
```
其中,`stdio.h` 库中包含了 `scanf` 和 `printf` 等用于读取用户输入和输出信息的函数,`string.h` 库中包含了 `strcpy` 和 `strcmp` 等用于字符串操作的函数,`stdlib.h` 库中包含了 `malloc` 和 `free` 等用于动态分配内存的函数。这些函数都是实现一个员工管理系统必不可少的。
相关问题
c语言员工管理系统 包含编号想,姓名,性别,电话,地址,学历,完成查询更新插入删除操作
好的,这是一个较为复杂的问题,我会尽力回答。根据您的需求,我可以为您提供一个简单的C语言员工管理系统的框架,包括以下功能:
1. 添加员工信息:从键盘输入员工编号,姓名,性别,电话,地址,学历等信息,将其保存在文件中。
2. 查询员工信息:从文件中读取员工信息,并根据用户输入的关键字(如编号、姓名、电话等)进行查询。
3. 更新员工信息:根据员工编号,修改员工的其他信息。
4. 删除员工信息:根据员工编号,从文件中删除员工信息。
下面是一个简单的C语言员工管理系统的代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct employee {
int id;
char name[20];
char gender[10];
char phone[20];
char address[50];
char education[20];
};
void add_employee() {
FILE *fp;
struct employee emp;
fp = fopen("employee.dat", "ab");
printf("Enter employee id: ");
scanf("%d", &emp.id);
printf("Enter employee name: ");
scanf("%s", emp.name);
printf("Enter employee gender: ");
scanf("%s", emp.gender);
printf("Enter employee phone: ");
scanf("%s", emp.phone);
printf("Enter employee address: ");
scanf("%s", emp.address);
printf("Enter employee education: ");
scanf("%s", emp.education);
fwrite(&emp, sizeof(emp), 1, fp);
fclose(fp);
}
void search_employee() {
FILE *fp;
struct employee emp;
int id, found = 0;
char name[20], phone[20];
printf("Enter search keyword: ");
scanf("%s", name);
fp = fopen("employee.dat", "rb");
while (fread(&emp, sizeof(emp), 1, fp)) {
if (strcmp(emp.name, name) == 0 || strcmp(emp.phone, name) == 0 || emp.id == atoi(name)) {
printf("Employee details:\n");
printf("ID: %d\n", emp.id);
printf("Name: %s\n", emp.name);
printf("Gender: %s\n", emp.gender);
printf("Phone: %s\n", emp.phone);
printf("Address: %s\n", emp.address);
printf("Education: %s\n", emp.education);
found = 1;
}
}
if (!found) {
printf("Employee not found.\n");
}
fclose(fp);
}
void update_employee() {
FILE *fp;
struct employee emp;
int id, found = 0;
fp = fopen("employee.dat", "rb+");
printf("Enter employee id to update: ");
scanf("%d", &id);
while (fread(&emp, sizeof(emp), 1, fp)) {
if (emp.id == id) {
printf("Enter new details:\n");
printf("Enter employee name: ");
scanf("%s", emp.name);
printf("Enter employee gender: ");
scanf("%s", emp.gender);
printf("Enter employee phone: ");
scanf("%s", emp.phone);
printf("Enter employee address: ");
scanf("%s", emp.address);
printf("Enter employee education: ");
scanf("%s", emp.education);
fseek(fp, -sizeof(emp), SEEK_CUR);
fwrite(&emp, sizeof(emp), 1, fp);
found = 1;
break;
}
}
if (!found) {
printf("Employee not found.\n");
}
fclose(fp);
}
void delete_employee() {
FILE *fp, *temp;
struct employee emp;
int id, found = 0;
fp = fopen("employee.dat", "rb");
temp = fopen("temp.dat", "wb");
printf("Enter employee id to delete: ");
scanf("%d", &id);
while (fread(&emp, sizeof(emp), 1, fp)) {
if (emp.id != id) {
fwrite(&emp, sizeof(emp), 1, temp);
} else {
found = 1;
}
}
if (!found) {
printf("Employee not found.\n");
} else {
printf("Employee deleted successfully.\n");
}
fclose(fp);
fclose(temp);
remove("employee.dat");
rename("temp.dat", "employee.dat");
}
int main() {
int choice;
do {
printf("Employee Management System\n");
printf("1. Add employee\n");
printf("2. Search employee\n");
printf("3. Update 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:
search_employee();
break;
case 3:
update_employee();
break;
case 4:
delete_employee();
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice.\n");
}
} while (choice != 5);
return 0;
}
```
以上是一个简单的C语言员工管理系统,包括添加、查询、更新和删除员工信息的基本功能。您可以根据自己的需求进行修改和完善。
C语言员工管理系统,包括,编号,姓名,性别,出生年月,电话,地址,完成查询,更新,插入,删除
好的,我听懂了你的问题。你需要一个C语言员工管理系统,包括编号、姓名、性别、出生年月、电话、地址,并能够完成查询、更新、插入、删除的功能。
首先,你需要定义一个员工结构体来存储每个员工的信息,结构体中应该包括编号、姓名、性别、出生年月、电话、地址等信息。例如:
```
struct employee {
int id; // 员工编号
char name[20]; // 员工姓名
char gender[10]; // 员工性别
char birth[20]; // 员工出生年月
char phone[20]; // 员工电话
char address[50]; // 员工地址
};
```
接下来,你需要实现查询、更新、插入、删除等功能。以下是一个简单的实现示例:
查询功能:
```
void search_employee(int id) {
// 将员工信息从文件中读取出来
struct employee emp;
FILE *fp = fopen("employee.dat", "rb");
while (fread(&emp, sizeof(struct employee), 1, fp) == 1) {
if (emp.id == id) { // 找到了对应的员工
printf("编号:%d\n", emp.id);
printf("姓名:%s\n", emp.name);
printf("性别:%s\n", emp.gender);
printf("出生年月:%s\n", emp.birth);
printf("电话:%s\n", emp.phone);
printf("地址:%s\n", emp.address);
fclose(fp);
return;
}
}
// 没有找到对应的员工
printf("未找到编号为%d的员工\n", id);
fclose(fp);
}
```
更新功能:
```
void update_employee(int id) {
// 将员工信息从文件中读取出来
struct employee emp;
FILE *fp = fopen("employee.dat", "rb+");
while (fread(&emp, sizeof(struct employee), 1, fp) == 1) {
if (emp.id == id) { // 找到了对应的员工
printf("请输入新员工姓名:");
scanf("%s", emp.name);
printf("请输入新员工性别:");
scanf("%s", emp.gender);
printf("请输入新员工出生年月:");
scanf("%s", emp.birth);
printf("请输入新员工电话:");
scanf("%s", emp.phone);
printf("请输入新员工地址:");
scanf("%s", emp.address);
fseek(fp, -sizeof(struct employee), SEEK_CUR); // 将文件指针移回到当前位置
fwrite(&emp, sizeof(struct employee), 1, fp); // 将更新后的员工信息写回文件
printf("更新成功!\n");
fclose(fp);
return;
}
}
// 没有找到对应的员工
printf("未找到编号为%d的员工\n", id);
fclose(fp);
}
```
插入功能:
```
void insert_employee() {
// 输入新员工信息
struct employee emp;
printf("请输入新员工编号:");
scanf("%d", &emp.id);
printf("请输入新员工姓名:");
scanf("%s", emp.name);
printf("请输入新员工性别:");
scanf("%s", emp.gender);
printf("请输入新员工出生年月:");
scanf("%s", emp.birth);
printf("请输入新员工电话:");
scanf("%s", emp.phone);
printf("请输入新员工地址:");
scanf("%s", emp.address);
// 将新员工信息写入文件
FILE *fp = fopen("employee.dat", "ab");
fwrite(&emp, sizeof(struct employee), 1, fp);
fclose(fp);
printf("插入成功!\n");
}
```
删除功能:
```
void delete_employee(int id) {
// 将员工信息从文件中读取出来并删除对应的员工
struct employee emp;
FILE *fp = fopen("employee.dat", "rb");
FILE *temp = fopen("temp.dat", "wb"); // 用于临时存放未删除的员工信息
int found = 0; // 标记是否找到对应的员工
while (fread(&emp, sizeof(struct employee), 1, fp) == 1) {
if (emp.id != id) { // 如果不是要删除的员工,就将其写入临时文件中
fwrite(&emp, sizeof(struct employee), 1, temp);
} else { // 找到了要删除的员工
found = 1;
}
}
fclose(fp);
fclose(temp);
// 将临时文件中的员工信息写回原文件
remove("employee.dat"); // 删除原文件
rename("temp.dat", "employee.dat"); // 将临时文件重命名为原文件名
if (found) {
printf("删除成功!\n");
} else {
printf("未找到编号为%d的员工\n", id);
}
}
```
以上是一个简单的C语言员工管理系统的实现示例,你可以根据自己的需求进行修改和完善。
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)