c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码

上传人:E**** 文档编号:102541385 上传时间:2019-10-03 格式:DOCX 页数:7 大小:271.96KB
返回 下载 相关 举报
c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码_第1页
第1页 / 共7页
c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码_第2页
第2页 / 共7页
c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码_第3页
第3页 / 共7页
c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码_第4页
第4页 / 共7页
c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码》由会员分享,可在线阅读,更多相关《c语言程序设计第2版) 教学课件 作者 梅创社代码 竞技比赛打分系统源代码(7页珍藏版)》请在金锄头文库上搜索。

1、#include #include #include #include#defineJUDEGNUM3 /* 裁判数 */#define NAMELEN20/* 姓名最大字符数 */#define CODELEN10/* 号码最大字符数 */#define FNAMELEN80/* 文件名最大字符数 */#define BUFFSIZE128/* 缓冲区最大字符数 */char judgementJUDEGNUMNAMELEN+1 = judgementA,judgementB,judgementC;struct AthleteScorecharnameNAMELEN+1;/* 姓名 */ch

2、ar codeCODELEN+1;/* 学号 */int scoreJUDEGNUM;/* 各裁判给的成绩 */int total; /* 总成级 */;struct LinkNodecharnameNAMELEN+1;/* 姓名 */char codeCODELEN+1;/* 号码 */int scoreJUDEGNUM;/* 各裁判给的成绩 */int total; /* 总成级 */structLinkNode *next;*head;/* 链表首指针 */int totalJUDEGNUM;/* 各裁判给的总成绩 */FILE *filepoint;/* 文件指针 */char fil

3、enameFNAMELEN;/* 文件名 */* 从指定文件读入一个记录 */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;itota

4、l+=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(

5、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;system(cls);if(fp=fopen(fname,r)=NULL)printf(Cant open file %s.n,fname);return ;while(GetRecord(fp,&s)!=0)ShowAthleteRecord(&s);fclose(

6、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

7、*)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)system(cls);while(h!=NULL)ShowAthleteRecord(struct AthleteScore *)h);printf(n);while(ge

8、tchar()!=n);h=h-next;return;/* 按运动员姓名查找记录 */int SearchbyName(char *fname, char *key)FILE *fp;int c;struct AthleteScore s;system(cls);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.name,key)=0)ShowAthleteRecord(&s);c+;fclose(fp);if(c=0)p

9、rintf(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;system(cls);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)ShowAth

10、leteRecord(&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;system(cls);printf(Please input the athletes score record files name: n);scanf(%s,filename);if(fp=fopen(filename,r)=NULL)printf(T

11、he 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,&s.name);printf(Input the athletes code: );scanf(%s,&s.code);for(j=0

12、;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)system(cls);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.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号