http://www.cnblogs.com/live-no-regrets/

队员的代码 之人力资源管理系统(本人帮debug)

题目:人力资源管理系统

长代码

  1 #include <stdio.h>
  2 #include <conio.h>
  3 #include <stdlib.h>
  4 #include <string.h>
  5 #define N 100
  6 #define format "%10s%10s%10s%10d%10s%10s%10s%10s%10s%10d %10d %10d%10s\n"
  7 #include<fstream>
  8 #include<iostream>
  9 using namespace std;
 10 
 11 typedef struct HumanResources
 12 {
 13     char No[10];     //编号
 14     char name[10];   //姓名
 15     char sex[10];    //性别
 16     int age;         //年龄
 17     char post[10];    //职务
 18     char title[20];   //职称
 19     char politic[10];            //政治面貌
 20     char diploma[10];          //最高学历
 21     char period[10];             //任职时间
 22     int s_year,s_month,s_day;   //来院时间
 23     char p_category[10];         //职工类别
 24 } HR;
 25 HR hr[N];
 26 
 27 void judge(int jdg);        //判断执行哪项操作
 28 int open();    //统计已录入的人员数
 29 void input();  //录入人员信息
 30 void add();    //添加函数
 31 void del();    //删除函数
 32 void query_No();  //按编号查询函数
 33 void query_name(); //按姓名查询函数
 34 void modify(); //修改函数
 35 void count_zzry();  //统计在职人员人数函数
 36 void count_dy();  //统计党员人数函数
 37 void count_ng();  //统计女工人数函数
 38 void count_gao();  //统计高学历高职称函数
 39 void sort_age();   //按年龄排序函数
 40 void sort_s();       //按来院时间排序函数
 41 void save(int m);    //保存函数
 42 void show();         //浏览函数
 43 
 44 int  flag = 1, menu;
 45 
 46 
 47 int main()
 48 {
 49     
 50     system("color B");
 51     printf("                              ************************************\n");
 52     printf("                                欢迎使用深圳大学人力资源管理系统   \n") ;
 53     printf("                              ************************************\n");
 54 
 55     while(flag)
 56     {
 57         do
 58         {
 59             printf("--------------------------------------------菜单栏-------------------------------------------\n");
 60             printf("                                  请输入想要实现的功能选项\n");
 61             printf("                                         1、录入功能\n");
 62             printf("                                         2、添加功能\n");
 63             printf("                                         3、删除功能\n");
 64             printf("                                         4、查询功能\n");
 65             printf("                                         5、修改功能\n");
 66             printf("                                         6、统计功能\n");
 67             printf("                                         7、排序功能\n");
 68             printf("                                         8、浏览功能\n");
 69             printf("                                         9、退出功能\n");
 70             printf("--------------------------------------------菜单栏-------------------------------------------\n");
 71             printf("请输入选项:");
 72             scanf("%d", &menu);
 73         }while (menu>9 || menu<1);
 74         judge(menu);
 75         
 76     }
 77     return 0;
 78 }
 79 
 80 void judge(int jdg)
 81 {
 82     switch (jdg)
 83     {
 84     case 1:
 85         input();
 86         break;
 87     case 2:
 88         add();
 89         break;
 90     case 3:
 91         del();
 92         break;
 93     case 4:
 94         printf("选择查询类型\n");
 95         printf("1、按编号查询\n");
 96         printf("2、按姓名查询\n");
 97         int t;
 98         scanf("%d",&t);
 99         switch(t)
100         {
101         case 1:
102             query_No();
103             break;
104         case 2:
105             query_name();
106             break;
107         }
108         break;
109     case 5:
110         modify();
111         break;
112     case 6:
113         printf("选择统计类型\n");
114         printf("1、统计在职人员数\n");
115         printf("2、统计党员人数\n");
116         printf("3、统计女工人数\n");
117         printf("4、统计高学历高职称人数\n");
118         int a;
119         scanf("%d",&a);
120         switch(a)
121         {
122         case 1:
123             count_zzry();
124             break;
125         case 2:
126             count_dy();
127             break;
128         case 3:
129             count_ng();
130             break;
131         case 4:
132             count_gao();
133             break;
134         }
135         break;
136     case 7:
137         printf("选择排序类型\n");
138         printf("1、按年龄排序\n");
139         printf("2、按来院时间排序\n");
140         int b;
141         scanf("%d",&b);
142         switch(t)
143         {
144         case 1:
145             sort_age();
146             break;
147         case 2:
148             sort_s();
149             break;
150         }
151         break;
152     case 8:
153         show();
154         break;
155     case 9:
156         flag = 0;
157         break;
158     }
159 }
160 
161 /*统计人员数函数,并把内容写入缓冲区*/
162 int open()
163 {
164     FILE *fp;
165     int i = 0;
166     if((fp = fopen("HR.txt","r")) == NULL)
167     {
168         printf("cannot open this file\n");
169         exit(0);
170     }
171     while(!feof(fp))
172     {
173         fscanf(fp,format,hr[i].No,hr[i].name,hr[i].sex,&hr[i].age,hr[i].post,
174                 hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,&hr[i].s_year,&hr[i].s_month,&hr[i].s_day,hr[i].p_category);
175         i++;
176     }
177     return i;
178     fclose(fp);
179 }
180 
181 
182 /*录入函数*/
183 void input()
184 {
185     FILE *fp;
186     int i,n;
187     if((fp = fopen("HR.txt","w")) == NULL)
188     {
189         printf("cannot open this file\n");
190         return;
191     }
192     printf("请输入要录入的人员数:");
193     scanf("%d",&n);
194     for(i = 0; i < n; i++)
195     {
196         printf("请输入人员编号:");
197         scanf("%s",hr[i].No);
198         printf("请输入人员姓名:");
199         scanf("%s",hr[i].name);
200         printf("请输入人员性别:");
201         scanf("%s",hr[i].sex);
202         printf("请输入人员年龄:");
203         scanf("%d",&hr[i].age);
204         printf("请输入人员职务:");
205         scanf("%s",hr[i].post);
206         printf("请输入人员职称:");
207         scanf("%s",hr[i].title);
208         printf("请输入人员政治面貌:");
209         scanf("%s",hr[i].politic);
210         printf("请输入人员最高学历:");
211         scanf("%s",hr[i].diploma);
212         printf("请输入人员任职时间:");
213         scanf("%s",hr[i].period);
214         printf("请输入人员来院时间:");
215         scanf("%d%d%d",&hr[i].s_year,&hr[i].s_month,&hr[i].s_day);
216         printf("请输入人员类别:");
217         scanf("%s",hr[i].p_category);
218         fprintf(fp,format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
219                 hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
220     }
221     fclose(fp);
222 }
223 
224 
225 /*添加函数*/
226 void add()
227 {
228     FILE *fp;
229     int i,n;
230     if((fp = fopen("HR.txt","a")) == NULL)
231     {
232         printf("cannot open this file\n");
233         return;
234     }
235     printf("请输入要添加的人员数:");
236     scanf("%d",&n);
237     for(i = 0; i < n; i++)
238     {
239         printf("请输入人员编号:");
240         scanf("%s",hr[i].No);
241         printf("请输入人员姓名:");
242         scanf("%s",hr[i].name);
243         printf("请输入人员性别:");
244         scanf("%s",hr[i].sex);
245         printf("请输入人员年龄:");
246         scanf("%d",&hr[i].age);
247         printf("请输入人员职务:");
248         scanf("%s",hr[i].post);
249         printf("请输入人员职称:");
250         scanf("%s",hr[i].title);
251         printf("请输入人员政治面貌:");
252         scanf("%s",hr[i].politic);
253         printf("请输入人员最高学历:");
254         scanf("%s",hr[i].diploma);
255         printf("请输入人员任职时间:");
256         scanf("%s",hr[i].period);
257         printf("请输入人员来院时间:");
258         scanf("%d%d%d",&hr[i].s_year,&hr[i].s_month,&hr[i].s_day);
259         printf("请输入人员类别:");
260         scanf("%s",hr[i].p_category);
261     }
262 
263     for(i=0; i<n; i++)
264     {
265         fprintf(fp,format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
266                 hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
267     }
268     
269     fclose(fp);
270 }
271 
272 
273 /*删除函数*/
274 void del()
275 {
276     int m = open(), i = 0, n, j, t;
277     char No[10];
278     printf("请输入要删除人员的编号:");
279     scanf("%s",No);
280     for(i = 0;i < m; i++)
281     {
282         if(strcmp(hr[i].No,No)==0)
283         {
284             printf("找到该员工!信息为:\n");
285             printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
286                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
287             printf("\n");
288             break;
289         }
290     }
291     printf("\n确认删除请输入1,不删除请输入0\n");
292     scanf("%d",&n);
293     if(n == 1)
294     {
295         for(j = i; j < m; j++)
296         {
297             hr[j] = hr[j+1];
298         }
299         m--;  //删除记录,人员数减一
300         save(m); //把人员数传给save,
301     }
302     if(i == m) //说明循环没有提前终止,即找不到此人
303     {
304         printf("\n查找失败!\n");
305         save(m);
306     }
307     printf("\n继续删除请输入1,退出删除请输入2\n");
308     scanf("%d",&t);
309     switch(t)
310     {
311     case 1:
312         del();
313         break;
314     case 2:
315         break;
316     default:
317         break;
318     }
319     printf("按任意键继续!");
320     getchar();
321 }
322 
323 
324 /*按编号查找函数*/
325 void query_No()
326 {
327     int m = open(), i = 0;
328     char No[10];
329     printf("请输入要查找的人员的编号:");
330     scanf("%s",No);
331     for(i = 0;i < m; i++)
332     {
333         if(strcmp(hr[i].No,No)==0)
334         {
335             printf("找到该员工!信息为:\n");
336             fprintf(stdout,format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
337                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
338             printf("\n");
339             break;
340         }
341     }
342     if(i == m) //说明循环没有提前终止,即找不到此人
343     {
344         printf("\n查找失败!\n");
345         return;
346     }
347     printf("按任意键继续!");
348     getchar();
349 }
350 
351 
352 /*按姓名查询函数*/
353 void query_name()
354 {
355     int m = open(), i = 0;
356     char name[10];
357     printf("请输入要查找的人员的姓名:");
358     scanf("%s",name);
359     for(i = 0;i < m; i++)
360     {
361         if(strcmp(hr[i].name,name)==0)
362         {
363             printf("找到该员工!信息为:\n");
364             fprintf(stdout,format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
365                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
366             printf("\n");
367             break;
368         }
369     }
370     if(i == m) //说明循环没有提前终止,即找不到此人
371     {
372         printf("\n查找失败!\n");
373         return;
374     }
375     printf("按任意键继续!");
376     getchar();
377 }
378 
379 
380 /*修改函数*/
381 void modify()
382 {
383     int m = open(); /*统计已录入人员数,并把信息输到缓冲区*/
384     char name[10];
385     int i, n, c;
386     printf("请输入要修改的人员的姓名:\n");  //为了检验此人是否存在
387     scanf("%s",name);
388     for(i = 0; i < m; i++)
389     {
390         if(strcmp(hr[i].name,name) == 0)  //此人存在,开始修改
391         {
392             printf("\n此人存在\n");
393             printf("确认要修改请输入1,不修改请输入0\n");
394             scanf("%d",&n);
395             if(n == 1)
396             {
397                 printf("修改的选项\n 1.编号 2.姓名 3.性别 4.年龄 5.职务 6.职称 7.政治面貌 8.最高学历 9.任职时间 10.来院时间 11.职工类别\n");
398                 printf("请输入序号:\n");
399                 scanf("%d",&c);
400                 if(c>11 || c<1)
401                 { 
402                     printf("\n输入序号不符!\n");
403                 }
404             }
405             switch(c)  //根据用户需要进行相应项的修改
406             {
407             case 1:
408                 printf("编号改为: ");
409                 scanf("%s",hr[i].No);
410                 break;
411             case 2:
412                 printf("姓名改为: ");
413                 scanf("%s",hr[i].name);
414                 break;
415             case 3:
416                 printf("性别改为: ");
417                 scanf("%s",hr[i].sex);
418                 break;
419             case 4:
420                 printf("年龄改为: ");
421                 scanf("%d",&hr[i].age);
422                 break;
423             case 5:
424                 printf("职务改为: ");
425                 scanf("%s",hr[i].post);
426                 break;
427             case 6:
428                 printf("职称改为: ");
429                 scanf("%d",hr[i].title);
430                 break;
431             case 7:
432                 printf("政治面貌改为: ");
433                 scanf("%s",hr[i].politic);
434                 break;
435             case 8:
436                 printf("最高学历改为: ");
437                 scanf("%s",hr[i].diploma);
438                 break;
439             case 9:
440                 printf("任职时间改为: ");
441                 scanf("%s",hr[i].period);
442                 break;
443             case 10:
444                 printf("来院时间改为: ");
445                 scanf("%d",&hr[i].s_year);
446                 scanf("%d",&hr[i].s_month);
447                 scanf("%d",&hr[i].s_day);
448                 break;
449             case 11:
450                 printf("职工类别改为: ");
451                 scanf("%s",hr[i].p_category);
452             default:
453                 break;
454             }
455             break;
456         }
457 
458     }
459     if(i == m)//循环正常结束
460     { 
461         printf("\n此人不存在!\n");
462     }
463     save(m);
464     printf("\n修改后的所有人员信息:\n");
465 }
466 
467 
468 /*统计在职人数函数*/
469 void count_zzry()
470 {
471     int m = open(); // 统计已录入人员数
472     int i, a = 0;
473     char p_category[10] = {"在职人员"};
474     for(i = 0; i < m; i++)
475     {
476         if(strcmp(p_category,hr[i].p_category)==0)
477         {
478             printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
479                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
480             printf("\n");
481             a++;
482         }
483     }
484     printf("在职人员数为:%d\n",a);
485 }
486 
487 
488 /*统计党员数函数*/
489 void count_dy()
490 {
491     int m = open(); // 统计已录入人员数
492     int i, a = 0;
493     char politic[10] = {"党员"};
494     for(i = 0; i < m; i++)
495     {
496         if(strcmp(politic,hr[i].politic)==0)
497         {
498             printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
499                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
500             printf("\n");
501             a++;
502         }
503     }
504     printf("党员人数为:%d\n",a);
505 }
506 
507 /*统计女工人数函数*/
508 void count_ng()
509 {
510     int m = open(); // 统计已录入人员数
511     int i, a = 0;
512     char sex[10] = {"党员"};
513     for(i = 0; i < m; i++)
514     {
515         if(strcmp(sex,hr[i].sex)==0)
516         {
517             printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
518                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
519             printf("\n");
520             a++;
521         }
522     }
523     printf("女工人数为:%d\n",a);
524 }
525 
526 /*统计高学历高职称人数函数*/
527 void count_gao()
528 {
529     int m = open(); // 统计已录入人员数
530     int i, a = 0;
531     char diploma1[10] = {"硕士"};
532     char diploma2[10] = {"博士"};
533     char diploma3[10] = {"博士后"};
534     char title1[10] = {"副教授"};
535     char title2[10] = {"教授"};
536     for(i = 0; i < m; i++)
537     {
538         if(strcmp(diploma1,hr[i].diploma)==0 || strcmp(diploma2,hr[i].diploma)==0 || strcmp(diploma3,hr[i].diploma)==0 ||
539             strcmp(title1,hr[i].title)==0 || strcmp(title2,hr[i].title)==0)
540         {
541             printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
542                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
543             printf("\n");
544             a++;
545         }
546     }
547     printf("高学历高职称人数为:%d\n",a);
548 }
549 
550 /*按年龄排序*/
551 void sort_age()
552 {
553     int m = open(); //统计已录入的人员数
554     HR p;
555     int i, j, k;
556     for (i = 0; i < m-1; i++)   /*选择排序*/
557     {
558         k = i;
559         for (j = i; j < m; j++)
560         {
561             if (hr[k].age < hr[j].age)
562             {
563                k = j;
564             }
565         }
566         if(k != i)
567         {
568             p = hr[i];
569             hr[i] = hr[k];
570             hr[k] = p;
571         }
572     }
573     for(i = 0; i < m; i++) //排好序后输出
574     {
575         printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
576                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
577         printf("\n");
578     }
579 }
580 
581 
582 /*按来院时间排序*/
583 void sort_s()
584 {
585     int m = open(); //统计已录入人员数
586     int i, k, j;
587     HR p;
588     for(i = 0; i < m-1; i++)
589     {
590         k = i;
591         for(j = i;j < m; j++)
592         {
593             if(hr[j].s_year > hr[k].s_year)
594                 k = j;
595             if(hr[j].s_year == hr[k].s_year)
596             {
597                 if(hr[j].s_month > hr[k].s_month)
598                     k = j;
599                 if(hr[j].s_month == hr[k].s_month)
600                 {
601                     if(hr[j].s_day > hr[j].s_day)
602                         k = j;
603                 }
604             }
605         }
606         if(k != i)
607         {
608             p = hr[i];
609             hr[i] = hr[k];
610             hr[k] = p;
611         }
612     }
613     for(i = 0; i < m; i++) //排好序后输出
614     {
615         printf(format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
616                    hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
617         printf("\n");
618     }
619 }
620 
621 
622 /*保存函数*/
623 void save(int m)
624 {
625     FILE *fp;
626     int i;
627     if((fp = fopen("HR.txt","w")) == NULL)
628     {
629         printf("cannot open this file\n");
630         return;
631     }
632     for(i = 0; i < m; i++)
633     {
634         cerr<<"I:"<<i<<" "<<hr[i].age<<"\n";
635         fprintf(fp,format,hr[i].No,hr[i].name,hr[i].sex,hr[i].age,hr[i].post,
636                 hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,hr[i].s_year,hr[i].s_month,hr[i].s_day,hr[i].p_category);
637         printf("\n");
638     }
639     fclose(fp);
640 }
641 
642 /*浏览函数*/
643 void show()
644 {
645     FILE *fp;
646     int i = 0, j;
647     
648     if((fp = fopen("HR.txt","r")) == NULL)
649     {
650         printf("cannot open this file\n");
651         fclose(fp);
652         return;
653     }
654     ///////////////////////////////change here(C++ I/O version)
655     /*fclose(fp);
656         >>>>>>>>>>>>#include<fstream>
657     ifstream fin("HR.txt");
658     string no,name,sex,post,title,politic,diploma,period,p_category;
659     int age,year,month,day;
660     while (fin>>no>>name>>sex>>age>>post>>title>>politic>>diploma>>period>>p_category){
661         strcpy(hr[i].No,no.c_str());
662         strcpy(hr[i].name,name.c_str());
663         strcpy(hr[i].sex,sex.c_str());
664         hr[i].age=age;
665         strcpy(hr[i].post,post.c_str());
666         strcpy(hr[i].title,title.c_str());
667         strcpy(hr[i].politic,politic.c_str());
668         strcpy(hr[i].diploma,politic.c_str());
669         strcpy(hr[i].period,period.c_str());
670         hr[i].s_year=year,hr[i].s_month=month,hr[i].s_day=day;
671         strcpy(hr[i].p_category,p_category.c_str());
672         cerr<<no<<" "<<name<<" "<<sex<<" "<<age<<" "<<post<<" "<<title<<" "<<politic<<" "<<diploma<<" "<<period<<" "<<p_category<<"\n";
673         printf("%d\n",hr[i].age);
674         i++;
675     }
676     
677     for (j=0;j<i;j++){///////////////////i------->>>>j!! 
678         printf(format,hr[j].No,hr[j].name,hr[j].sex,hr[j].age,hr[j].post,
679                hr[j].title,hr[j].politic,hr[j].diploma,hr[j].period,hr[j].s_year,hr[j].s_month,hr[j].s_day,hr[j].p_category);
680         printf("\n");
681     }//////////////i--->>>>>>>>>>j
682     fin.close();*/
683     
684     while(!feof(fp))
685     {                // 写入缓冲区,并统计人员数
686         fscanf(fp,"%s%s%s%d%s%s%s%s%s%d%d%d%s",hr[i].No,hr[i].name,hr[i].sex,&hr[i].age,hr[i].post,
687                hr[i].title,hr[i].politic,hr[i].diploma,hr[i].period,&hr[i].s_year,&hr[i].s_month,&hr[i].s_day,hr[i].p_category);
688         i++;
689     }
690     //#define format "%10s%10s%10s%10d%10s%10s%10s%10s%10s%10d %10d %10d%10s\n"
691 
692     for (j=0;j<i;j++){///////////////////i------->>>>j!! 
693         printf(format,hr[j].No,hr[j].name,hr[j].sex,hr[j].age,hr[j].post,
694                hr[j].title,hr[j].politic,hr[j].diploma,hr[j].period,hr[j].s_year,hr[j].s_month,hr[j].s_day,hr[j].p_category);
695         printf("\n");
696     }//////////////i--->>>>>>>>>>j
697     fclose(fp);
698 }

 

posted @ 2021-01-11 20:39  voyage~st~Imagine  阅读(186)  评论(0编辑  收藏  举报