C语言实现职工信息管理系统:从入门到精通

这篇文章将指导你使用 C 语言创建一个职工信息管理系统。该系统不仅能存储职工信息,还能进行增删改查等操作,并支持按职工编号排序。

1. 定义结构体

首先,我们需要定义一个结构体来存储职工信息。每个职工信息包括编号、姓名、性别、出生年月、入职年月、学历、职位、地址、电话等字段。cstruct employee{ char number[10]; //编号 char name[10]; //姓名 char sex[10]; //性别 char birthday[10]; //出生年月 char date[10]; //入职年月 char degree[10]; //学历 char position[10]; //职位 char add[10]; //地址 char tel[20]; //电话 struct employee *next;}em[100], *head;

2. 文件操作

为了持久化存储职工信息,我们需要将数据保存到文件中,并在程序启动时读取数据。

2.1 读取数据cvoid read(){ FILE *fp; int i; if ((fp = fopen('职工信息.txt', 'r')) == NULL) { printf('打开文件失败!请创建一个文本文件,文件名叫职工信息

'); system('pause'); // 冻结屏幕 system('cls'); // 清屏 exit(0); } fscanf(fp, '%d ', &n); for (i = 0; i < n; i++) { fscanf(fp, '%s %s %s %s %s %s %s %s %s ', em[i].number, em[i].name, em[i].sex, em[i].birthday, em[i].date, em[i].degree, em[i].position, em[i].add, em[i].tel); } head = &em[0]; fclose(fp);}

2.2 保存数据cvoid write(){ FILE *fp; int i = 0; if ((fp = fopen('职工信息录入.txt', 'w+')) == NULL) { printf('!!!打开文件失败!!!

'); return; } fprintf(fp,'%d ',n); while(i < n) { fprintf(fp,'%s %s %s %s %s %s %s %s %s ',em[i].number, em[i].name, em[i].sex, em[i].birthday, em[i].date, em[i].degree, em[i].position, em[i].add, em[i].tel); i++; } fclose(fp);}

3. CRUD 操作

3.1 增加职工信息cvoid add(){ // ... 代码实现 ...}

3.2 显示职工信息cvoid show(){ // ... 代码实现 ...}

3.3 查询职工信息cvoid search(){ // ... 代码实现 ...}

3.4 修改职工信息cvoid modify() { // ... 代码实现 ...}

3.5 删除职工信息cvoid Delete() { // ... 代码实现 ...}

4. 排序cvoid sort() { // ... 代码实现 ...}

5. 菜单和主函数cvoid menu(){ // ... 代码实现 ...}

int main(){ // ... 代码实现 ...}

总结

这篇博客提供了一个使用 C 语言构建职工信息管理系统的基本框架。你可以根据自己的需求扩展功能,例如添加图形界面、实现更复杂的排序算法等

C语言实现职工信息管理系统:从入门到精通

原文地址: https://www.cveoy.top/t/topic/fwU4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录