数据结构之学生成绩管理系统

数据结构之学生成绩管理系统

ID:22950636

大小:66.00 KB

页数:13页

时间:2018-11-02

上传者:U-21680
数据结构之学生成绩管理系统_第1页
数据结构之学生成绩管理系统_第2页
数据结构之学生成绩管理系统_第3页
数据结构之学生成绩管理系统_第4页
数据结构之学生成绩管理系统_第5页
资源描述:

《数据结构之学生成绩管理系统》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

学生成绩管理系统一、实验目的1.通过此次课程设计中学生成绩管理系统的题目,掌握链表等数据结构的基本操作方面的知识,并能灵活的解决一些基本的问题,加深对其性质及各项操作的理解;2.将所学数据结构方面的知识与一门具体的语言——C语言来进行实现,感受数据结构的强大作用,加深理解。二、试验要求管理系统中有五个要求:输入查找修改插入删除存储(1)输入要求:能够通过键盘输入和文件输入两种(2)查找要求:能够根据学生号查找单个学生的信息,也可以遍历所有学生信息(3)修改要求:能够根据学生号修改单个学生所有信息(4)插入要求:能够实现头插和尾插(5)删除要求:能够根据学生号删除单个学生信息(6)存储要求:通过链表存储所有信息三、算法的思想与算法实现步骤1.基本思想通过链表数据类型进行基本操作,主要有三个模块:分别是主函数模块、主要操作函数及基本操作函数。其中,主函数负责其他子函数的调用实现以及基本界面的操作主要函数包括:voidStuInput(Student*);//学生成绩管理系统的输入函数,由主函数调用voidStuSelect(Student*);//学生成绩管理系统的查找函数,由主函数调用voidStuAlter(Student*);//学生成绩管理系统的修改函数,由主函数调用voidStuInsert(Student*);//学生成绩管理系统的插入函数,由主函数调用voidStuDelect(Student*);//学生成绩管理系统的删除函数,由主函数调用 voidStuSave(Student*);//学生成绩管理系统的存储函数,由主函数调用基本操作函数:voidStuOutput(Student*p);//输出函数intStuImport(Student*head,Student*p);//输入函数voidStuInputHand(Student*head);//学生成绩管理系统的手动输入函数,由输入函数调用voidStuInputFile(Student*head);//学生成绩管理系统的文件输入函数,由输入函数调用voidStuSelectErg(Student*head);//学生成绩管理系统的遍历函数,由查找函数调用voidStuSelectNumFind(Student*head);//学生成绩管理系统的按学号查找函数,由查找函数调用voidStuSelectSubFind(Student*head);//学生成绩管理系统的按科目查找函数,由查找函数调用2.实现步骤首先,分析题目要求划分实现模块,定义基本数据类型,诸如结构体、链表等;其次,针对上述的基本操作实现具体需要进行的操作,具体实现每个环节需要进行的基本操作,即具体编写每个小函数实现功能;最后,编写主函数对每个实现进行按需调用,实现操作。3.流程图 mainStuMainStuInputStuSelectStuAlterStuInsertStuDelectStuSaveStuInputHandStuInputFileStuSelectErgStuSelectNumFindStuSelectSubFind四.代码:#include#include#includestructStudent{charname[10];charsubject[10];intnum;intgrade;Student*next;};voidStuMain();//学生成绩管理系统的主函数,由main函数调用voidStuInput(Student*);//学生成绩管理系统的输入函数,由主函数调用voidStuSelect(Student*);//学生成绩管理系统的查找函数,由主函数调用voidStuAlter(Student*);//学生成绩管理系统的修改函数,由主函数调用voidStuInsert(Student*);//学生成绩管理系统的插入函数,由主函数调用voidStuDelect(Student*);//学生成绩管理系统的删除函数,由主函数调用voidStuSave(Student*);//学生成绩管理系统的存储函数,由主函数调用voidStuOutput(Student*p);//输出函数intStuImport(Student*head,Student*p);//输入函数 voidStuOutput(Student*p)//打印函数,将链表的该节点信息输出{printf("学生姓名:");printf("%s",p->name);printf("学生号:");printf("%d",p->num);printf("科目:");printf("%s",p->subject);printf("学生成绩:");printf("%d ",p->grade);}intStuImport(Student*head,Student*p){Student*Opinion=(Student*)malloc(sizeof(Student));//用来判断输入节点中学生号是否有重复Opinion=head->next;printf("学生姓名: ");scanf("%s",p->name);printf("学生号: ");scanf("%d",&p->num);printf("科目: ");scanf("%s",p->subject);if(Opinion!=NULL){if(Opinion->num==p->num&&!strcmp(Opinion->subject,p->subject)){printf("该学生这门科目已有成绩,请重新输入 ");return1;}Opinion=Opinion->next;}printf("学生成绩: ");scanf("%d",&p->grade);return0;}voidmain(){StuMain();}voidStuMain(){chardecide='y';//定义while变量,函数是否继续进行intnum=1; //定义switch变量,函数跳转到哪个子函数Student*head;//定义链表的头指针head=(Student*)malloc(sizeof(Student));//给头指针开辟空间head->next=NULL;//初始化头指针while(decide!='n'){printf("*************************************************** ");printf("**********1输入2查找3修改4插入******** ");printf("**********5删除6存储7退出******** ");printf("*************************************************** ");scanf("%d",&num);switch(num){case1:StuInput(head);break;case2:StuSelect(head);break;case3:StuAlter(head);break;case4:StuInsert(head);break;case5:StuDelect(head);break;case6:StuSave(head);break;default:decide='n';break;}};}voidStuInputHand(Student*head);//学生成绩管理系统的手动输入函数,由输入函数调用voidStuInputFile(Student*head);//学生成绩管理系统的文件输入函数,由输入函数调用voidStuInput(Student*head)//学生成绩管理系统的输入函数,由主函数调用 {chardecide='y';//定义while变量,函数是否继续进行intnum;//定义switch变量,函数跳转到哪个子函数while(decide!='n'){printf("*************************************************** ");printf("**1手动输入2文件输入3退出** ");printf("*************************************************** ");scanf("%d",&num);switch(num){case1:StuInputHand(head);break;case2:StuInputFile(head);default:decide='n';break;}}}voidStuInputHand(Student*head)//学生成绩管理系统的手动输入函数,由输入函数调用{if(head->next==NULL){Student*point=(Student*)malloc(sizeof(Student));//链表中最后一个节点,只在该函数中存在point->next=NULL;intdecide=1;while(decide!=0){Student*p=(Student*)malloc(sizeof(Student));p->next=NULL;StuImport(head,p);if(head->next==NULL){head->next=p;point=p;}else{ point->next=p;point=p;}printf("是否继续:1/0 ");scanf("%d",&decide);}}elseprintf("管理系统中已存在信息,若想输入学生信息,请转插入子系统");}voidStuInputFile(Student*head)//学生成绩管理系统的文件输入函数,由输入函数调用{if(head->next!=NULL){printf("学生管理系统中已有信息,请跳转到插入选项 ");return;}FILE*fp;printf("请输入文件名(包括物理地址) ");charfilename[10];scanf("%s",filename);if((fp=fopen(filename,"r"))==NULL){printf("cannotopenfile ");return;}Student*point=(Student*)malloc(sizeof(Student));Student*Opinion=(Student*)malloc(sizeof(Student));//用来判断输入节点中学生号是否有重复while(!feof(fp)){Opinion=head->next;Student*p=(Student*)malloc(sizeof(Student));p->next=NULL;fread(p,sizeof(Student),1,fp);if(Opinion!=NULL){if(Opinion->num==p->num&&!strcmp(Opinion->subject,p->subject)){printf("该文件中有重复学生信息,请验明再传输 ");head->next=NULL;return;}Opinion=Opinion->next;} if(head->next==NULL){head->next=p;point=p;}else{point->next=p;point=p;}};Opinion=head->next;while(Opinion->next!=NULL){Opinion=Opinion->next;if(Opinion->next->next==NULL)Opinion->next=NULL;};fclose(fp);printf("传输成功 ");}voidStuSelectErg(Student*head);//学生成绩管理系统的遍历函数,由查找函数调用voidStuSelectNumFind(Student*head);//学生成绩管理系统的按学号查找函数,由查找函数调用voidStuSelectSubFind(Student*head);//学生成绩管理系统的按科目查找函数,由查找函数调用voidStuSelect(Student*head)//学生成绩管理系统的查找函数,由主函数调用{chardecide='y';//定义while变量,函数是否继续进行intnum;//定义switch变量,函数跳转到哪个子函数while(decide!='n'){printf("*************************************************** ");printf("****1遍历2学号查找3科目查找4退出**** ");printf("*************************************************** ");scanf("%d",&num);switch(num){case1:StuSelectErg(head);break; case2:StuSelectNumFind(head);break;case3:StuSelectSubFind(head);break;default:decide='n';break;}}}voidStuSelectErg(Student*head)//学生成绩管理系统的遍历函数,由查找函数调用{Student*p=(Student*)malloc(sizeof(Student));p=head->next;inti=1;while(p!=NULL){printf("第%d位学生信息: ",i);StuOutput(p);p=p->next;i++;}}voidStuSelectNumFind(Student*head)//学生成绩管理系统的查找子系统,有查找函数调用{intnum;printf("输入想要查找学生的学生号: ");scanf("%d",&num);Student*p=(Student*)malloc(sizeof(Student));p=head->next;inti=1;while(p!=NULL){if(num==p->num){StuOutput(p);i++;}p=p->next;}if(i==1) printf("没有该学生信息");}voidStuSelectSubFind(Student*head)//学生成绩管理系统的按科目查找函数,由查找函数调用{charSub[10];printf("输入想要查找科目: ");scanf("%s",Sub);Student*p=(Student*)malloc(sizeof(Student));p=head->next;inti=1;while(p!=NULL){if(!strcmp(Sub,p->subject)){StuOutput(p);i++;}p=p->next;}if(i==1)printf("没有该学生信息");}voidStuAlter(Student*head)//学生成绩管理系统的修改函数,由主函数调用{intnum;printf("输入想要查找学生的学生号: ");scanf("%d",&num);charSub[10];printf("输入想要查找科目: ");scanf("%s",Sub);Student*p=(Student*)malloc(sizeof(Student));p=head->next;inti=1;while(p!=NULL){if(num==p->num&&!strcmp(Sub,p->subject)){printf("输入修改成绩: ");scanf("%d",&p->grade);printf("修改成功 ");i++;}p=p->next; if(i==1)printf("没有该学生信息");}}voidStuInsert(Student*head)//学生成绩管理系统的插入函数,由主函数调用{Student*point=(Student*)malloc(sizeof(Student));point=head->next;while(point->next!=NULL)point=point->next;//找到尾结点chardecide='y';//定义while变量,函数是否继续进行intnum;//定义switch变量,函数跳转到哪个子函数while(decide!='n'){printf("*************************************************** ");printf("****1头插2尾插3退出**** ");printf("*************************************************** ");scanf("%d",&num);Student*p=(Student*)malloc(sizeof(Student));switch(num){case1:StuImport(head,p);p->next=head->next;head->next=p;printf("插入成功 ");break;case2:StuImport(head,p);point->next=p;p->next=NULL;printf("插入成功 ");break;default:decide='n';break;}}}voidStuDelect(Student*head)//学生成绩管理系统的删除函数,由主函数调用{ intnum;printf("输入想要删除学生的学生号: ");scanf("%d",&num);charSub[10];printf("输入想要删除科目: ");scanf("%s",Sub);Student*p=(Student*)malloc(sizeof(Student));p->next=head->next;inti=1;while(p->next!=NULL){if(num==p->next->num&&!strcmp(Sub,p->next->subject)){StuOutput(p->next);printf("是否删除:1/0 ");scanf("%d",&i);if(num==head->next->num&&!strcmp(Sub,head->next->subject)){head->next=head->next->next;}else{p->next=p->next->next;}i=2;printf("删除成功 ");break;}p=p->next;}if(i==1)printf("没有该学生信息 ");}voidStuSave(Student*head)//学生成绩管理系统的存储函数,由主函数调用{FILE*fp;charfilename[10];printf("请输入存储文件名(包括物理地址) ");scanf("%s",filename);Student*p=(Student*)malloc(sizeof(Student));p=head->next; if((fp=fopen(filename,"w"))==NULL){printf("cannotopenfile");return;}printf("inputdata:/n");while(p!=NULL){fwrite(p,sizeof(Student),1,fp);/*成块写入文件*/p=p->next;}fclose(fp);}

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
关闭