C语言课程设计实验报告_第1页
C语言课程设计实验报告_第2页
C语言课程设计实验报告_第3页
C语言课程设计实验报告_第4页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、一实验题目:人事管理说明及要求 实现红河学院工学院人事信息(编号、姓名、年龄、职务、职称、政治面貌、最高学历、人员类别)的新增、修改、删除、按编号查找,及按职称(助教、讲师、副教授、教授)和性别统计工人数的功能。注意,人事编号不能重复。提示 ( 1)用一个文件存放人事信息。( 2)定义结构体表示人员信息。( 3)分别编写函数实现人事信息的新增、修改、删除、按编号查找、按职称和性别统计工人数的功能。( 4)编写 main 函数调用上述函数进行演示。二实验目的:1. 完成 C 语言程序设计课程的教学之后, 通过一周的课程设计可以进一步巩固所学知识,加深理解。2. 指导和促使学生通过各种途径对 C

2、语言相关技术内容进行拓展和深入, 增强自学能力,软件开发能力等综合能力的培训。三实验要求:1. 掌握 C语言程序设计有关的专业基础知识和程序设计的基本方法。2. 学会利用程序的三种基本结构: 顺序结构,选择结构, 循环结构解决不同的问题。3. 学会根据实际需要定义变量及类型。4. 掌握过程和函数的定义和调用方法。5. 学会程序调试的基本方法。四实验思路:( 1) 添加删除功能:能根据学院人事的变动情况,添加删除记录。( 2) 查询功能:能根据编号和姓名进行查询。( 3) 编辑功能(高级):根据查询对相应的记录进行修改并记录。( 4) 统计功能:能根据多种参数进行人员的统计(在职人数、党员人数、

3、女工人数, 高学历高职称人数),统计要求同时显示被统计着的信息。( 5) 排序功能:按照年龄、来院时间进行排序。( 6) 保存功能:能对输入的数据进行相应的存储。人事管理系统增删删删删删加除除除除除人人人人人人员员员员员员信信信信信信息息息息息息五实验过程:1、定义结构struct staffchar num10;char name20;char sex10;int age;char title20;char p_landscape30;char Qualifications30;int Service_time;char come_time30;char category30;staff10

4、0;2、主程序进入主菜单函数void main()menu();/*主菜单函数*/void menu()char w0;dosystem("cls");fflush(stdin); /*清除缓冲区输入 */puts("*高校人事管理系统*nn");puts("tttt1)puts("tttt2)puts("tttt3)puts("tttt4)puts("tttt5)puts("tttt6)puts("tttt7)增加人员信息删除人员信息查询人员信息修改人员信息统计人员信息保存人员信息浏

5、览人员信息n");n");n");n");n");n");n");puts("tttt8)printf("tttt退出 n");请选择 bb");w0=getchar();while(w0<'1'|w0>'9');switch(w0-48)case 1:add();break;case 2:delete_data();break;case 3:search();break;case 4:modify();break;case 5:stasti

6、c();break;case 6:save();break;case 7:browse();break;case 8:break;( 1)查询功能int search_data()/*查找单个数据函数int i,flag;char s30,w0;system("cls");/*清屏 */n=load();dofflush(stdin); /*清除缓冲区输入printf("通过 1) 编号2)w0=getchar();*/*/姓名bb");while(w0<'1'|w0>'2');if(w0='1'

7、;)/*按编号查找 */flag=0;puts("输入人员编号 :");scanf("%s",s);for(i=0;i<n;i+)if(strcmp(s,staffi.num)=0)printf_face();printf_one(staffi);flag=1;break;else continue;if(flag=0)puts(" 该人员不存在 !");return i;void search()int k;char w1; loop: k=search_data();dofflush(stdin); /*清除缓冲区输入*/p

8、rintf("1)回主菜单2) 退出 3)继续查询 bb");w1=getchar();while(w1<'1'|w1>'3');if(w1='1')menu();else if(w1='2')exit(0);else goto loop;(2)增加人员信息void add()char w0,w1;loop: system("cls");puts("请输入编号( 如 001):");scanf("%s",s.num);if(test(s.n

9、um)goto loop;/*编号重复*/puts("请输入姓名:");scanf("%s",);puts("请输入性别( 男, 女):");scanf("%s",s.sex);puts("请输入年龄:");scanf("%d",&s.age);puts(" 请输入职务 ( 教授 副教授 讲师 助教 学生 后勤人员 ):"); scanf("%s",s.duty);puts(" 请输入职称( 无初级 高级

10、):");scanf("%s",s.title);puts(" 请输入政治面貌( 党员 非党员 ):");scanf("%s",s.p_landscape);puts(" 请输入最高学历( 小学 初中高中 大学 硕士学位更高 ):");scanf("%s",s.Qualifications);puts("请输入人员类别 ( 行政人员教师 一般员工退休人员临时工 ):");scanf("%s",s.category);dofflush(stdin)

11、;/*清除缓冲区输入 */printf("是否保存 ?1) 是2)否 bb");w0=getchar();while(w0<'1'|w0>'2');switch(w0-48)case 1:single_save(s);break;case 2:break;dofflush(stdin); /*清除缓冲区输入*/printf("1)继续增加人员信息2)回主菜单3)退出 bb");w1=getchar();while(w1<'1'|w1>'3');if(w1='1

12、')goto loop;else if(w1='2')menu();else exit(0);(3)保存信息void save()char w0;save_all();printf("所有信息已保存 !n");dofflush(stdin); /* printf("1)清除缓冲区输入回主菜单2)退出*/ bb");w0=getchar();while(w0<'1'|w0>'2');if(w0='1')menu();else exit(0);void save_all()/

13、*保存所有数据函数*/int i;FILE *fp;if(fp=fopen("text.txt","wb")=NULL)printf("无法打开文件 !");exit(0);for(i=0;i<n;i+)if(staffi.age!=0)fprintf(fp,"%s %s %s %d %s %s %s %s %sn",staffi.num,,staff i.sex,staffi.age,staffi.duty,staffi.title,staffi.p_landscape,staffi.

14、Qualifications,staffi.category); else continue;fclose(fp);int test(char h10)/*检查编号是否重复*/int i;n=load();for(i=0;i<n;i+)if(strcmp(h,staffi.num)=0)puts("输入的编号有重复! 请重新输入编号!");system("pause");return 1;return 0;void save_all()/*保存所有数据函数*/int i;FILE *fp;if(fp=fopen("text.txt&quo

15、t;,"wb")=NULL)printf("无法打开文件 !");exit(0);for(i=0;i<n;i+)if(staffi.age!=0)fprintf(fp,"%s %s %s %d %s %s %s %s %sn",staffi.num,,staff i.sex,staffi.age,staffi.duty,staffi.title,staffi.p_landscape,staffi.Qualifications,staffi.category); else continue;fclose(fp

16、);(4)删除人员void delete_data()int k;char w0,w1;loop: k=search_data();if(k<n)Dofflush(stdin);printf("确认要删除该人员信息?1) 是2) 否bb");w0=getchar();while(w0<'1'|w0>'2');if(w0='1')staffk.age=0;save_all();puts("该人员信息已被删除!");Dofflush(stdin);printf("1)继续删除数据2)

17、 回主菜单3) 退出 bb");w1=getchar();while(w1<'1'|w1>'3');if(w1='1') goto loop;else if(w1='2')menu();else exit(0);( 5)修改人员信息void modify()int k=0,w0,g;char h30,w1,w2;loop: g=search_data();if(g<n)doputs("ttt修改:1)编号 ");puts("ttt2)姓名 ");puts(&quo

18、t;ttt3)性别 ");puts("ttt4)年龄 ");puts("ttt5)职务 ");puts("ttt6)职称 ");puts("ttt7)政治面貌 ");puts("ttt8)最高学历 ");puts("ttt9)人员类别 ");printf("请选择 : bb");scanf("%d",&w0);while(w0<1|w0>11);switch(w0)case 1:puts("请输入

19、新编号 :");scanf("%s",h);strcpy(staffg.num,h);break;case 2:puts("请输入姓名 :");scanf("%s",h);strcpy(,h);break;case 3:puts("请输入性别 :");scanf("%s",h);strcpy(staffg.sex,h);break;case 4:puts("请输入年龄 :");scanf("%d",&k);staff

20、g.age=k;break;case 5:puts("请输入职务 :");scanf("%s",h);strcpy(staffg.duty,h);break;case 6:puts("请输入职称 :");scanf("%s",h);strcpy(staffg.title,h);break;case 7:puts("请输入政治面貌 :");scanf("%s",h);strcpy(staffg.p_landscape,h);break;case 8:puts("请输入

21、最高学历 :");scanf("%s",h);strcpy(staffg.Qualifications,h);break;case 9:puts("请输入人员类别 :");scanf("%s",h);strcpy(staffg.category,h);break;dofflush(stdin);printf("是否保存?1) 保存2)否 bb");w1=getchar();while(w1<'1'|w1>'2');if(w1='1')save_a

22、ll(); puts("保存修改成功!");dofflush(stdin);printf("1)继续 修改2) 回主 菜单3) 退出 bb");w2=getchar();while(w2<'1'|w2>'3');if(w2='1')goto loop;else if(w2='2')menu();else exit(0);(6)统计人员信息void stastic()int i,count;char w0,w1;n=load();if(n=0)puts(" 没有数据 !&

23、quot;);getchar();menu();loop: system("cls");dofflush(stdin); /*清除缓冲区输入 */printf("通过 1)在职人员2)党员 n");printf("3)女工人数4)最高学历 bb");w0=getchar();while(w0<'1'|w0>'4');if(w0='1')/*统计在职人员*/printf_face();for(i=0,count=0;i<n&&staffi.age;i+)i

24、f(strcmp(staffi.category,"退休人员")!=0&&strcmp(staffi.category,"临时工 ")!=0)count+; printf_one(staffi);printf("tttt共有 %d条记录 ",count);else if(w0='2')/*统计党员*/printf_face();for(i=0,count=0;i<n;i+)if(strcmp(staffi.p_landscape,"党员 ")=0)count+; printf_

25、one(staffi);printf("tttt共有 %d条记录 ",count);else if(w0='3')/*统计女工人员printf_face();for(i=0,count=0;i<n;i+)if(strcmp(staffi.sex,"*/女 ")=0)count+; printf_one(staffi);printf("tttt共有 %d条记录 ",count);else/* 统计高学历人员 */printf_face();for(i=0,count=0;i<n;i+)if(strcmp(st

26、affi.Qualifications,"硕士学位")=0|strcmp(staffi.Qualifications,"更高 ")=0)count+; printf_one(staffi);printf("tttt共有 %d条记录 ",count);doprintf("n1)fflush(stdin); /*清除缓冲区输入 */继续统计2)回主菜单3)退出 bb");w1=getchar();while(w1<'1'|w1>'3');if(w1='1')

27、goto loop;else if(w1='2')menu();else exit(0);六实验调试和结果:实验调试出现的一些错误及解决方案:1, 语法错误,如没加分号,大括号等,根据错误提示找到错误地方改正错误。2,未定义,有些变量没定义就直接使用导致错误,找到未定义的变量根据实际要求定义再使用。调试结果:七实验小结:通过本次试验我对本学期所学的 C 语言程序设计有了更深的理解, 通过自己所学的知识加以老师网络的帮助完成了本次的课程设计, 我学到了很多, 不仅是课程中的知识,还有一种靠自己动手解决问题的能力。在编程中我遇到了很多困难,有的错误我根本不知道我哪里出错了, 获取到

28、老师或同学的帮助后我积极动手解决问题,最终完成了自己的课程设计。八附录(程序源代码)#include<stdlib.h>#include <stdio.h>#include <string.h>struct staff char num10;char name20;char sex10;int age;char duty20;char title20;char p_landscape30;char Qualifications30;/* char category30;/*学历 */人员类别 */staff100;struct staff s;int n;v

29、oid menu();void printf_face()/*显示数据结构项目函数*/printf("编号姓名性别年龄职务职称 政治面貌学历人员类别n");void printf_one(struct staff p)/*输出单个数据函数*/printf("%-4s%-7s%-5s%-3d%-7s%-5s%-8s%-12s%-3sn",p.num,,p.sex,p.age,p.duty,p.title,p.p_landscape,p.Qualifications,p.category);int load()/*加载函数 */int i=0;F

30、ILE *fp;if(fp=fopen("text.txt","rb")=NULL)return 0;exit(0);for(i=0;!feof(fp);i+) /* 输出数据到结构体 */fscanf(fp,"%s %s %s %d %s %s %s %s %sn",staffi.num,,staffi .sex,&staffi.age,staffi.duty,staffi.title,staffi.p_landscape,staffi .Qualifications,staffi.category);

31、fclose(fp);return i;int search_data()/*查找单个数据函数int i,flag;char s30,w0;system("cls");/*清屏 */n=load();dofflush(stdin); /*清除缓冲区输入 */printf("通过 1) 编号2)w0=getchar();*/姓名bb");while(w0<'1'|w0>'2');if(w0='1')/*按编号查找 */flag=0;puts("输入人员编号 :");scanf(

32、"%s",s);for(i=0;i<n;i+)if(strcmp(s,staffi.num)=0)printf_face();printf_one(staffi);flag=1;break;else continue;if(flag=0)puts(" 该人员不存在 !");return i;void save_all()/*保存所有数据函数*/int i;FILE *fp;if(fp=fopen("text.txt","wb")=NULL)printf("无法打开文件 !");exit(0

33、);for(i=0;i<n;i+)if(staffi.age!=0)fprintf(fp,"%s %s %s %d %s %s %s %s %sn",staffi.num,,staff i.sex,staffi.age,staffi.duty,staffi.title,staffi.p_landscape,staffi.Qualifications,staffi.category); else continue;fclose(fp);int test(char h10)/*检查编号是否重复*/int i;n=load();for(i=0;i<

34、;n;i+)if(strcmp(h,staffi.num)=0)puts("输入的编号有重复! 请重新输入编号!");system("pause");return 1;return 0;void single_save(struct staff p)/*保存单个数据函数*/ FILE *fp; if(fp=fopen("text.txt","ab+")=NULL)printf("无法打开文件 !");exit(0);fprintf(fp,"%s %s %s %d %s %s %s %s

35、 %sn",p.num,,p.sex,p.age,p.duty, p.title,p.p_landscape,p.Qualifications,p.category);printf("该信息已成功保存!n");fclose(fp);/*修改模块*/void modify()int k=0,w0,g;char h30,w1,w2;loop: g=search_data();if(g<n)doputs("ttt修改:1)编号 ");puts("ttt2)姓名 ");puts("ttt3)性别 &quo

36、t;);puts("ttt4)年龄 ");puts("ttt5)职务 ");puts("ttt6)职称 ");puts("ttt7)政治面貌 ");puts("ttt8)最高学历 ");puts("ttt9)人员类别 ");printf("请选择 : bb");scanf("%d",&w0);while(w0<1|w0>11);switch(w0)case 1:puts("请输入新编号 :");s

37、canf("%s",h);strcpy(staffg.num,h);break;case 2:puts("请输入姓名 :");scanf("%s",h);strcpy(,h);break;case 3:puts("请输入性别 :");scanf("%s",h);strcpy(staffg.sex,h);break;case 4:puts("请输入年龄 :");scanf("%d",&k);staffg.age=k;break;

38、case 5:puts("请输入职务 :");scanf("%s",h);strcpy(staffg.duty,h);break;case 6:puts("请输入职称 :");scanf("%s",h);strcpy(staffg.title,h);break;case 7:puts("请输入政治面貌 :");scanf("%s",h);strcpy(staffg.p_landscape,h);break;case 8:puts("请输入最高学历 :");

39、scanf("%s",h);strcpy(staffg.Qualifications,h);break;case 9:puts("请输入人员类别 :");scanf("%s",h);strcpy(staffg.category,h);break;dofflush(stdin); /*清除缓冲区输入 */printf("是否保存 ?1) 保存 2)否 bb");w1=getchar();while(w1<'1'|w1>'2');if(w1='1')save_

40、all(); puts("保存修改成功 !");dofflush(stdin); /*清除缓冲区输入 */printf("1)继续修改2) 回主菜单3) 退出 bb");w2=getchar();while(w2<'1'|w2>'3');if(w2='1')goto loop;else if(w2='2')menu();else exit(0);/*保存模块 */void save()char w0;save_all();printf("所有信息已保存 !n"

41、);dofflush(stdin); /*清除缓冲区输入 */printf("1)回主菜单w0=getchar();while(w0<'1'|w0>'2');if(w0='1')menu();else exit(0);2)退出 bb");/*查找模块*/void search()int k;char w1; loop: k=search_data();dofflush(stdin); /*清除缓冲区输入*/printf("1)回主菜单2) 退出 3)继续查询 bb");w1=getchar();

42、while(w1<'1'|w1>'3');if(w1='1')menu();else if(w1='2')exit(0);else goto loop;/*增加模块*/void add()char w0,w1;loop: system("cls");puts(" 请输入编号 ( 如 001):");scanf("%s",s.num);if(test(s.num)goto loop;/*puts(" 请输入姓名 :");编号重复*/scanf

43、("%s",);puts(" 请输入性别 ( 男 , 女):");scanf("%s",s.sex);puts(" 请输入年龄 :");scanf("%d",&s.age);puts(" 请输入职务 ( 教授 副教授 讲师 助教 学生 后勤人员 ):"); scanf("%s",s.duty);puts(" 请输入职称( 无初级 高级 ):");scanf("%s",s.title);puts(&

44、quot; 请输入政治面貌( 党员 非党员 ):");scanf("%s",s.p_landscape);puts(" 请输入最高学历 ( 小学 初中 高中 大学 硕士学位 更高 ):"); scanf("%s",s.Qualifications);puts("请输入人员类别 ( 行政人员教师 一般员工退休人员临时工 ):");scanf("%s",s.category);dofflush(stdin);/*清除缓冲区输入 */printf("是否保存 ?1) 是2)否 bb

45、");w0=getchar();while(w0<'1'|w0>'2');switch(w0-48)case 1:single_save(s);break;case 2:break;dofflush(stdin);printf("1)继续增加人员信息2)回主菜单3)退出 bb");w1=getchar();while(w1<'1'|w1>'3');if(w1='1')goto loop;else if(w1='2')menu();else exi

46、t(0);/*删除 模块 */void delete_data()int k;char w0,w1;loop: k=search_data();if(k<n)Dofflush(stdin);printf("确 认 要 删 除 该 人 员 信 息 ?1) 是2) 否bb");w0=getchar();while(w0<'1'|w0>'2');if(w0='1')staffk.age=0;save_all();puts(" 该人员信息已被删除!");Dofflush(stdin);printf

47、("1)继续删除数据2)回主菜单3)退出bb");w1=getchar();while(w1<'1'|w1>'3');if(w1='1') goto loop;else if(w1='2')menu();else exit(0);/*统计模块*/void stastic()int i,count;char w0,w1;n=load();if(n=0)puts(" 没有数据 !");getchar();menu();loop:system("cls");doff

48、lush(stdin); /*清除缓冲区输入printf("通过 1) 在职人员2)printf("3)女工人数4)*/党员 n");最高学历 bb");w0=getchar();while(w0<'1'|w0>'4');if(w0='1')/*统计在职人员*/printf_face();for(i=0,count=0;i<n&&staffi.age;i+)if(strcmp(staffi.category,"退休人员")!=0&&strcmp(staffi.category,&q

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论