




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、c语言课程设计报告课题:学生成绩简单管理姓名:学号:-* *-实验报告要目-* *-l 一. 程序的主要功能l 二. 题目分析l 三. 遇到的问题及解决办法l 四. 感想和心得l 五. 源程序及注释l 六. 函数关系及调用图l 七. 主要算法的实现 2006年11月一,程序的主要功能用单向链表结构实现简单的学生成绩管理功能。体有成绩表的建立,从键盘输入一条记录,从文件输入多条记录,将所有记录写入文件或显示在屏幕上,以及单项数据的查询、删除,所有记录本的逆置,删除同名记录等功能。二,题目分析这个题目是三个题目中最难的一个,用到的知识最多最广,涉及到循环语句、指针、链表结构,其中还有一些比较复杂的
2、算法,所以还是有一定难度的。三,遇到的问题及解决办法1) 在编display()函数时,要控制一屏输出10个学生数据。一开始不知如何编,后想到一个变量,每输出一次让它自加一次,再取余10进行判断,便实现了。2) 在编addfrom text()函数时,一开始老打不开文件,打不开程序也就结束,后来才发现把exit(0)放在判断语句的外面了,其实文件已打开,然而发现不能像书上一样用exit(0),也不能用return,要用goto end,这样就解决了问题了。也完全实现了函数所需的功能。3) 程序都编好后,发现若这样“1”输入记录,能输出一样的。但若最开始就用功能“3”,“6”输入记录,输出就会出
3、现乱码。检查程序发现insert函数中没有考虑head=0的情况,而creat()中已经让最先输入的记录赋给head了。四,感想和心得(一) 遇到了问题,不要忙着去做,刚拿到题目的时候我完全傻了,一点思绪也没有,当时真可以说大脑一片空白,盯了题目好久,什么都不懂。可程序还是得编啊,只有好好看书,理解书上建立链表的程序,然后尝试着自己编写,调试成功后的喜悦是难以形容的,很兴奋,遇到问题时先不要忙着去做,要冷静地思考一下,根据出现的问题,去分析,猜想一下可能出现这种情况的原因。比isplay如编逆序这个函数,我索然遇到了很多的困难,也花了不少时间,可我感到非常地满意,经验教训,心得和体会也不少。虽
4、然开始时觉得好复杂,但是后来听了提示倒也还好啦。(二) 程序遇到问题时,要先想一想,算法是不是有问题,确认算法无误后,再检查有没有语法错误,比如,“;”“()”“ ”一定要检查一下,是不是写错了位置,我在编第一个create函数时,就是多写了一个分号,害的我找了两个钟头才找到。这里面,如果分号,括号写错了一个就会谬以千里。这和我们平时生活中的“差之毫厘,谬以千里,”是一个道理。(三) 算法问题,要仔细地去思考,虽然有时候很困难,但是,总是可以解决的,解决了之后,会感到非常欣慰的。比如,编第一个建立链表的函数,老师一再强调要我们把姓名按升序写入文件时。我想到,我们可不可以把文件中不是升序的姓名按
5、升序读入链表,开始以为很难,后来,终于想到了算法,心里感到异常兴奋。(四) 程序时一定要细致周密,考虑周到,想到可能出现的每一种情况,这样程序才会有生存力,例如,在这个链表中,如果是空链表怎么办,改变了链表中的内容以后要不要也改变文件中的姓名,等等,其实,现实生活中也是这样,做什么事情都要考虑周到。(五) 因为课设是我们小组共同努力的结果,在共同的编写过程中,我学到了很多知识,也了解了团队合作的重要性。五、源程序及注释# include # include # include # define null 0# define len sizeof(struct student)struct st
6、ud char name20; int score; struct stud *next; ;typedef struct stud student;int n=0;int menu_select();void display(student *head);void *query_a_record(student *head);void writetotext(student *head);void quit(student *head);student *insert_a_record(student *head);student *insert(student *head,student
7、*stud);student *create(void);student *delete(student *head,char *name);student *delete_a_record(student *head);student *query(student *head,char *student);student *addfromtext(student *head);student *reverse(student *head);student *deletesame(student *head);void main() student *head=null; for ( ; ;
8、) switch (menu_select() case 1: head=create(); system(pause); break; case 2: display(head); system(pause); break; case 3: head=insert_a_record(head); system(pause); break; case 4: head=delete_a_record(head); system(pause); break; case 5: query_a_record(head); system(pause); break; case 6: head=addfr
9、omtext(head); system(pause); break; case 7: writetotext(head); system(pause); break; case 8: head=reverse(head); system(pause); break; case 9: head=deletesame(head); system(pause); break; case 0: quit(head); printf( goodbye! n); system(pause); exit(0); int menu_select() char c; do system(cls); print
10、f(n); printf(* student management system *n); printf( 1. create list n); printf( 2. display all record n); printf( 3. insert a record n); printf( 4. delete a record n); printf( 5. query n); printf( 6. add record from a text file n); printf( 7. write to a text file n); printf( 8. resert listn); print
11、f( 9. delete the same recordn); printf( 0. quit n); printf(n); printf( input 1-9,0 : ); c=getchar(); while (c9); return (c-0);student *insert(student *head,student *stud)student *p0,*p1,*p2; p1=head; p0=stud; n=n+1; if (head!=null) while (strcmp(p0-name,p1-name)0)&(p1-next!=null) p2=p1;p1=p1-next; i
12、f (p1-next=null) p1-next=p0;p0-next=null;return(head); else if (strcmp(p0-name,p1-name)next=p0; p0-next=p1; return(head); else if (head=null) head=p0;p0-next=null;return(head);student *insert_a_record(student *head)student *stud; stud=(student *)malloc(sizeof(student); printf(please input a name and
13、 the score of him:); scanf(%s%d,stud-name,&stud-score); getchar(); return(insert(head,stud);student *create(void)student *head; char w; head=(student *)malloc(sizeof(student); printf(please input a name and the score of him:); scanf(%s%d,head-name,&head-score); getchar(); head-next=null; n=1; for(;)
14、 printf(do you want to add next record(y/n)?); w=getchar(); if (w=n|w=n) break; else if (w=y|w=y) head=insert_a_record(head);continue; else getchar(); return(head);void display(student *head)student *w; int i=1; if (head=null) printf(there is no record!); else if (head!=null) printf(now,there %d rec
15、ords are:n,n); printf( name scoren); w=head; do printf( %sttt%dn,w-name,w-score); w=w-next; i+; if (i%10=0) system(pause); system(cls); while(w!=null); student *delete(student *head,char *stud)student *p1,*p2; if (head=null)printf(nlist null! ! !n);return(head); p1=head; while(strcmp(stud,p1-name)!=
16、0)&(p1-next!=null) p2=p1;p1=p1-next; if (strcmp(stud,p1-name)=0) if (p1!=head) p2-next=p1-next;free(p1); else if (p1=head) free(head);head=p1-next; printf(delet:%sn,stud); n=n-1; else printf(%s not been found!n,stud); return(head);student *delete_a_record(student *head)char stud20,w; printf(please i
17、nput the name you want to delete:); scanf(%s,stud); getchar(); for(;) printf(are you sure(y/n)?); w=getchar(); if (w=n|w=n) break; if (w=y|w=y) delete(head,stud);break; return(head);student *query(student *head,char *stud)for(;head=head-next) if (strcmp(head-name,stud)=0)|(head=null) break; return(h
18、ead);void *query_a_record(student *head)student *w; char stud20; if (head=null) printf(empty list! !); else if (head!=null) printf(nplease input a name you want to be query:); scanf(%s,stud); w=query(head,stud); if (w=null) printf(no such record! !n); else printf( name scoren); printf( %sttt%dn,w-na
19、me,w-score); student *addfromtext(student *head)file *fp; student *stud; int i,n; char filename30; printf(please input the name of the file:); scanf(%s,filename); if(fp=fopen(filename,r)=null) printf(cannot open file! !n); return(head); fscanf(fp,%d,&n); for(i=0;iname,&stud-score); head=insert(head,
20、stud); printf(%d records have been inserted !n,n); fclose(fp); return (head);void writetotext(student *head)file *fp; student *w=head; int i; char filename30; printf(please input the name of the file:); scanf(%s,filename); printf(write to file records.txtn); if(fp=fopen(filename,w)=null) printf(cann
21、ot open file! !n); else fprintf(fp,%dn,n); for(i=0;iname,&w-score); w=w-next; printf(%d records have been written into file !n,n); fclose(fp);student *reverse(student *head)student *p1,*p2,*p3; char a20; int t,i; p1=p2=p3=head; if (head=null) printf(nempty list.n); else while(p2-next!=null) p2=p2-next; for(i=0;iname); strcpy(p1-name,p2-name); strcpy(p2-name,a); t=p1-score; p1-score=p2-score; p2-score=t; p1=p1-next; while(p3-next!=p2) p3=p3-next; p2=p3; p3=head; printf(list has been reversed!n); return(head);student *deletesame(student *head)student *p1,*p2; int t=n; p1=p2=head;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高中家长会的发言稿
- 城市适宜居住发言稿
- 生日贺卡制作课件
- 高二月考质量分析会
- 港口安全员培训
- OPPO年度公关传播方案博雅公关FINAL
- 2025版地质灾害打桩工程监理合同
- 二零二五年电子商务平台安全认证与技术支持服务合同
- 二零二五年度报刊订阅及广告合作合同范本
- 二零二五年度地质灾害点搬迁拆迁补偿协议
- 人教版九年级全一册第十四章内能的利用测试卷
- 2024年销售居间合同
- YC/T 310-2024烟草漂浮育苗基质
- 智慧公厕设备采购投标方案(技术方案技术标)
- 有限空间安全检查表
- 关于吃火锅的心得感悟
- MapInfo使用教程教学课件
- 电梯高处施工方案
- 脑梗死的健康宣教
- 医药产品经理成长手册
- 新能源汽车综合故障诊断技术PPT完整全套教学课件
评论
0/150
提交评论