数据结构之学生成绩_第1页
数据结构之学生成绩_第2页
数据结构之学生成绩_第3页
数据结构之学生成绩_第4页
数据结构之学生成绩_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论