写一个员工通讯录管理系统的c语言代码
时间: 2023-11-09 14:04:17 浏览: 125
通讯录管理系统c语言编程
5星 · 资源好评率100%
好的,这是一个简单的员工通讯录管理系统的C语言代码,包括添加员工信息、查询员工信息、修改员工信息和删除员工信息等功能。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100
struct Employee {
char name[20];
char phone[20];
char email[30];
};
struct Employee employees[MAX_EMPLOYEES];
int numEmployees = 0;
void addEmployee() {
if (numEmployees >= MAX_EMPLOYEES) {
printf("Unable to add employee, maximum number of employees reached.\n");
return;
}
struct Employee employee;
printf("Enter employee name: ");
scanf("%s", employee.name);
printf("Enter employee phone number: ");
scanf("%s", employee.phone);
printf("Enter employee email: ");
scanf("%s", employee.email);
employees[numEmployees++] = employee;
printf("Employee added successfully.\n");
}
void searchEmployee() {
char name[20];
int found = 0;
printf("Enter employee name to search: ");
scanf("%s", name);
for (int i = 0; i < numEmployees; i++) {
if (strcmp(employees[i].name, name) == 0) {
found = 1;
printf("Employee found: %s %s %s\n", employees[i].name, employees[i].phone, employees[i].email);
}
}
if (!found) {
printf("Employee not found.\n");
}
}
void updateEmployee() {
char name[20];
int found = 0;
printf("Enter employee name to update: ");
scanf("%s", name);
for (int i = 0; i < numEmployees; i++) {
if (strcmp(employees[i].name, name) == 0) {
found = 1;
printf("Enter new phone number: ");
scanf("%s", employees[i].phone);
printf("Enter new email: ");
scanf("%s", employees[i].email);
printf("Employee updated successfully.\n");
}
}
if (!found) {
printf("Employee not found.\n");
}
}
void deleteEmployee() {
char name[20];
int found = 0;
printf("Enter employee name to delete: ");
scanf("%s", name);
for (int i = 0; i < numEmployees; i++) {
if (strcmp(employees[i].name, name) == 0) {
found = 1;
for (int j = i; j < numEmployees - 1; j++) {
employees[j] = employees[j + 1];
}
numEmployees--;
printf("Employee deleted successfully.\n");
}
}
if (!found) {
printf("Employee not found.\n");
}
}
void displayMenu() {
printf("\n");
printf("Employee Management System\n");
printf("--------------------------\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("\n");
}
int main() {
int choice;
do {
displayMenu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addEmployee();
break;
case 2:
searchEmployee();
break;
case 3:
updateEmployee();
break;
case 4:
deleteEmployee();
break;
case 5:
printf("Exiting program...\n");
break;
default:
printf("Invalid choice, please try again.\n");
break;
}
} while (choice != 5);
return 0;
}
```
这个代码使用了一个结构体来存储每个员工的姓名、电话号码和电子邮件地址。它使用一个数组来存储所有员工的信息,并提供了添加、查询、更新和删除员工的功能。
阅读全文