C语言课程设计报告学生成绩简单管理.doc

上传人:laozhun 文档编号:2384914 上传时间:2023-02-17 格式:DOC 页数:12 大小:49.50KB
返回 下载 相关 举报
C语言课程设计报告学生成绩简单管理.doc_第1页
第1页 / 共12页
C语言课程设计报告学生成绩简单管理.doc_第2页
第2页 / 共12页
C语言课程设计报告学生成绩简单管理.doc_第3页
第3页 / 共12页
C语言课程设计报告学生成绩简单管理.doc_第4页
第4页 / 共12页
C语言课程设计报告学生成绩简单管理.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《C语言课程设计报告学生成绩简单管理.doc》由会员分享,可在线阅读,更多相关《C语言课程设计报告学生成绩简单管理.doc(12页珍藏版)》请在三一办公上搜索。

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-ne

22、xt; 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; if(head=NULL) p

23、rintf(nEmpty List.n); else while(p1-next!=NULL) p2=p1;p1=p1-next; if(strcmp(p1-Name,p2-Name)=0) p2-next=p1-next; n=n-1; if (nnext!=NULL) p2=p1; p1=p1-next; free(p2); free(p1);函数关系图mainWhile循环Display_Main_MenucreateDisplayInsert_a_recordDelet_a_recordQuery_a_wordAddfromTestWritetoTextRevrseDetetSameQ

24、uiteQueryDeleteInsert七 主要算法的实现1)、建立链表,序有序插入,编一个被调用的Insert函数,用strcmp循环找到新记录插入的位置,按该位置处于不同的情况下连到链表中去。2)、要删除一条记录,输入要删除的姓名,在链表中用循环找到后,按其处于的不同位置分情况删除。3)、从文件中读入多个数据,先打开文件,在没有到文件最后时循环:开辟一个空间,将文件中的一个记录赋给该空间,调用Insert函数将该空间插入到链表中去。4)、逆序存放:先判断链表是否为空,为空输出提示,若只有一个记录,直接返回首指针。否则,依次读入链表中的记录,后面的记录插入到前面的记录的前面。5)、删除同名的记录:内部while循环控制P1指针,从头指尾结束,内部 do while循环,控制P2指针在P1到末尾之间循环,每循环一次将P1指向的姓名与P2指向的姓名进行比较,若相同,则结束本次内部循环,删除P2指向的记录,输出提示信息。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号