




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 租赁商铺押金合同范本(含租赁期限及租金调整)
- 离婚协议书:离婚赔偿金及生活费用保障协议
- 盛芷特殊状况下子女抚养权及赡养费约定书
- 道路安全员考试及答案1
- 智能网联传感器及控制器生产线项目建设工程方案
- 2025年新能源企业客户关系管理优化方案报告
- 普通话知识竞赛题及答案
- 第14课 成长变化(二)教学设计-六年级下册小学美术同步备课资源包(苏少版)
- DB65T 4395-2021 乡村绿化美化技术规范
- 空乘专业考试题及答案
- 小儿抽搐课件
- 锻压机床行业分析报告
- 化工生产工艺培训课件
- 2025一级造价工程师《建设工程造价案例分析》(土木建筑工程、安装工程)考前必背笔记
- 交投面试题目及答案
- 2023年一级建造师《建设工程项目管理》真题及答案解析
- 2025年企业文化企业建设知识竞赛-锦江之星服务知识竞赛历年参考题库含答案解析(5套)
- 2025年全国青少年禁毒知识竞赛试题(附答案)
- 2025年法律基础知识考题库和答案
- 精益生产管理课件
- 集合运算说课课件
评论
0/150
提交评论