学生成绩信息表_第1页
学生成绩信息表_第2页
学生成绩信息表_第3页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

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

文档简介

1、# in clude<stdio.h># in clude<stdlib.h># in clude<stri ng.h> typedef struct stude nt int ij;char no10;char n ame10;float score2;float average;stude nt;typedef struct linkstude nt ia;struct link*n ext;List;/录入数据List *in putO()List *p;stude nt x;p=NULL;x.average=O;int i=0;float y=0;f

2、flush(stdi n);puts("t请输入学生学号:(输0结束)"); gets(x. no);if(strcmp(x .n o,"0")!=0)puts("t 请输入学生姓名:"); gets(x .n ame);puts("t 请输入数学成绩:");scan f("%f", &x.score0);y=y+x.score0;puts("t请输入英语成绩:");scan f("%f", &x.score1); y=y+x.score1

3、;x.average=y/2.0;p=(List *)malloc(sizeof(List);strcpy(p->ia .no,x.no);strcpy(p->ia .n ame,x .n ame);for(i=0;i<2;i+)p->ia.scorei=x.scorei;p->ia.average=x.average;p-> next=NULL;return p;/创建链表List *creat_List()int ix;List *head,*p,*tail;head=(List*)malloc(sizeof(List);head-> next=N

4、ULL;tail=head;p=i nputO();while(p!=NULL)tail->n ext=p;tail=p;tail-> next=NULL;p=i nputO();retur n head;/遍历链表void output_List(List *head) int i;i nt ii=1;平均成绩");List *p=head->n ext;puts("t 序号t学 号t姓 名t数学t英语t while(p!=NULL)prin tf("t%d",ii);ii+;prin tf("t%s",p->

5、;ia. no);prin tf("t%s",p->ia .n ame);for(i=0;i<2;i+)prin tf("t%-4.1f',p->ia.scorei);prin tf("t%-4.1fn",p->ia.average);p=p->n ext;List *in put1()/插入数据的学生信息List *p;char ix10;int i=0;float y=0;fflush(stdi n);puts("请输入学生学号:"); gets(ix);p=(List *)mall

6、oc(sizeof(List); strcpy(p->ia .n o,ix);puts("t请输入学生姓名:”);gets(p->ia .n ame);puts("t请输入数学成绩:”); scan f("%f",&p->ia.score0); y=y+p_>ia.scoreO;puts("t请输入英语成绩:”);scan f("%f",&p->ia.score1); y=y+p->ia.score1;p->ia.average=y/2.0;p-> next=N

7、ULL;return p;/链表的插入void in sert_List(List *head,List *p) List *q,*s;s=(List *)malloc(sizeof(List);s=p;q=head;while(strcmp(q->n ext->ia .no ,s->ia .no)<=0)q=q_>n ext;if(q-> next=NULL)break;s->n ext=q->n ext;q_>n ext=s;List *outputO(List *p)/输出某位学生的信息int i;puts("t学号t姓名t

8、数学t英语t平均成绩");prin tf("t%s",p->ia. no);prin tf("t%s",p->ia. name);for(i=0;i<2;i+)prin tf("t%-4.1f',p->ia.scorei);prin tf("t%-4.1fn",p->ia.average); return p;/查找学生信息void fin d1_List(List *head)List *p;char ix1O;int ii=0;fflush(stdi n);p=head-&

9、gt;n ext;puts("请输入学生学号:");gets(ix);while(1)if(p=NULL)if(ii=0) puts("不存在此学号的学生信息break;break;while(strcmp(ix,p->ia. no )=0)outputO(p);if(p-> next=NULL)break;p=p->n ext;ii+;p=p->n ext;List *find2(List *head)/ 查找指定节点List *p;char ix10;fflush(stdi n);p=head->n ext;puts("

10、输入查找学生的学号:”);while(p!=NULL&&strcmp(ix,p->ia. no)!=0)p=p->n ext;return p;List *delete_List(List *head,List *p)/ 链表的删除List *q=head,*s=head->n ext;while(s!=NULL&&strcmp(p->ia. no,s->ia. no )!=0)q=s;s=s->n ext;q->n ext=s->n ext;free(s);retur n head;int length_List

11、(List *head)/ 链表长度List *p=head;int ii=0;while(p-> next!=NULL)p=p->n ext;ii+;return ii;List *fin d3(List *head,i nt ij)List *p;i nt ii;fflush(stdi n);p=head->n ext; while(p!=NULL&&i i!=ij) ii+; p=p->n ext;return p;List *paixu(List *head)List *p,*q,*large;/查找指定节点/*排序*/float itemp;c

12、har ctemp10;for(p=head->n ext;p->n ext!=NULL;p=p->n ext) for(q=p->n ext;q!=NULL;q=q_>n ext) large=p;if(p->ia.average<q->ia.average) large=q;if(large=q)strcpy(ctemp,p->ia. no); strcpy(p->ia .no,q->ia .no);strcpy(q->ia .no, ctemp);strcpy(ctemp,p->ia. name); strcp

13、y(p->ia .n ame,q->ia .n ame); strcpy(q->ia .n ame,ctemp); for(i=0;i<2;i+)itemp=p->ia.scorei; p->ia.scorei=q->ia.scorei; q->ia.scorei=itemp;itemp=p->ia.average;p->ia.average=q->ia.average; q->ia.average=itemp;return(head);/链表菜单int menu()int ii=0;puts("tt欢迎进入链表

14、系统”);puts("=");/*界面设计*/puts("|tt请选择下列某一项 ttt|");puts("|ttt(1)创建ttt|");puts("|ttt(2)序号输出ttt|");puts("|ttt(3)查找ttt|");puts("|ttt(4)插入ttt|");puts("|ttt(5)删除ttt|");puts("|ttt(6)成绩输出ttt|");puts(” =");dofflush(stdi n);put

15、s("请输入你的选择:”);scan f("%d", &i i);while(ii<1|ii>7);return ii;void mai n()int ii,l,ij,ix,in;List *head,*p;dosystem("cls");/* 清屏函数*/fflush(stdin);/* 清除键盘缓冲区*/ii=me nu();switch(ii)case 1: head=creat_List(); puts(" break;case 2: output_List(head);break;case 3: fin d1_List(head);break;case 4: p=in put1();in sert_List(head,p); puts("插入成功");break;case 5: p=fi nd2(head);i

温馨提示

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

评论

0/150

提交评论