人事管理系统 c语言版_人事信息管理系统c

人事管理系统 c语言版_人事信息管理系统c

int menu(){
printf("请按提示输入完成操作!\n");
printf("1.查询员工信息\n");
printf("2.统计员工数量\n");
printf("3.录入员工信息\n");
printf("4.删除员工信息\n");
printf("5.按id排序所有员工\n");
printf("6.打印所有员工信息\n");
printf("7.退出系统\n");
return 0;

}

如menu()函数所示,该系统一共有7个功能

  1. #include <stdio.h>

  2. #include <stdlib.h>

  3. #include <string.h>

  4. struct emp{

  5. int id;

  6. char name[50];

  7. struct emp * next;

  8. };

  9. struct emp * initList();

  10. struct emp * addListTailNode(struct emp * head);

  11. struct emp * deleteListNode(struct emp * head,int id);

  12. struct emp * searchEmp(struct emp * head,int id);

  13. int printList(struct emp * l);

  14. int printNode(struct emp * p);

  15. struct emp * sortList(struct emp * head);

  16. int getListLen(struct emp * head);

  17. int writeToDisk(struct emp * head);

  18. struct emp * readFromDisk();

  19. int menu();

  20. int usage(struct emp * head);

 

  1. #include "emp.h"

  2. int main(){

  3. struct emp * head;

  4. head=readFromDisk();

  5. usage(head);

  6. return 0;

  7. }

  8. struct emp * initList(){

  9. struct emp * head;

  10. head=(struct emp *)malloc(sizeof(struct emp));

  11. head->next=NULL;

  12. return head;

  13. }

  14. struct emp * addListTailNode(struct emp * head){

  15. int id;

  16. char name[50];

  17. struct emp * p, * last , * check;

  18. last = head;

  19. while(last->next!=NULL){

  20. last=last->next;

  21. }

  22. printf("依次输入:员工id号,姓名!\n");

  23. scanf("%d%s",&id,&name);

  24. check = head;

  25. while(check!=last){

  26. check=check->next;

  27. if(id==check->id){

  28. printf("添加失败!员工id号重复!\n");

  29. return head;

  30. }

  31. }

  32. p=(struct emp *)malloc(sizeof(struct emp));

  33. p->id=id;

  34. strcpy(p->name,name);

  35. last->next=p;

  36. last=p;

  37. p->next=NULL;

  38. printf("%s员工信息已添加!\n",p->name);

  39. return head;

  40. }

  41. struct emp * deleteListNode(struct emp * head,int id){

  42. struct emp * p,* q;

  43. p = head->next;

  44. while(p!=NULL){

  45. if(p->next->id==id){

  46. break;

  47. }

  48. p=p->next;

  49. }

  50. if(head->next==NULL){

  51. printf("书籍信息为空!删除失败!\n");

  52. }

  53. else{

  54. q = p->next;

  55. p->next = q->next;

  56. printf("%s书籍信息被删除!\n",q->name);

  57. free(q);

  58. }

  59. return head;

  60. }

  61. struct emp * searchEmp(struct emp * head,int id){

  62. struct emp * p;

  63. p = head->next;

  64. while(p!=NULL){

  65. if(p->id==id){

  66. break;

  67. }

  68. p=p->next;

  69. }

  70. return p;

  71. }

  72. int printNode(struct emp * p){

  73. if(p!=NULL){

  74. printf("员工id: %d 员工姓名:%s\n",p->id,p->name);

  75. }

  76. else{

  77. printf("系统内无该员工信息!\n");

  78. }

  79. return 0;

  80. }

  81. int printList(struct emp * head){

  82. struct emp * p;

  83. p = head->next;

  84. while(p!=NULL){

  85. printNode(p);

  86. p=p->next;

  87. }

  88. return 0;

  89. }

  90. struct emp * sortList(struct emp * head){

  91. struct emp * p,* q;

  92. int temp_id;

  93. char temp_name[50];

  94. for(p=head->next;p!=NULL;p=p->next){

  95. for(q=p->next;q!=NULL;q=q->next){

  96. if(p->id>q->id){

  97. temp_id = q->id;

  98. q->id = p->id;

  99. p->id = temp_id;

  100. strcpy(temp_name,q->name);

  101. strcpy(q->name,p->name);

  102. strcpy(p->name,temp_name);

  103. }

  104. }

  105. }

  106. return head;

  107. }

  108. int getListLen(struct emp * head){

  109. int len=0;

  110. struct emp * p;

  111. p=head->next;

  112. while(p!=NULL){

  113. len++;

  114. p=p->next;

  115. }

  116. return len;

  117. }

  118. int writeToDisk(struct emp * head){

  119. FILE * fp;

  120. struct emp * p;

  121. if((fp = fopen("D:\\emp.hhtx", "w")) == 0){

  122. printf("写入失败……!\n");

  123. return 0;

  124. }

  125. p=head->next;

  126. while(p!=NULL){

  127. fwrite(p,sizeof(struct emp),1,fp);

  128. printf("%d %s\n",p->id,p->name);

  129. p=p->next;

  130. }

  131. fclose(fp);

  132. return 0;

  133. }

  134. struct emp * readFromDisk(){

  135. FILE * fp;

  136. struct emp * head,* last,* p,* temp;

  137. head = initList();

  138. if((fp = fopen("D:\\emp.hhtx", "r")) == 0){

  139. printf("加载失败……未找到存档数据!\n\n");

  140. return head;

  141. }

  142. last = head;

  143. p=(struct emp *)malloc(sizeof(struct emp));

  144. while(p!=NULL){

  145. p=(struct emp *)malloc(sizeof(struct emp));

  146. fread(p,sizeof(struct emp),1,fp);

  147. printf("读取数据: %d %s\n",p->id,p->name);

  148. last->next=p;

  149. last=p;

  150. p=p->next;

  151. }

  152. fclose(fp);

  153. printf("系统数据初始化完成!");

  154. return head;

  155. }

  156. int menu(){

  157. printf("请按提示输入完成操作!\n");

  158. printf("1.查询员工信息\n");

  159. printf("2.统计员工数量\n");

  160. printf("3.录入员工信息\n");

  161. printf("4.删除员工信息\n");

  162. printf("5.按id排序所有员工\n");

  163. printf("6.打印所有员工信息\n");

  164. printf("7.退出系统\n");

  165. return 0;

  166. }

  167. int usage(struct emp * head){

  168. int x,id;

  169. struct emp * p;

  170. menu();

  171. while(1){

  172. printf("请输入序列号:");

  173. scanf("%d",&x);

  174. switch(x){

  175. case 1:

  176. printf("输入所要查询的员工的id号:");

  177. scanf("%d",&id);

  178. p = searchEmp(head,id);

  179. printNode(p);

  180. printf("---------------------------------\n");

  181. break;

  182. case 2:

  183. printf("系统中一共存在%d个员工\n",getListLen(head));

  184. break;

  185. case 3:

  186. head=addListTailNode(head);

  187. printf("---------------------------------\n");

  188. break;

  189. case 4:

  190. printf("输入所要删除的员工的id号:");

  191. scanf("%d",&id);

  192. head=deleteListNode(head,id);

  193. printf("---------------------------------\n");

  194. break;

  195. case 5:

  196. printf("排序开始……\n");

  197. head=sortList(head);

  198. printf("排序已完成!\n");

  199. printf("---------------------------------\n");

  200. break;

  201. case 6:

  202. printList(head);

  203. printf("---------------------------------\n");

  204. break;

  205. case 7:

  206. writeToDisk(head);

  207. printf("保存完成……\n");

  208. printf("已退出系统!\n");

  209. printf("---------------------------------\n");

  210. return 0;

  211. default:

  212. return 0;

  213. }

  214. }

  215. return 0;

  216. }

 

人事管理系统 c语言版_人事信息管理系统c

人事管理系统 c语言版_人事信息管理系统c

原创文章,作者:192.168.1.1,如若转载,请注明出处:https://www.224m.com/229987.html

(0)
192.168.1.1192.168.1.1
上一篇 2022年11月7日 12:04
下一篇 2022年11月7日 12:10

相关推荐

  • 鼠标指向冲锋宏 鼠标宏怎么取消?

    鼠标指向冲锋宏 魔兽世界怎么喊话宏?比如我想做一个按键叫部落勇士和我一起冲锋?鼠标宏怎么取消? 进入游戏后,按ESC键,可以看到宏命令。点击进去后,新建一个宏。输入宏命令编辑栏:/y 部落勇士!和

    投稿 2022年7月19日
  • rar和zip哪个格式好 用什么软件可以打开?

    rar和zip哪个格式好 rar和rar4选哪个?用什么软件可以打开? rar代表是的rar 5.0后版本,rar比rar4.x要好。 支持格式不同 1、rar:对RAR和ZIP全力支持; 支

    投稿 2022年7月25日
  • 世界汽车排名前十 全球车企排名?

    世界汽车排名前十 全球汽车品牌排名2020?全球车企排名? 第一名,梅赛德斯奔驰(Mercedes-Benz) . 戴姆勒集团41亿美元 第二名,丰田(Toyota) 日本  580. 丰田集团7

    投稿 2022年7月25日
  • 三星商务机全部机型 三星最早的商务手机?

    三星商务机全部机型 折叠屏是近两年手机屏幕无法回避的话题。不久前,曲面屏幕仍然是手机圈的热门话题。现在曲面屏已经成为很多手机系列旗舰车型的标准。最近折叠屏手机是追求数码产品风口浪尖用户的宠儿。但是折

    投稿 2022年7月23日
  • casio手表什么档次 卡西欧值得买吗?

    casio手表什么档次 卡西欧手表是什么档次的?卡西欧值得买吗? 卡西欧手表档次一般。初中的时候戴,中小学生用的比较多。上了大学或者已经工作不合适,运动风格太明显。你可以试试贾明的garminmo

    投稿 2022年7月16日
  • officeword办公软件 office全部软件用途?

    officeword办公软件 office四大常用软件?office全部软件用途? Office包括办公软件Word、Excel、PowerPoint、Outlook、Publisher、OneN

    投稿 2022年7月14日
  • 游戏交易平台哪个好 什么平台可以出售游戏账号?

    游戏交易平台哪个好 端游交易平台哪个好?什么平台可以出售游戏账号? 有交易猫和5173,还有网易的宝库。游戏交易中最重要的一点是不要私下和玩家交易,因为没有人能保证玩家拿到钱就跑路。所以一定要有中

    投稿 2022年7月7日
  • 电脑如何强制关机 我的电脑不能正常关机怎么办?

    电脑如何强制关机 如何强制关机?我的电脑不能正常关机怎么办? 长按电脑机箱或笔记本电源键3秒以上,即可强制关机;或同时按住【Ctrl】 【Alt】 【Delete】三键,选择关机图标关机电脑;也可

    投稿 2022年7月22日
  • 深圳电信宽带价格表 电信哪个宽带套餐性价比高?

    深圳电信宽带价格表 深圳电信宽带套餐有哪些?电信哪个宽带套餐性价比高? 深圳电信的宽带套餐更新的很快,有时候几个月就会有新的资费。套餐种类繁多,每个套餐都有合适的人群。在这里,我们可以在网上找到一

    投稿 2022年7月15日
  • 阿里巴巴物流服务平台 在阿里巴巴进货用什么物流?

    阿里巴巴物流服务平台 为什么阿里巴巴物流平台要更名为菜鸟物流?在阿里巴巴进货用什么物流? 这是延伸上下游产业的策略。这样可以扩大阿里在电商上下游产业的地图。由于竞争激烈,电子商务可以开拓新的市场,

    投稿 2022年7月21日