体育打分系统.docx

上传人:b****0 文档编号:12474882 上传时间:2023-04-19 格式:DOCX 页数:19 大小:259KB
下载 相关 举报
体育打分系统.docx_第1页
第1页 / 共19页
体育打分系统.docx_第2页
第2页 / 共19页
体育打分系统.docx_第3页
第3页 / 共19页
体育打分系统.docx_第4页
第4页 / 共19页
体育打分系统.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

体育打分系统.docx

《体育打分系统.docx》由会员分享,可在线阅读,更多相关《体育打分系统.docx(19页珍藏版)》请在冰豆网上搜索。

体育打分系统.docx

体育打分系统

体育打分系统

一、课题内容和要求

(1)系统可针对不同的竞技项目;

(2)可查询各裁判员打分的明细;

(3)能给出运动员的排名、打分情况等;

(4)运动员的基本信息保存于数据库中;

(5)裁判可直接选取某选手,对其打分;

(6)可查询打分规则;

(7)用VC++实现系统,要求界面简洁美观。

2、需求分析

2.1各函数的功能和实现

1.插入记录.:

输入田径记录分数文件,可用函数InsertRecord()来实现此作

2.按运动员的姓名寻找记录:

输入田径运动员的名字,可用函数SearchbyName(filename,buf)来实现此操作

 

3.按运动员的号码寻找记录输入田:

径运动员号码,可用SearchbyCode(filename,buf)来实现

4.列出所有运动员记录:

分数列表,可用Listathleteinfo(filename)来实现

 

5.按总分从高到低排列显示:

计算总分数,可用OutputLinklist(head)来实现

6.退出:

可用一个函数exit()来实现,首先将信息保存到文件中,释放动态创建的内存空间,再退出此程序。

3、概要设计

 

从指定文件读入一个记录

对指定文件写入一个记录

 

按条件查找运动员记录

4、详细设计

#include

#include

#include

#include

#defineJUDEGNUM4/*裁判数*/

#defineNAMELEN20/*姓名最大字符数*/

#defineCODELEN10/*号码最大字符数*/

#defineFNAMELEN80/*文件名最大字符数*/

#defineBUFFSIZE128/*缓冲区最大字符数*/

charjudgement[JUDEGNUM][NAMELEN+1]={"judgementA","judgementB","judgementC","judgementD"};

structAthleteScore

{

charname[NAMELEN+1];/*姓名*/

charcode[CODELEN+1];/*学号*/

intscore[JUDEGNUM];/*各裁判给的成绩*/

inttotal;/*总成级*/

intaverage;

};

structLinkNode

{

charname[NAMELEN+1];/*姓名*/

charcode[CODELEN+1];/*号码*/

intscore[JUDEGNUM];/*各裁判给的成绩*/

inttotal;/*总成级*/

intaverage;

structLinkNode*next;

}*head;/*链表首指针*/

inttotal[JUDEGNUM];/*各裁判给的总成绩*/

FILE*filepoint;/*文件指针*/

charfilename[FNAMELEN];/*文件名*/

/*从指定文件读入一个记录*/

intGetRecord(FILE*fpt,structAthleteScore*sturecord)

{

charbuf[BUFFSIZE];

inti,j,temp,max=0,min=10;

intaverage;

if(fscanf(fpt,"%s",buf)!

=1)

return0;/*文件结束*/

strncpy(sturecord->name,buf,NAMELEN);

fscanf(fpt,"%s",buf);

strncpy(sturecord->code,buf,CODELEN);

for(i=0;i

fscanf(fpt,"%d",&sturecord->score[i]);

while(sturecord->score[i]>0||sturecord->score[i]>10)

{printf("请输入0到10之间的数字\n");}

for(i=0;i<4;i++)

for(j=i+1;j<4;j++)/*注意循环的上下限*/

if(sturecord->score[i]>sturecord->score[j])

{temp=sturecord->score[i];sturecord->score[i]=sturecord->score[j];sturecord->score[j]=temp;

}

for(sturecord->total=0,i=0;i

sturecord->total+=sturecord->score[i];

for(i=0;i

{if(sturecord->score[i]>max)

{max=sturecord->score[i];

}

}

for(i=0;i

{if(sturecord->score[i]

{min=sturecord->score[i];

}

}

sturecord->average=(sturecord->total-max-min)/2;

return1;

}

/*对指定文件写入一个记录*/

voidPutRecord(FILE*fpt,structAthleteScore*sturecord)

{

inti;

fprintf(fpt,"%s\n",sturecord->name);

fprintf(fpt,"%s\n",sturecord->code);

for(i=0;i

fprintf(fpt,"%d\n",sturecord->score[i]);

return;

}

/*显示运动员记录*/

voidShowAthleteRecord(structAthleteScore*rpt)

{

inti;

printf("\nName:

%s\n",rpt->name);

printf("Code:

%s\n",rpt->code);

printf("score:

\n");

for(i=0;i

printf("%-15s:

%4d\n",judgement[i],rpt->score[i]);

printf("Total:

%4d\n",rpt->total);

printf("average:

%4d\n",rpt->average);

}

/*列表显示运动员成绩*/

voidListathleteinfo(char*fname)

{

FILE*fp;

structAthleteScores;

system("cls");

if((fp=fopen(fname,"r"))==NULL)

{

printf("Can'topenfile%s.\n",fname);

return;

}

while(GetRecord(fp,&s)!

=0)

{

ShowAthleteRecord(&s);

}

fclose(fp);

return;

}

/*构造链表*/

structLinkNode*CreatLinklist(char*fname)

{

FILE*fp;

structAthleteScores;

structLinkNode*p,*u,*v,*h;

inti;

if((fp=fopen(fname,"r"))==NULL)

{

printf("Can'topenfile%s.\n",fname);

returnNULL;

}

h=NULL;

p=(structLinkNode*)malloc(sizeof(structLinkNode));

while(GetRecord(fp,(structAthleteScore*)p)!

=0)

{

v=h;

while(v&&p->total<=v->total)

{

u=v;

v=v->next;

}

if(v==h)

h=p;

else

u->next=p;

p->next=v;

p=(structLinkNode*)malloc(sizeof(structLinkNode));

}

free(p);

fclose(fp);

returnh;

}

/*顺序显示链表各表元*/

voidOutputLinklist(structLinkNode*h)

{

system("cls");

while(h!

=NULL)

{

ShowAthleteRecord((structAthleteScore*)h);

printf("\n");

while(getchar()!

='\n');

h=h->next;

}

return;

}

/*按运动员姓名查找记录*/

intSearchbyName(char*fname,char*key)

{

FILE*fp;

intc;

structAthleteScores;

system("cls");

if((fp=fopen(fname,"r"))==NULL)

{

printf("Can'topenfile%s.\n",fname);

return0;

}

c=0;

while(GetRecord(fp,&s)!

=0)

{

if(strcmp(s.name,key)==0)

{

ShowAthleteRecord(&s);

c++;

}

}

fclose(fp);

if(c==0)

printf("Theathlete%sisnotinthefile%s.\n",key,fname);

return1;

}

/*按运动员号码查找记录*/

intSearchbyCode(char*fname,char*key)

{

FILE*fp;

intc;

structAthleteScores;

system("cls");

if((fp=fopen(fname,"r"))==NULL)

{

printf("Can'topenfile%s.\n",fname);

return0;

}

c=0;

while(GetRecord(fp,&s)!

=0)

{

if(strcmp(s.code,key)==0)

{

ShowAthleteRecord(&s);

c++;

break;

}

}

fclose(fp);

if(c==0)

printf("Theathlete%sisnotinthefile%s.\n",key,fname);

return1;

}

voidInsertRecord()

{

FILE*fp;

charc,i,j,n;

structAthleteScores;

system("cls");

printf("Pleaseinputtheathletesscorerecordfile'sname:

\n");

scanf("%s",filename);

if((fp=fopen(filename,"r"))==NULL)

{

printf("Thefile%sdoesn'texit.\ndoyouwanttocreatit?

(Y/N)",filename);

getchar();

c=getchar();

if(c=='Y'||c=='y')

{

fp=fopen(filename,"w");

printf("Pleaseinputtherecordnumber:

");

scanf("%d",&n);

for(i=0;i

{

printf("Inputtheathlete'sname:

");

scanf("%s",&s.name);

printf("Inputtheathlete'scode:

");

scanf("%s",&s.code);

for(j=0;j

{

printf("Inputthe%smark:

",judgement[j]);

scanf("%d",&s.score[j]);

}

PutRecord(fp,&s);

}

fclose(fp);

}

}

fclose(fp);

return;

}

intmain()

{

charc;

charbuf[BUFFSIZE];

while

(1)

{

system("cls");

printf("\n--------------输入命令-----------\n");

printf("|1:

插入记录.\n");

printf("|2:

按运动员的姓名寻找记录.\n");

printf("|3:

按运动员的号码寻找记录.\n");

printf("|4:

列出所有的记录.\n");

printf("|5:

按总分从高到低排列.\n");

printf("|6:

退出.\n");

printf("------------------------------------------\n");

printf("请输入命令:

\n");

scanf("%c",&c);/*输入选择命令*/

switch(c)

{case'1':

InsertRecord();

getch();

break;

case'2':

/*按运动员的姓名寻找记录*/

printf("Pleaseinputtheathlete'sname:

\n");

scanf("%s",buf);

SearchbyName(filename,buf);

getch();

break;

case'3':

/*按运动员的号码寻找记录*/

printf("Pleaseinputtheathlete'scode:

\n");

scanf("%s",buf);

SearchbyCode(filename,buf);

getch();

break;

case'4':

/*列出所有运动员记录*/

Listathleteinfo(filename);

getch();

break;

case'5':

/*按总分从高到低排列显示*/

if((head=CreatLinklist(filename))!

=NULL)

OutputLinklist(head);

getch();

break;

case6:

return1;

default:

break;

}

}

return1;

}

 

5、测试数据及其结果分析

 

1、首页界面

 

2、输入命令一,插入运动员记录

3、输入命令二,按运动员姓名查找

 

3、输入命令三按运动员号码查找及结果

 

4、输入命令四,列出所有运动员记录

5、输入命令5,对所有的运动员的成绩排序

 

6、调试过程中的问题

1、开始时用的清屏的,代码是clrscr()兼容性不好,XX搜索后改变了函数system("cls");第一个问题就圆满解决了。

2、对于打分的细则问题,参考网上的代码过于简单只计算了总分,于是自己想了改成去掉一个最高分一个最低分,再去平均分,介于平均分是float型的,总分是int型的,考虑在计算过程电脑是否自己会强制转换,不行就手动转换float(a)/n。

3、对于对每个裁判打分进行排序的问题,只实现了成绩的排队,和裁判本人对不上了。

7、参考文献和查阅的资料(给出文献名或者网络链接)

1.朱立华,王立柱.《C语言程序设计》.人民邮电出版社

2.

8、程序设计总结

这是大学四年里的最后的一次的课程设计,不能说自己新学到了什么多的东西,只能说是对自己之前学的C语言以及数据结构的复习吧,由于这些事大一和大二时学的很长时间没碰了,几乎都已经很陌生了,这次在不断的查询和解决办法的过程,对遗忘的很多知识点算是一个回顾。

对于一些基本算法和文件、链表的运用更是加深了印象。

这次实验最深刻的体会还是时间的合理分配及运用,由于目前大四自己要实习而且英语方面还报了考试,这些综合在一起就需要自己高效率的利用分配自己是时间。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1