C语言课程设计实验报告.docx
- 文档编号:15096913
- 上传时间:2023-06-30
- 格式:DOCX
- 页数:35
- 大小:60.90KB
C语言课程设计实验报告.docx
《C语言课程设计实验报告.docx》由会员分享,可在线阅读,更多相关《C语言课程设计实验报告.docx(35页珍藏版)》请在冰点文库上搜索。
C语言课程设计实验报告
一.实验题目:
人事管理
[说明及要求]
实现红河学院工学院人事信息(编号、姓名、年龄、职务、职称、政治面貌、最高学历、人员类别)的新增、修改、删除、按编号查找,及按职称(助教、讲师、副教授、教授)和性别统计工人数的功能。
注意,人事编号不能重复。
[提示]
(1)用一个文件存放人事信息。
(2)定义结构体表示人员信息。
(3)分别编写函数实现人事信息的新增、修改、删除、按编号查找、按职称和性别统计工人数的功能。
(4)编写main函数调用上述函数进行演示。
二.实验目的:
1.完成C语言程序设计课程的教学之后,通过一周的课程设计可以进一步巩固所学知识,加深理解。
2.指导和促使学生通过各种途径对C语言相关技术内容进行拓展和深入,增强自学能力,软件开发能力等综合能力的培训。
三.实验要求:
1.掌握《C语言程序设计》有关的专业基础知识和程序设计的基本方法。
2.学会利用程序的三种基本结构:
顺序结构,选择结构,循环结构解决不同的问题。
3.学会根据实际需要定义变量及类型。
4.掌握过程和函数的定义和调用方法。
5.学会程序调试的基本方法。
四.实验思路:
(1)添加删除功能:
能根据学院人事的变动情况,添加删除记录。
(2)查询功能:
能根据编号和姓名进行查询。
(3)编辑功能(高级):
根据查询对相应的记录进行修改并记录。
(4)统计功能:
能根据多种参数进行人员的统计(在职人数、党员人数、女工
人数,高学历高职称人数),统计要求同时显示被统计着的信息。
(5)排序功能:
按照年龄、来院时间进行排序。
(6)保存功能:
能对输入的数据进行相应的存储。
五.实验过程:
1、定义结构
structstaff
{
charnum[10];
charname[20];
charsex[10];
intage;
chartitle[20];
charp_landscape[30];
charQualifications[30];
intService_time;
charcome_time[30];
charcategory[30];
}staff[100];
2、主程序
进入主菜单函数
voidmain()
{
menu();
}
/*******************主菜单函数***************************/
voidmenu()
{
charw0;
do
{
system("cls");
fflush(stdin);/*清除缓冲区输入*/
puts("******************高校人事管理系统*****************\n\n");
puts("\t\t\t\t1)增加人员信息\n");
puts("\t\t\t\t2)删除人员信息\n");
puts("\t\t\t\t3)查询人员信息\n");
puts("\t\t\t\t4)修改人员信息\n");
puts("\t\t\t\t5)统计人员信息\n");
puts("\t\t\t\t6)保存人员信息\n");
puts("\t\t\t\t7)浏览人员信息\n");
puts("\t\t\t\t8)退出\n");
printf("\t\t\t\t请选择[]\b\b");
w0=getchar();
}
while(w0<'1'||w0>'9');
switch(w0-48)
{
case1:
add();break;
case2:
delete_data();break;
case3:
search();break;
case4:
modify();break;
case5:
stastic();break;
case6:
save();break;
case7:
browse();break;
case8:
break;
}
}
(1)查询功能
intsearch_data()/*查找单个数据函数*/
{
inti,flag;
chars[30],w0;
system("cls");/*清屏*/
n=load();
do
{
fflush(stdin);/*清除缓冲区输入*/
printf("通过1)编号2)姓名[]\b\b");
w0=getchar();
}
while(w0<'1'||w0>'2');
if(w0=='1')
{/*按编号查找*/
flag=0;
puts("输入人员编号:
");
scanf("%s",s);
for(i=0;i { if(strcmp(s,staff[i].num)==0) { printf_face(); printf_one(staff[i]); flag=1;break; } elsecontinue; } if(flag==0) puts("该人员不存在! "); } returni; } voidsearch() { intk;charw1;loop: k=search_data(); do { fflush(stdin);/*清除缓冲区输入*/ printf("1)回主菜单2)退出3)继续查询[]\b\b"); w1=getchar();}while(w1<'1'||w1>'3'); if(w1=='1')menu(); elseif(w1=='2')exit(0); elsegotoloop; } (2)增加人员信息 voidadd() { charw0,w1; loop: system("cls"); puts("请输入编号(如001): "); scanf("%s",s.num); if(test(s.num))gotoloop;/*编号重复*/ puts("请输入姓名: "); scanf("%s",s.name); puts("请输入性别(男,女): "); scanf("%s",s.sex); puts("请输入年龄: "); scanf("%d",&s.age); puts("请输入职务(教授副教授讲师助教学生后勤人员): "); scanf("%s",s.duty); puts("请输入职称(无初级高级): "); scanf("%s",s.title); puts("请输入政治面貌(党员非党员): "); scanf("%s",s.p_landscape); puts("请输入最高学历(小学初中高中大学硕士学位更高): "); scanf("%s",s.Qualifications); puts("请输入人员类别(行政人员教师一般员工退休人员临时工): "); scanf("%s",s.category); do { fflush(stdin);/*清除缓冲区输入*/ printf("是否保存? 1)是2)否[]\b\b"); w0=getchar();}while(w0<'1'||w0>'2'); switch(w0-48) { case1: single_save(s);break; case2: break; } do { fflush(stdin);/*清除缓冲区输入*/ printf("1)继续增加人员信息2)回主菜单3)退出[]\b\b"); w1=getchar(); } while(w1<'1'||w1>'3'); if(w1=='1')gotoloop; elseif(w1=='2')menu(); elseexit(0); } (3)保存信息 voidsave() { charw0; save_all(); printf("所有信息已保存! \n"); do { fflush(stdin);/*清除缓冲区输入*/ printf("1)回主菜单2)退出[]\b\b"); w0=getchar(); } while(w0<'1'||w0>'2'); if(w0=='1')menu(); elseexit(0); } voidsave_all()/*保存所有数据函数*/ { inti; FILE*fp; if((fp=fopen("text.txt","wb"))==NULL) { printf("无法打开文件! "); exit(0); } for(i=0;i { if(staff[i].age! =0) fprintf(fp,"%s%s%s%d%s%s%s%s%s\n",staff[i].num,staff[i].name,staff[i].sex,staff[i].age,staff[i].duty,staff[i].title, staff[i].p_landscape,staff[i].Qualifications,staff[i].category); elsecontinue; } fclose(fp); } inttest(charh[10])/*检查编号是否重复*/ { inti; n=load(); for(i=0;i if(strcmp(h,staff[i].num)==0) { puts("输入的编号有重复! 请重新输入编号! "); system("pause"); return1; } return0; } voidsave_all()/*保存所有数据函数*/ { inti; FILE*fp; if((fp=fopen("text.txt","wb"))==NULL) { printf("无法打开文件! "); exit(0); } for(i=0;i { if(staff[i].age! =0) fprintf(fp,"%s%s%s%d%s%s%s%s%s\n",staff[i].num,staff[i].name,staff[i].sex,staff[i].age,staff[i].duty,staff[i].title, staff[i].p_landscape,staff[i].Qualifications,staff[i].category); elsecontinue; } fclose(fp); } (4)删除人员 voiddelete_data() { intk; charw0,w1; loop: k=search_data(); if(k { Do { fflush(stdin); printf("确认要删除该人员信息? 1)是2)否[]\b\b");w0=getchar();}while(w0<'1'||w0>'2');if(w0=='1') { staff[k].age=0; save_all(); puts("该人员信息已被删除! "); } } Do { fflush(stdin); printf("1)继续删除数据2)回主菜单3)退出[]\b\b");w1=getchar(); } while(w1<'1'||w1>'3'); if(w1=='1')gotoloop; elseif(w1=='2')menu(); elseexit(0); } (5)修改人员信息 voidmodify() { intk=0,w0,g; charh[30],w1,w2; loop: g=search_data(); if(g { do { puts("\t\t\t修改: 1)编号"); puts("\t\t\t2)姓名"); puts("\t\t\t3)性别"); puts("\t\t\t4)年龄"); puts("\t\t\t5)职务"); puts("\t\t\t6)职称"); puts("\t\t\t7)政治面貌"); puts("\t\t\t8)最高学历"); puts("\t\t\t9)人员类别"); printf("请选择: []\b\b"); scanf("%d",&w0); } while(w0<1||w0>11); switch(w0) { case1: puts("请输入新编号: "); scanf("%s",h);strcpy(staff[g].num,h);break; case2: puts("请输入姓名: "); scanf("%s",h);strcpy(staff[g].name,h);break; case3: puts("请输入性别: "); scanf("%s",h);strcpy(staff[g].sex,h);break; case4: puts("请输入年龄: "); scanf("%d",&k);staff[g].age=k;break; case5: puts("请输入职务: "); scanf("%s",h);strcpy(staff[g].duty,h);break; case6: puts("请输入职称: "); scanf("%s",h);strcpy(staff[g].title,h);break; case7: puts("请输入政治面貌: "); scanf("%s",h);strcpy(staff[g].p_landscape,h);break; case8: puts("请输入最高学历: "); scanf("%s",h);strcpy(staff[g].Qualifications,h);break; case9: puts("请输入人员类别: "); scanf("%s",h);strcpy(staff[g].category,h);break; } do { fflush(stdin); printf("是否保存? 1)保存2)否[]\b\b"); w1=getchar();}while(w1<'1'||w1>'2'); if(w1=='1'){save_all();puts("保存修改成功! "); } } do { fflush(stdin); printf("1)继续修改2)回主菜单3)退出[]\b\b");w2=getchar();}while(w2<'1'||w2>'3'); if(w2=='1')gotoloop; elseif(w2=='2')menu(); elseexit(0); } (6)统计人员信息 voidstastic() { inti,count; charw0,w1; n=load(); if(n==0) { puts("没有数据! "); getchar();menu(); } loop: system("cls"); do { fflush(stdin);/*清除缓冲区输入*/ printf("通过1)在职人员2)党员\n"); printf("3)女工人数4)最高学历[]\b\b"); w0=getchar();}while(w0<'1'||w0>'4'); if(w0=='1') {/*统计在职人员*/ printf_face(); for(i=0,count=0;i if(strcmp(staff[i].category,"退休人员")! =0&&strcmp(staff[i].category,"临时工")! =0) { count++;printf_one(staff[i]); } printf("\t\t\t\t共有%d条记录",count); } elseif(w0=='2') {/*统计党员*/ printf_face(); for(i=0,count=0;i if(strcmp(staff[i].p_landscape,"党员")==0) { count++;printf_one(staff[i]); } printf("\t\t\t\t共有%d条记录",count); } elseif(w0=='3'){/*统计女工人员*/ printf_face(); for(i=0,count=0;i if(strcmp(staff[i].sex,"女")==0) { count++;printf_one(staff[i]); } printf("\t\t\t\t共有%d条记录",count); } else { /*统计高学历人员*/ printf_face(); for(i=0,count=0;i if(strcmp(staff[i].Qualifications,"硕士学位")==0||strcmp(staff[i].Qualifications,"更高")==0) { count++;printf_one(staff[i]); } printf("\t\t\t\t共有%d条记录",count); } do { fflush(stdin);/*清除缓冲区输入*/ printf("\n1)继续统计2)回主菜单3)退出[]\b\b"); w1=getchar();}while(w1<'1'||w1>'3'); if(w1=='1')gotoloop; elseif(w1=='2')menu(); elseexit(0); } 六.实验调试和结果: 实验调试出现的一些错误及解决方案: 1,语法错误,如没加分号,大括号等,根据错误提示找到错误地方改正错误。 2,未定义,有些变量没定义就直接使用导致错误,找到未定义的变量根据实际要求定义再使用。 调试结果: 七.实验小结: 通过本次试验我对本学期所学的C语言程序设计有了更深的理解,通过自己所学的知识加以老师网络的帮助完成了本次的课程设计,我学到了很多,不仅是课程中的知识,还有一种靠自己动手解决问题的能力。 在编程中我遇到了很多困难,有的错误我根本不知道我哪里出错了,获取到老师或同学的帮助后我积极动手解决问题,最终完成了自己的课程设计。 八.附录(程序源代码) #include #include #include structstaff {charnum[10]; charname[20]; charsex[10]; intage; charduty[20]; chartitle[20]; charp_landscape[30]; charQualifications[30];/*学历*/ charcategory[30];/*人员类别*/ } staff[100]; structstaffs; intn; voidmenu(); voidprintf_face()/*显示数据结构项目函数*/ { printf("编号姓名性别年龄职务职称政治面貌学历人员类别\n"); } voidprintf_one(structstaffp)/*输出单个数据函数*/ { printf("%-4s%-7s%-5s%-3d%-7s%-5s%-8s%-12s%-3s\n",p.num,p.name,p.sex,p.age,p.duty,p.title p.p_landscape,p.Qualifications,p.category); } intload()/*加载函数*/ { inti=0; FILE*fp; if((fp=fopen("text.txt","rb"))==NULL) { return0; exit(0); } for(i=0;! feof(fp);i++) {/*输出数据到结构体*/ fscanf(fp,"%s%s%s%d%s%s%s%s%s\n",staff[i].num,staff[i].name,staff[i].sex, &staff[i].age,staff[i].duty,staff[i].title,staff[i].p_landscape,staff[i].Qualifications,staff[i].category); } fclose(fp); returni; } intsearch_data()/*查找单个数据函数*/ { inti,flag; chars[30],w0; system("cls");/*清屏*/ n=load(); do { fflush(stdin);/*清除缓冲区输入*/ printf("通过1)编号2)姓名[]\b\b"); w0=getchar(); } while(w0<'1'||w0>'2'); if(w0=='1') {/*按编号查找*/ flag=0; puts("输入人员编号: "); scanf("%s",s); for(i=0;i {
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 课程设计 实验 报告