职工信息管理系统c语言
时间: 2023-09-25 15:06:15 浏览: 130
职工信息管理系统是一种常见的管理系统,它可以帮助企业和组织管理员工的基本信息、工作信息以及其他相关信息。以下是一个简单的职工信息管理系统的C语言代码示例,供您参考:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_WORKERS 100
struct worker {
char name[20];
int age;
char gender;
int salary;
};
int num_workers = 0;
struct worker workers[MAX_WORKERS];
int main() {
int choice;
while (1) {
printf("Welcome to the worker information management system!\n");
printf("1. Add a new worker\n");
printf("2. Delete a worker\n");
printf("3. Modify a worker\n");
printf("4. Search for a worker\n");
printf("5. Display all workers\n");
printf("6. Exit\n");
printf("Please enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_worker();
break;
case 2:
delete_worker();
break;
case 3:
modify_worker();
break;
case 4:
search_worker();
break;
case 5:
display_workers();
break;
case 6:
exit(0);
default:
printf("Invalid choice! Please try again.\n");
}
}
return 0;
}
void add_worker() {
if (num_workers == MAX_WORKERS) {
printf("The maximum number of workers has been reached!\n");
return;
}
printf("Please enter the name of the worker: ");
scanf("%s", workers[num_workers].name);
printf("Please enter the age of the worker: ");
scanf("%d", &workers[num_workers].age);
printf("Please enter the gender of the worker (M/F): ");
scanf(" %c", &workers[num_workers].gender);
printf("Please enter the salary of the worker: ");
scanf("%d", &workers[num_workers].salary);
printf("New worker added successfully!\n");
num_workers++;
}
void delete_worker() {
char name[20];
int i, j;
printf("Please enter the name of the worker to delete: ");
scanf("%s", name);
for (i = 0; i < num_workers; i++) {
if (strcmp(name, workers[i].name) == 0) {
for (j = i; j < num_workers - 1; j++) {
workers[j] = workers[j + 1];
}
num_workers--;
printf("Worker deleted successfully!\n");
return;
}
}
printf("Worker not found!\n");
}
void modify_worker() {
char name[20];
int i;
printf("Please enter the name of the worker to modify: ");
scanf("%s", name);
for (i = 0; i < num_workers; i++) {
if (strcmp(name, workers[i].name) == 0) {
printf("Please enter the new age of the worker: ");
scanf("%d", &workers[i].age);
printf("Please enter the new gender of the worker (M/F): ");
scanf(" %c", &workers[i].gender);
printf("Please enter the new salary of the worker: ");
scanf("%d", &workers[i].salary);
printf("Worker modified successfully!\n");
return;
}
}
printf("Worker not found!\n");
}
void search_worker() {
char name[20];
int i;
printf("Please enter the name of the worker to search for: ");
scanf("%s", name);
for (i = 0; i < num_workers; i++) {
if (strcmp(name, workers[i].name) == 0) {
printf("Name: %s\n", workers[i].name);
printf("Age: %d\n", workers[i].age);
printf("Gender: %c\n", workers[i].gender);
printf("Salary: %d\n", workers[i].salary);
return;
}
}
printf("Worker not found!\n");
}
void display_workers() {
int i;
printf("Name\tAge\tGender\tSalary\n");
for (i = 0; i < num_workers; i++) {
printf("%s\t%d\t%c\t%d\n", workers[i].name, workers[i].age, workers[i].gender, workers[i].salary);
}
}
```
这个示例代码中使用了结构体来存储职工的基本信息,包括姓名、年龄、性别和工资。程序提供了添加、删除、修改、查找和显示职工信息的功能。注意,这只是一个简单的示例,实际的职工信息管理系统可能会更加复杂和完善。
阅读全文