运动会统计问题.docx

上传人:b****8 文档编号:28264823 上传时间:2023-07-09 格式:DOCX 页数:35 大小:106.70KB
下载 相关 举报
运动会统计问题.docx_第1页
第1页 / 共35页
运动会统计问题.docx_第2页
第2页 / 共35页
运动会统计问题.docx_第3页
第3页 / 共35页
运动会统计问题.docx_第4页
第4页 / 共35页
运动会统计问题.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

运动会统计问题.docx

《运动会统计问题.docx》由会员分享,可在线阅读,更多相关《运动会统计问题.docx(35页珍藏版)》请在冰豆网上搜索。

运动会统计问题.docx

运动会统计问题

目录

1前言1

2需求分析2

2.1问题描述2

2.2基本要求2

2.3测试数据2

3概要设计2

3.1算法设计思想2

3.2数据结构2

3.3系统流程图3

4具体代码实现4

5课程设计总结20

5.1程序运行结果20

5.2课程设计体会20

参考文献22

致谢22

 

前言

本学期开设的《C语言程序设计》课程已经告一段落。

在学习科目的第一天开始,老师就为我们阐述了它的重要性。

它对我们来说具有一定难度。

它是其他编程语言的一门基本学科。

尽管不好学,但是我们必须学好这门课程,这对于我们计算机专业的学生来说意义重大。

经过一个学期的理论知识的学习,对于数据结构相关的知识有了一定的了解。

这是一门纯属于设计的科目,它需要把理论变为上机调试和具体实践。

在课程介绍之后,老师为我们安排了这次为期两周的课程设计。

目的就是让我们自己在计算机上自己设计算法来实现相应的功能以及锻炼学生的动手能力和实践能力,最重要的是要把我们所学的数据结构的理论知识应用到实践中去。

这次课程设计的题目是:

运功会成绩统计,要求学生自己查阅相关资料,完成相应的任务,自己上机设计算法,调试程序,运行出结果,以此来加深理解线性表、查找表的逻辑结构、存储结构,掌握查找、排序登记本运算的实现,进一步理解和熟练掌握课本中所学的各种书本中所学的各种数据结构,学会把学到的知识用于解决实际问题,培养自己的动手能力。

 

2需求分析

2.1问题描述

参加运动会有n个系,系编号为1……n。

比赛分成m个男子项目,和w个女子项目。

项目编号为男子1……m,女子m+1……m+w。

不同的项目取前五名或前三名积分;取前五名的积分分别为:

7、5、3、2、1,前三名的积分分别为:

5、3、2;哪些取前五名或前三名由学生自己设定。

(m<=20,n<=20)

2.2基本要求

(1).可以输入各个项目的前三名或前五名的成绩;

(2).能统计各系总分;

(3).可以按系编号、系总分、男女团体总分排序输出;

(4).可以按系编号查询系某个项目的情况;可以按项目编号查询取得前三或前五名的系。

2.3测试数据

(1)输入:

1进入添加系的界面,根据提示,再输入相应的信息:

,成功添加了一个系。

再输入:

2进入运动项目添加界面,根据提示,再输入:

跳高;1;0;1;2;3。

之后输入0。

再次进入系统界面。

(2)输入:

3查看输出结果。

(3):

输入:

4查看输出结果。

(4):

输入:

5查看输出结果。

(5):

输入:

6查看输出结果。

(6):

输入:

7根据提示输入项目编号:

2。

查看输出结果。

(7):

输入:

8根据提示输入系编号:

3。

查看输出结果

3概要设计

3.1算法设计思想

本程序主要是使用链表来实现操作。

一个运动会包括运动项目和参加运动会的成员。

因此构造两个链表Department,Sport。

为了操作的方便,并且能够保存输入数据,所以通过文件操作来实现数据的写和读。

每次添加新的数据后都要输入0退出,数据才能保存。

对于总分的排序使用了冒泡排序。

为了使整个程序看起来更加友好,又添加了程序启动画面。

3.2数据结构

(1)系的定义:

typedefstructDepartment//系的结构

{charname[20];//系的名称

intnumber;//系的编号

intboy;//男子团体总分

intgirl;//女子团体总分

Department*next;}Department;

(2)运动项目定义:

typedefstructSport//运动项目结构

{charname[20];//运动项目名称

intisboy;//0为女项目,1为男项目

intis3;//0为取前五名,1为取前五名

intnumber;//项目编号

intfirst;//第一名系的编号

intsecond;//第二名系的编号

intthird;//第三名系的编号

intfourth;//第四名系的编号

intfifth;//第五名系的编号

Sport*next;}Sport;

3.3系统流程图

图3.1主模块流程图

4具体代码实现

#include

#include

#include

#include

#include

#include

#include

#include

typedefstructDepartment//系的结构

{

charname[20];//系的名称

intnumber;//系的编号

intboy;//男子团体总分

intgirl;//女子团体总分

Department*next;}Department;

typedefstructSport//运动项目结构

{

charname[20];//运动项目名称

intisboy;//0为女项目,1为男项目

intis3;//0为取前五名,1为取前五名

intnumber;//项目编号

intfirst;//第一名系的编号

intsecond;//第二名系的编号

intthird;//第三名系的编号

intfourth;//第四名系的编号

intfifth;//第五名系的编号

Sport*next;

}Sport;

intgetint(inta)//字符转换成数字

{

return(int)(a-'0');

}

Department*head1;

//-------启动画面函数----------

voidCover()

{system("color1b");

charline[]={"程序读取中 请耐心等待..."};

charbar[]={"...."};

inti,j,k=0,x=0,y=0;

for(i=0;i<=strlen(line)/2;)

{

system("cls");

for(j=0;j<9;j++)//改变行坐标

cout<

for(j=0;j<(75-strlen(line))/2;j++)//改变列坐标

cout<<"";

for(j=1;j<=i;j++)//进度显示器

cout<<"●";

for(x=strlen(line)/2;x>i;x--)

cout<<"○";

if(k==4)

i++;

cout<

for(j=0;j<(75-strlen(line))/2;j++)//行坐标定位

cout<<"";

cout<

cout<

for(j=0;j<(65-strlen(bar))/2;j++)

cout<<"";

cout<<(i+7)*5<<"%Loading";

cout.write(bar,k);

cout<

for(j=0;j<10;j++)

cout<

for(j=0;j<24;j++)

cout<<"";

cout<<"程序设计员:

10计本李艳红"<

for(j=0;j<24;j++)

cout<<"";

for(j=0;j<=18;j++)

cout<<"─";

cout<

for(j=0;j<10000000;j++);//延时效果

k++;

if(k>4)

k=0;

}

}

voiddepartment_add()//添加系

{

Department*p;

intmark=0;

p=newDepartment;

cout<<"请输入系的名称:

";

cin>>p->name;

charc;

while(mark!

=1)

{

cout<<"请输入系的编号:

";

cin>>c;

if(!

isdigit(c))//是否为数字

{

cout<<"数据非法"<

}

else

{

mark=1;

p->number=c;

}

}

p->boy=0;

p->girl=0;

p->next=head1->next;

head1->next=p;

cout<<"成功添加了一个系"<

}

intdepartment_getlong(Department*first)//得到链表长度

{

inti=0;

while(first->next!

=NULL)

{

i++;

first=first->next;

}

returni;

}

voiddepartment_write()//将系数据写入文本

{

Department*p;

p=head1;

p=p->next;

ofstreamoutfile("Department.txt",ios:

:

out);

outfile<

while(p!

=NULL)

{

outfile<name<<""<number<<""<boy<<""<girl<<"";

p=p->next;

}

outfile.close();

cout<<"WriteSuccess!

"<

}

voiddepartment_read()//从文本读入系数据

{

inti;

ifstreaminfile("Department.txt",ios:

:

in);

infile>>i;

while(i>0)

{

Department*p;

p=newDepartment;

infile>>p->name>>p->number>>p->boy>>p->girl;

p->next=head1->next;

head1->next=p;

i--;

}

cout<<"DepartmentDataReadSuccess!

"<

}

voiddepartment_output(Department*p)//输出系

{

cout<<" 系名    编号 男团总分 女团总分 总分\t\n";

while(p)

{

cout<name<<"\t"<number)<<"\t"<boy<<"\t"<girl<<"\t"<<(p->girl+p->boy)<

p=p->next;

}

}

intdepartment_isexist(inta)//检验系是否存在

{

intb=0;

Department*p;

p=head1;

p=p->next;

while(p)

{

if(p->number==a)

{

return1;

}

p=p->next;

}

return0;

}

voiddepartment_show(inta)//输出所有系

{

Department*p;

p=head1;

p=p->next;

while(p)

{

if(p->number==a)

{

cout<name<<" ";

return;

}

p=p->next;

}

cout<<" 无  ";

}

voiddepartment_search(inta)//按编号搜索系

{

Department*p;

p=head1;

p=p->next;

while(p)

{

if(p->number==a)

{

cout<<"系名:

"<name<<" "<<"男子团体总分:

"<boy<<" "<<"女子团体总分:

"<girl<<" "<<"总分:

"<<(p->boy+p->girl)<<" ";

return;

}

p=p->next;

}

cout<<"无此编号";

}

voiddepartment_addmark(inta,intb,intc)//a为分数,b为系编号,c=1表示男,c=0表示女

{

Department*p;

p=head1;

p=p->next;

while(p)

{

if(p->number==b)

{

if(c=='1')

{

p->boy=p->boy+a;

}

else

{

p->girl=p->girl+a;

}

}

p=p->next;

}

}

voiddepartment_order(Department*temp,inttype)//type=0按总分,type=1按男总分,type=2按女总分,

{

Department*p,*q,*small,*temp1;

temp1=newDepartment;

temp1->next=NULL;

p=temp;

while(p)

{

small=p;

q=p->next;

while(q)

{

switch(type)

{

case0:

if((q->boy+q->girl)<(small->girl+small->boy))

{

small=q;

}

break;

case1:

if(q->boyboy)

{

small=q;

}

break;

case2:

if(q->girlgirl)

{

small=q;

}

break;

default:

cout<<"error"<

}

if(small!

=p)

{

temp1->boy=p->boy;

p->boy=small->boy;

small->boy=temp1->boy;

temp1->girl=p->girl;

p->girl=small->girl;

small->girl=temp1->girl;

strcpy(temp1->name,p->name);

strcpy(p->name,small->name);

strcpy(small->name,temp1->name);

temp1->number=p->number;

p->number=small->number;

small->number=temp1->number;//将系的名字互换

}

q=q->next;

}

p=p->next;

}

}

Sport*head2;

intsport_isexist(inta)//检查运动项目(编号)是否已经存在

{

intb=0;

Sport*p;

p=head2;

p=p->next;

while(p)

{

if(p->number==a)

{

return1;

}

p=p->next;

}

return0;

}

voidsport_add()//添加项目

{

Sport*p;

intmark=0;

p=newSport;

cout<<"请输入项目名称:

";

cin>>p->name;

charc;

while(mark!

=1)

{

cout<<"请输入项目编号:

";

cin>>c;

if(!

isdigit(c))

{

cout<<"数据非法"<

}

else

{

if(sport_isexist(c))

{

cout<<"该编号已存在"<

}

else

{

mark=1;

p->number=c;

}

}

}

mark=0;

while(mark!

=1)

{

cout<<"请输入项目类型(0为女子项目,1为男子项目):

";

cin>>c;

p->isboy=(int)(c-'0');//字符转换成数字

if(!

isdigit(c))

{

cout<<"数据非法"<

}

elseif(p->isboy<0||p->isboy>1)

{

cout<<"数据非法"<

}

else

{

mark=1;

p->isboy=c;

}

}

mark=0;

while(mark!

=1)

{

cout<<"请输入项目名次情况(0为取前3名,1为取前5名):

";

cin>>c;

p->is3=(int)(c-'0');

if(!

isdigit(c))

{

cout<<"数据非法"<

}

elseif(p->is3<0||p->is3>1)

{

cout<<"数据非法"<

}

else

{

mark=1;

p->is3=c;

}

}

mark=0;

while(mark!

=1)

{

cout<<"请输入第一名的系的编号:

";

cin>>c;

if(!

isdigit(c))

{

cout<<"数据非法"<

}

else

{

if(!

department_isexist(c))

{

cout<<"该系不存在,请先添加";

}

else

{

mark=1;

p->first=c;

if(p->is3=='0')

department_addmark(5,c,p->isboy);

else

department_addmark(7,c,p->isboy);

}

}

}

mark=0;

while(mark!

=1)

{

cout<<"请输入第二名的系的编号:

";

cin>>c;

if(!

isdigit(c))

{

cout<<"数据非法"<

}

else

{

if(!

department_isexist(c))

{

cout<<"该系不存在,请先添加";

}

else

{

mark=1;

p->second=c;

if(p->is3=='0')

department_addmark(3,c,p->isboy);

else

department_addmark(5,c,p->isboy);

}

}

}

mark=0;

while(mark!

=1)

{

cout<<"请输入第三名的系的编号:

";

cin>>c;

if(!

isdigit(c))

{

cout<<"数据非法"<

}

else

{

if(!

department_isexist(c))

{

cout<<"该系不存在,请先添加";

}

else

{

mark=1;

p->third=c;

if(p->is3=='0')

department_addmark(2,c,p->isboy);

else

department_addmark(3,c,p->isboy);

}

}

}

mark=0;

if(p->is3=='1')

{

while(mark!

=1)

{

cout<<"请输入第四名的系的编号:

";

cin>>c;

if(!

isdigit(c))

{

cout<<"数据非法"<

}

else

{

if(!

department_isexist(c))

{

cout<<"该系不存在,请先添加";

}

else

{

mark=1;

p->fourth=c;

department_addmark(2,c,p->isboy);

}

}

}

mark=0;

while(mark!

=1)

{

cout<<"请输入第五名的系的编号:

";

cin>>c;

if(!

isdigit(c))

{

cout<<"数据非法"<

}

else

{

if(!

department_isexist(c))

{

cout<<"该系不存在,请先添加"<

}

else

{

mark=1;

p->fifth=c;

department_addmark(1,c,p->isboy);

}

}

}

}

else

{

p->fourth='0';

p->fifth='0';

}

p->next=head2->next;

head2->next=p;

cout<<"成功添加了一个运动项目"<

}

intsport_getlong(Sport*first)//得到项目链表长度

{

inti=0;

while(first->next!

=NULL)

{

i++;

first=first->next;

}

returni;

}

voidsport_write()//将项目数据写入文本文档

{

Sport*p;

p=head2;

p=p->next;

ofstreamoutfile("Sport.txt",ios:

:

out);

outfile<

while(p!

=NULL)

{

outfile<name<<""<number<<""<isboy<<""<is3<<""<first<<""<second<<""<third<<""<fourth<<""<fifth<<"";

p=p->next;

}

outfile.close();

cout<<"WriteSuccess!

"<

}

voidsport_read()//从文本读取项目数据

{

inti;

ifstreaminfile("Sport.txt",ios:

:

in);

infile>>i;

while(i>0)

{

Sport*p;

p=newSport;

infile>>p->name>>p->nu

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

当前位置:首页 > 人文社科 > 视频讲堂

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

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