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


要实现一个简单的职工信息管理系统,可以使用C语言结合文件操作来实现。以下是一个简单的示例:
```c
#include
#include
#define MAX_EMPLOYEES 100
struct Employee {
char name[50];
int age;
float salary;
};
void addEmployee(struct Employee employees[], int* count);
void displayEmployees(struct Employee employees[], int count);
int main() {
struct Employee employees[MAX_EMPLOYEES];
int count = 0;
int choice;
do {
printf("1. Add employee\n");
printf("2. Display employees\n");
printf("3. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
addEmployee(employees, &count);
break;
case 2:
displayEmployees(employees, count);
break;
case 3:
printf("Exiting program\n");
break;
default:
printf("Invalid choice\n");
break;
}
} while(choice != 3);
return 0;
}
void addEmployee(struct Employee employees[], int* count) {
if (*count >= MAX_EMPLOYEES) {
printf("Maximum number of employees reached\n");
return;
}
printf("Enter employee name: ");
scanf("%s", employees[*count].name);
printf("Enter employee age: ");
scanf("%d", &employees[*count].age);
printf("Enter employee salary: ");
scanf("%f", &employees[*count].salary);
(*count)++;
}
void displayEmployees(struct Employee employees[], int count) {
if (count == 0) {
printf("No employees to display\n");
return;
}
printf("Employee information:\n");
for (int i = 0; i < count; i++) {
printf("Name: %s\n", employees[i].name);
printf("Age: %d\n", employees[i].age);
printf("Salary: %.2f\n", employees[i].salary);
printf("--------------------\n");
}
}
```
这个示例代码中,定义了一个结构体 `Employee` 表示职工的信息,包含了姓名、年龄和工资。使用 `addEmployee` 函数可以添加职工,使用 `displayEmployees` 函数可以显示所有职工的信息。
程序通过一个循环菜单实现交互,用户可以选择添加职工、显示职工信息或退出程序。
在实际使用中,可以将职工信息保存到文件中,比如使用 `fopen` 函数打开一个文件,使用 `fprintf` 函数将职工信息写入文件,使用 `fscanf` 函数从文件读取职工信息。


上一篇:Java文件读取的进度条怎么实现

下一篇:美国稳定高防服务器租用怎么维护


Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器