华北科技学院计算机系综合性实验实验报告课程名称C语言程序设计实验学期2011至2012学年第二学期学生所在系部计算机系年级2011专业班级计算机科学与技术B-111学生姓名学号任课教师实验成绩计算机系制实验报告须知学生上交实验报告时,必须为打印稿(A4纸)。
页面空间不够,可以顺延。
学生应该填写的内容包括:封面相关栏目、实验地点、时间、目的、设备环境、内容、结果及分析等。
教师根据本课程的《综合性实验指导单》中实验内容的要求,评定学生的综合性实验成绩;要求在该课程期末考试前将实验报告交给任课教师。
综合性实验中,所涉及 的程序,文档等在交实验报告前,拷贝给任课教师。
任课教师统一刻录成光盘,与 该课程的期末考试成绩一同上交到系里存档。
5、 未尽事宜,请参考该课程的实验大纲和教学大纲。
1、 2、 3、 教师应该填写的内容包括:实验成绩、教师评价等。
4、《c语言程序设计》课程综合性实验报告开课实验室:基础五2012年7月6日实验题目基于链表的学生成绩管理系统、实验目的1、掌握链表的创建、遍历显示和清除;2、掌握链表数据的文件保存、读取;—、设备与环境微型计算机、VC++6.0三、实验内容1、定义结构体,创建链表structxs node in txh;charxm[15];in tgs;in tyy;in twl;structxs no de* next;};2、根据以上链表结点结构,实现以下功能a、学生学号、姓名、各门成绩的录入;b、链表数据显示及清除;C、链表数据的文件保存与读取;四、实验结果及分析1、运行结果主菜单数据显示2、源程序主函数voidmain()intxz=O;structxs*head;head=init();while(xz!=5)menu();sca nf("%d",&xz);switch(xz)easel:create(head);break;case2:print(head);break;case3:save(head);break;case4:read(head);break;case5:printf("\n 系统退出,拜拜!\n");break;default:printf("\n 选择错误,请按任意键选择!\n");getch();break;fr(head);free(head);数据录入源代码voidcreate(structxs*hd)in txh,gs,yy,wl,i;charxm[20];structxs* p;fr(hd);printf("\n 请输入学生个数:");sca nf("%d",&nu m);for(i=0;i vnu m;i++)printf(" 请输入%c个学生of%d\n",i+1,num);prin tf("学号:");scan f("%d",& xh);prin tf(" 姓名:");prin tf("高数:");scan f("%s",xm);scan f("%d",&gs);prin tf("英语:");scan f("%d", &yy);prin tf("物理:");scan f("%d",&wl);p=(structxs*)malloc(sizeof(structxs)); p->xh=xh;strc py(p->xm,xm);p->gs=gs;p->yy=yy;p->wl=wl;p->n ext=hd->n ext;hd->n ext=p;prin tf(" 录入数据完毕,请按任意键继续!\n");getch();添加记录源代码void prin t(structxs*hd) structxs* p;p=hd->n ext;if(p!=NULL)prin tf("\n 数据显示\n");printf("**********************************************\n");printf(" 学号姓名高数英语物理平均分\n");prin tf("高数:");while( p!=NULL)prin tf("%4d",p->xh);prin tf("%10s",p->xm);prin tf("%8d",p->gs);prin tf("%7d",p->yy);prin tf("%6d",p->wl);printf("%8.2f\n",( p->wl+p->wl+p->wl)/3.0);p=p->next;printf("**********************************************\n");prin tf(" 链表显示完毕,请按任意键继续!\n");getch();elseprintf("\n 当前链表为空,请先读取文件或创建链表!\n按任意键继续!\n");查询记录源代码voidme nu()system("cls");printf("****************************************\n");printf("* 学生成绩管理系统(1.0)*\n");printf("****************************************\n");printf("*jb11-131 宋洁2012-7-3*\n");printf("****************************************\n");printf("*1-创建链表*\n");prin tf("****************************************\n"); printf("请选择操作(1-5:");#in clude"stdio.h" #in clude"stdlib.h" #i ncludevstri ng.h> #i nclude"c on prin tf("*2- 数据显示*\n"); prin tf("*3- 保存文件*\n"); prin tf("*4- 读取文件*\n"); prin tf("*5- 系统退出*\n"); 源程序io.h" structxsin txh;charxm[20];in tgs,yy,wl;structxs* next;}; intnum=0;structxs* in it()structxs*hd;hd=(structxs*)malloc( sizeof(structxs));hd-> next=NULL;returnhd;voidfr(structxs*hd)structxs* p;p=hd->n ext;while(hd-> next!=NULL)p=hd->n ext;hd->n ext=p->n ext;free( p); voidcreate(structxs*hd)in txh,gs,yy,wl,i;charxm[20];structxs* p;fr(hd);printf("\n 请输入学生个数:"); sca nf("%d",&nu m);for(i=0;i vnu m;i++)printf(" 请输入%c个学生of%d\n",i+1,num);prin tf("学号:");scan f("%d",& xh);prin tf(" 姓名:");scan f("%s",xm);prin tf("高数:");scan f("%d",&gs);prin tf("英语:");scan f("%d",& yy);prin tf("物理:");scan f("%d",&wl);p=(structxs*)malloc(sizeof(structxs));p->xh=xh;strc py(p->xm,xm);p->gs=gs;p->yy=yy;p->wl=wl;p->n ext=hd->n ext;hd->n ext=p;prin tf(" 录入数据完毕,请按任意键继续!\n"); getch();voidsave(structxs*hd)if(hd-> next!=NULL)structxs* p=hd->n ext;inti;FILE*fp;fp=fo pen( "yh.txt","w");fprin tf(fp,"%3d\n", nu m);for(i=0;i vnu m;i++)fprin tf(fp,"%3d%12s%3d%3d%3d\n", p->xh, p->xm, p->gs ,p->yy, p->wl);p=p->n ext;fclose(fp);prin tf("\n 保存文件完毕,请按任意键继续!\n");getch();elseprin tf("\n 当前链表为空,不需要保存,请按任意键继续!\n");getch();voidread(structxs*hd)inti;structxs* p;FILE*fp;fr(hd);fp=fo pen( "yh.txt","r");fscan f(fp,"%3d\n",&nu m);for(i=0;i vnu m;i++)p=(structxs*)malloc(sizeof(structxs));fscan f(fp,"%3d%12s%3d%3d%3d\n", p->xh, p->xm, p->gs ,p->yy, p->wl);p->n ext=hd->n ext;hd->n ext=p;fclose(fp);prin tf("\n 读取文件完毕,请按任意键继续!\n");getchO;void prin t(structxs*hd) structxs* p;p=hd->n ext;if(p!=NULL)prin tf("\n 数据显示\n");prin tf("**********************************************\n");printf("学号姓名高数英语物理平均分\n");while( p!=NULL)prin tf("%4d", p->xh);prin tf("%10s", p->xm);prin tf("**********************************************\n");prin tf("%8d", p->gs);prin tf("%7d", p->yy);prin tf("%6d", p->wl);prin tf("%8.2f\n",( p->wl+p->wl+p->wl)/3.0);p=p->n ext;prin tf("**********************************************\n");prin tf(" 链表显示完毕,请按任意键继续!\n");getch();elseprintf("\n 当前链表为空,请先读取文件或创建链表!\n按任意键继续!\n");voidme nu()system("cls");prin tf("****************************************\n"); printf("* 学生成绩管理系统(1.0)*\n");prin tf("****************************************\n"); printf("*jb11-131 宋洁2012-7-3*\n");prin tf("****************************************\n"); printf("*1-创建链表*\n");printf("****************************************\n ");printf("请选择操作(1-5:");voidmai n()in txz=O;structxs*head;head=i nit();prin tf("*2- 数据显示*\n"); prin tf("*3- 保存文件*\n"); prin tf("*4-读取文件*\n"); printf("*5- 系统退出*\n");while(xz!=5)menu();sea nf("%d",&xz);switch(xz)easel:create(head);break;case2:print(head);break;case3:save(head);break;case4:read(head);break;case5:printf("\n 系统退出,拜拜!\n");break;default:printf("\n 选择错误,请按任意键选择!\n");getch();break;fr(head);free(head);3、试验收获通过这次试验,我掌握了链表的创建、遍历显示和清除功能,掌握了链表数据的文件保存、读取,能够熟练的使用VC++6.0,对C程序有了更深的了解。