新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

C语言怎么实现简单职工信息管理系统,C语言怎么实现动态数组

发布时间:2023-08-02 09:29:16

C语言怎样实现简单职工信息管理系统

要实现一个简单的职工信息管理系统,你可使用C语言来编写以下功能:
1. 定义一个职工结构体:首先,你需要定义一个职工结构体,用于存储职工的信息。结构体可以包括职工的姓名、工号、职位、部门等信息。
```c
struct Employee {
char name[50];
int id;
char position[50];
char department[50];
};
```
2. 添加职工:编写一个函数用于添加新的职工信息。该函数会从用户输入中获得职工的姓名、工号、职位和部门等信息,并将其保存到一个职工结构体数组中。
```c
void addEmployee(struct Employee *employees, int *count) {
printf("Enter employee name: ");
scanf("%s", employees[*count].name);
printf("Enter employee ID: ");
scanf("%d", &employees[*count].id);
printf("Enter employee position: ");
scanf("%s", employees[*count].position);
printf("Enter employee department: ");
scanf("%s", employees[*count].department);
(*count)++;
}
```
3. 查找职工:编写一个函数用于依照工号查找职工信息。该函数会从用户输入中获得要查找的工号,并在职工结构体数组中查找对应的职工信息,并将其打印出来。
```c
void findEmployee(struct Employee *employees, int count) {
int id;
printf("Enter employee ID to search: ");
scanf("%d", &id);
for (int i = 0; i < count; i++) {
if (employees[i].id == id) {
printf("Employee Name: %s ", employees[i].name);
printf("Employee Position: %s ", employees[i].position);
printf("Employee Department: %s ", employees[i].department);
return;
}
}
printf("Employee not found. ");
}
```
4. 显示所有职工:编写一个函数用于显示所有职工的信息。该函数会遍历职工结构体数组,并将每一个职工的信息打印出来。
```c
void displayEmployees(struct Employee *employees, int count) {
for (int i = 0; i < count; i++) {
printf("Employee Name: %s ", employees[i].name);
printf("Employee ID: %d ", employees[i].id);
printf("Employee Position: %s ", employees[i].position);
printf("Employee Department: %s ", employees[i].department);
printf(" ");
}
}
```
以上是一个简单的职工信息管理系统的实现。你可以在主函数中调用这些函数来实现区分的操作,例如添加职工、查找职工和显示所有职工等。