经典C源码之竞技比赛打分系统.doc_第1页
经典C源码之竞技比赛打分系统.doc_第2页
经典C源码之竞技比赛打分系统.doc_第3页
经典C源码之竞技比赛打分系统.doc_第4页
经典C源码之竞技比赛打分系统.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

竞技比赛打分系统#include #defineJUDEGNUM3 /* 裁判数 */#define NAMELEN20/* 姓名最大字符数 */#define CODELEN10/* 号码最大字符数 */#define FNAMELEN80/* 文件名最大字符数 */#define BUFFSIZE128/* 缓冲区最大字符数 */char judgementJUDEGNUMNAMELEN+1 = judgementA,judgementB,judgementC;struct AthleteScorecharnameNAMELEN+1;/* 姓名 */char codeCODELEN+1;/* 学号 */int scoreJUDEGNUM;/* 各裁判给的成绩 */int total; /* 总成级 */;struct LinkNodecharnameNAMELEN+1;/* 姓名 */char codeCODELEN+1;/* 号码 */int scoreJUDEGNUM;/* 各裁判给的成绩 */int total; /* 总成级 */structLinkNode *next;*head;/* 链表首指针 */int totalJUDEGNUM;/* 各裁判给的总成绩 */FILE *filepoint;/* 文件指针 */char filenameFNAMELEN;/* 文件名 */* 从指定文件读入一个记录 */int GetRecord(FILE *fpt,struct AthleteScore *sturecord)char bufBUFFSIZE;int i;if(fscanf(fpt,%s,buf)!=1)return 0;/* 文件结束 */strncpy(sturecord-name,buf,NAMELEN);fscanf(fpt,%s,buf);strncpy(sturecord-code,buf,CODELEN);for(i=0;iscorei);for(sturecord-total=0,i=0;itotal+=sturecord-scorei;return 1;/* 对指定文件写入一个记录 */void PutRecord(FILE *fpt,struct AthleteScore *sturecord)int i;fprintf(fpt,%sn,sturecord-name);fprintf(fpt,%sn,sturecord-code);for(i=0;iscorei);return ;/* 显示运动员记录 */void ShowAthleteRecord(struct AthleteScore *rpt)int i;printf(nName : %sn,rpt-name);printf(Code : %sn,rpt-code);printf(score :n);for(i=0;iscorei);printf(Total : %4dn,rpt-total);/* 列表显示运动员成绩 */void Listathleteinfo(char *fname)FILE *fp;struct AthleteScore s;clrscr();if(fp=fopen(fname,r)=NULL)printf(Cant open file %s.n,fname);return ;while(GetRecord(fp,&s)!=0)ShowAthleteRecord(&s);fclose(fp);return;/* 构造链表 */struct LinkNode *CreatLinklist(char *fname)FILE *fp;struct AthleteScore s;struct LinkNode *p,*u,*v,*h;int i;if(fp=fopen(fname,r)=NULL)printf(Cant open file %s.n,fname);return NULL;h=NULL;p=(struct LinkNode *)malloc(sizeof(struct LinkNode);while(GetRecord(fp,(struct AthleteScore *)p)!=0)v=h;while(v&p-totaltotal)u=v;v=v-next;if(v=h)h=p;elseu-next=p;p-next=v;p=(struct LinkNode *)malloc(sizeof(struct LinkNode);free(p);fclose(fp);return h;/* 顺序显示链表各表元 */void OutputLinklist(struct LinkNode *h)clrscr();while(h!=NULL)ShowAthleteRecord(struct AthleteScore *)h);printf(n);while(getchar()!=n);h=h-next;return;/* 按运动员姓名查找记录 */int SearchbyName(char *fname, char *key)FILE *fp;int c;struct AthleteScore s;clrscr();if(fp=fopen(fname,r)=NULL)printf(Cant open file %s.n,fname);return 0;c=0;while(GetRecord(fp,&s)!=0)if(strcmp(,key)=0)ShowAthleteRecord(&s);c+;fclose(fp);if(c=0)printf(The athlete %s is not in the file %s.n,key,fname);return 1;/* 按运动员号码查找记录 */int SearchbyCode(char *fname, char *key)FILE *fp;int c;struct AthleteScore s;clrscr();if(fp=fopen(fname,r)=NULL)printf(Cant open file %s.n,fname);return 0;c=0;while(GetRecord(fp,&s)!=0)if(strcmp(s.code,key)=0)ShowAthleteRecord(&s);c+;break;fclose(fp);if(c=0)printf(The athlete %s is not in the file %s.n,key,fname);return 1;void InsertRecord()FILE *fp;char c,i,j,n;struct AthleteScore s;clrscr();printf(Please input the athletes score record files name: n);scanf(%s,filename);if(fp=fopen(filename,r)=NULL)printf(The file %s doesnt exit.ndo you want to creat it? (Y/N) ,filename);getchar();c=getchar();if(c=Y|c=y)fp=fopen(filename,w);printf(Please input the record number : );scanf(%d,&n);for(i=0;in;i+)printf(Input the athletes name: );scanf(%s,&);printf(Input the athletes code: );scanf(%s,&s.code);for(j=0;jJUDEGNUM;j+)printf(Input the %s mark: ,judgementj);scanf(%d,&s.scorej);PutRecord(fp,&s);fclose(fp);fclose(fp);return;int main()int i,j,n;char c;char bufBUFFSIZE;while(1)clrscr();printf(n- Input a command -n);printf(| i : insert record to a file. |n);printf(| n : search record by name. |n);printf(| c : search record by code. |n);printf(| l : list all the records. |n);printf(| s : sort the records by total. |n);printf(| q : quit. |n);printf(-n);printf(Please input a command:n);scanf(%c,&c);/* 输入选择命令 */switch(c)case i: InsertRecord();getch();break;case n: /* 按运动员的姓名寻找记录 */printf(Please input the athletes name:n);scanf(%s,buf);SearchbyName(filename,buf);getch();break;case c: /* 按运动员的号码寻找记录 */printf(Please input the athletes code:n);scanf(%s,buf);SearchbyCode(filename,buf);ge

温馨提示

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

评论

0/150

提交评论