运动会分数统计程序 C++

某学校开运动会,共有m个班参加,比赛设有n个男子项目和L个女子项目。假设项目编号为1,…,n,n+1,…,n+L,并且假定各比赛项目取前5名,得分顺序为7、5、3、2、1... 某学校开运动会,共有m个班参加,比赛设有n个男子项目和L个女子项目。假设项目编号为1,… ,n,n+1, … , n+L, 并且假定各比赛项目取前5名,得分顺序为7、5、3、2、1。请编写出一个程序以实现:
(1)成绩数据录入。每个项目结束时,将项目编号及名称、比赛时间(可只记载开始时间)输入,并按名次输入运动员的姓名、班级、成绩。能添加、删除、修改。
(2)产生指定班级在指定时间内的总分;
(3)产生指定运动员在指定时间内的总分;
(4)产生指定班级在指定项目的总得分;
(5)汇总各班级在指定时间内的总分,且排序输出;
(6)产生各班成绩单(包括各班所取得的各项成绩的项目号、名次、运动员姓名和得分)。
(7)程序运行过程中可将数据存从文件读入内存;
(8)程序运行过程中可将数据存文件;
提示:假设m≤20,n≤15,L≤10;
班级名称、比赛项目名称(如男子100米、女子5kg铅球等)都用字符串表示;
各比赛项目参赛单位为个人,即可以不考虑接力赛等多人作为参赛单位的项目;
时间可以用结构体类型数据表示;
本题实际就是要编写程序管理如下结构的表格信息,并且对表格数据按要求统计、汇总等。(建议用链表不要用数组)
项目编号 项目名称 比赛时间 姓名 班级 成绩

本选题程序应包含主控模块和其它若干个功能模块,主控模块要显示主界面和主菜单。
来来,先追加一个零头。30分。等有满意答案,补充到200.
还有没有满意答案啊。追加到200邀请高手啦~~~~~
展开
 我来答
sa495566524
2011-09-03 · TA获得超过379个赞
知道小有建树答主
回答量:82
采纳率:0%
帮助的人:150万
展开全部

楼主你好,你看看下面这个代码吧   和你的比较相似 :

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

class School{

private:

int id;//学校编号

string name;//学校名称

int total;//学校总分

int male;//男子总分

int female;//女子总分

public:

School(){//初始化

id=0;

male=0;

female=0;

total=0;

}

void setName(string s){

name=s;

}

string getName(){

return name;

}

void setId(int i){

id=i;

}

int getId(){

return id;

}

void setTotal(int a){

total=a;

}

int getTotal(){

return total;

}

void setMale(int a){

male=a;

}

void setFemale(int a){

female=a;

}

int getMale(){

return male;

}

int getFemale(){

return female;

}

};

class Item{

private:

School sc[20];

string name;

public:

School getSchool(int i){

return sc[i];

}

School* getSchools(){

return sc;

}

void setSchool(School sch,int i){

sc[i]=sch;

}

void setName(string s){

name=s;

}

string getName(){

return name;

}

};

class Count{

private:

School sc[20];

Item item[20];

int integral[5];

int n;

public:

Count(){

n=0;

integral[0]=7;

integral[1]=5;

integral[2]=3;

integral[3]=2;

integral[4]=1;

}

void input();//输入

void print(int);//打印

void statisticsForTotal();//按总分排序

void statisticsForId();//按编号排序

void statisticsForMale();//按男子总分排序

void statisticsForFemale();//按女子总分排序

void schoolInfo();//显示学校信息

void itemInfo();//显示项目信息

void menu();//显示菜单

void sort(School*,string,int);//排序操作

};

void Count::input(){

int i,j,num,m,f,id;

School *sch;

Item *it;

string s;

cout<<"输入学校数目:";

cin>>n;

for(i=0;i<n;i++){

sch=new School;

cout<<"请输入第"<<i+1<<"学校的名称:";

cin>>s;

sch->setName(s);

sch->setId(i+1);

sc[i]=*sch;

}

cout<<"输入男子和女子项目的数目:";

cin>>m;

cin>>f;

while(m>20||m<1||f>20||f<1){

cout<<"输入数据有误,请重新输入:"<<endl;

cin>>m;

cin>>f;

}

for(i=0;i<m+f;i++){

cout<<"输入第"<<i+1<<"个项目的名称:";

cin>>s;

it=new Item;

it->setName(s);

item[i]=*it;

cout<<"输入第"<<i+1<<"个项目的前5名学校的编号:"<<endl;

for(j=0;j<5;j++){

cin>>id;

if(i<m)

sc[id-1].setMale(sc[id-1].getMale()+integral[j]);

else if(i<m+f)

sc[id-1].setFemale(sc[id-1].getFemale()+integral[j]);

sc[id-1].setTotal(sc[id-1].getTotal()+integral[j]);

item[i].setSchool(sc[id-1],j);

}

}

}

void Count::print(int i){

cout<<"   "<<sc[i].getId()<<setw(10)<<sc[i].getName()<<setw(8)<<sc[i].getTotal()

<<setw(9)<<sc[i].getMale()<<setw(10)<<sc[i].getFemale()<<endl;

}

void Count::sort(School* sch,string mode,int num){//排序函数

int i,j,exchange;

School t;

if(mode=="total"){

exchange=0;

for(i=0;i<num-1;i++){

for(j=num-2;j>=0;j--)

if(sch[j+1].getTotal()>sch[j].getTotal()){

exchange=1;

t=sc[j+1];

sch[j+1]=sch[j];

sch[j]=t;

}

if(!exchange)

return;

}

return;

}

if(mode=="id"){

for(i=0;i<num;i++){

for(j=i+1;j<num;j++)

if(sch[i].getId()>sch[j].getId()){

t=sch[i];

sch[i]=sch[j];

sch[j]=t;

}

}

return;

}

if(mode=="male"){

exchange=0;

for(i=0;i<num-1;i++){

for(j=num-2;j>=0;j--)

if(sch[j+1].getMale()>sch[j].getMale()){

exchange=1;

t=sc[j+1];

sch[j+1]=sch[j];

sch[j]=t;

}

if(!exchange)

return;

}

return;

}

if(mode=="female"){

exchange=0;

for(i=0;i<num-1;i++){

for(j=num-2;j>=0;j--)

if(sch[j+1].getFemale()>sch[j].getFemale()){

exchange=1;

t=sc[j+1];

sch[j+1]=sch[j];

sch[j]=t;

}

if(!exchange)

return;

}

return;

}

}

void Count::statisticsForTotal(){

int i;

sort(sc,"total",n);

cout<<"按总分排序:"<<endl;

cout<<"学校编号  学校名称  总分 男子总分 女子总分"<<endl;

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

print(i);

}

void Count::statisticsForId(){

int i;

sort(sc,"id",n);

cout<<"按编号排序为:"<<endl;

cout<<"学校编号 学校名称 总分 男子总分 女子总分"<<endl;

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

print(i);

}

void Count::statisticsForMale(){

int i;

sort(sc,"male",n);

cout<<"按男子项目积分排序:"<<endl;

cout<<"学校编号 学校名称 总分 男子总分 女子总分"<<endl;

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

print(i);

}

void Count::statisticsForFemale(){

int i;

sort(sc,"female",n);

cout<<"按女子项目积分排序:"<<endl;

cout<<"学校编号 学校名称 总分 男子总分 女子总分"<<endl;

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

print(i);

}

void Count::schoolInfo(){ //查询学校的情况

int i,s;

cout<<"输入需要查询的学校编号:";

while(1){ 

cin>>s;

if(s<1||s>n){

cout<<"输入数据有误,请重新输入:";

continue;

}

break;

printf("该学校的信息信息:\n");

printf("编号 学校名称 总分 男子总分 女子总分\n");

for(i=0;i<n;i++){

if(sc[i].getId()==s){ 

print(i);

break;

}

}

cout<<endl;

}

void Count::itemInfo(){ //查询项目的情况

int i,s;

cout<<"输入需要查询的项目的编号:";

while(1){ 

cin>>s;

if(s<1||s>n){

cout<<"输入数据有误,请重新输入:";

continue;

}

break;

cout<<item[s-1].getName()<<"前5名学校编号及名称为:"<<endl;

sort(item[s-1].getSchools(),"total",5);

cout<<"名次 学校编号 学校名称"<<endl;

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

cout<<" "<<i+1<<"\t"<<item[s-1].getSchool(i).getId()

<<"\t"<<item[s-1].getSchool(i).getName()<<endl;

}

void Count::menu(){ //程序菜单

int i,flag=1;

while(flag){ 

cout<<"选择您需要的操作:"<<endl;

cout<<"1.按学校编号排序输出"<<endl;

cout<<"2.按学校总分排序输出"<<endl;

cout<<"3.按学校男总分排序输出"<<endl;

cout<<"4.按学校女总分排序输出"<<endl;

cout<<"5.查询某个学校成绩"<<endl;

cout<<"6.查询某个项目成绩"<<endl;

cout<<"7.结束"<<endl;

cin>>i;

while(i<1||i>7){

cout<<"你的输入有误,请重新输入:";

cin>>i;

}

switch(i){

case 1:

statisticsForId();

break;

case 2:

statisticsForTotal();

break;

case 3:

statisticsForMale();

break;

case 4:

statisticsForFemale();

break;

case 5:

schoolInfo();

break;

case 6:

itemInfo();

break;

case 7:

flag=0;

break;

}

}

}

void main(){

Count c;

c.input();

c.menu();

}

希望能够帮助到你!

参考资料: http://zhidao.baidu.com/question/314574733.html

Lvsky长风大侠
2011-09-24
知道答主
回答量:3
采纳率:0%
帮助的人:6.3万
展开全部
功能还算齐全,觉得可以加分啊!

#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
using namespace std;
int n; //n个学校
int m; //m个男子项目
int w; //w个女子项目
struct pro //表示项目的结构体
{
string name; //项目名称
int snum[6]; //前5名学校的编号
}p[21];
struct school //表示学校的结构体
{
int num;
string name; //学校名称
int score; //学校总分
int male; //男子总分
int female; //女子总分
}sch[21];
int integral[5]=;//前五名得分
void input()
{
int i,j,y,x;
printf("输入学校数目:");
y=0;
while(1)
{
scanf("%d",&n);
if(n>=1&&n<=20)y=1;
if(y)break;
else printf("输入数据有误,请重新输入:");
}
for(i=1;i<=n;i++)
{
printf("输入第%d个学校的名称:",i);
cin>>sch[i].name;
sch[i].score=0;
sch[i].female=0;
sch[i].male=0;
sch[i].num=i;
}
printf("输入男子项目数和女子项目数:");
y=0;
while(1)
{
scanf("%d%d",&m,&w);
if(m<=20&&m>=1&&w<=20&&w>=1)y=1;
if(y)break;
else printf("输入数据有误,请重新输入:");
}
for(i=1;i<=m+w;i++)
{
printf("输入第%d个项目的名称:\n",i);
cin>>p[i].name;
printf("输入第%d个项目的前5名的学校编号:\n",i);
for(j=1;j<=5;j++)
{
y=0;
while(1)
{
scanf("%d",&x);
if(x>=1&&x<=20)y=1;
if(y)break;
else printf("输入数据有误,请重新输入:");
}
p[i].snum[j]=x;
sch[x].score+=integral[j-1];
if(i<=m)sch[x].male+=integral[j-1];
else sch[x].female+=integral[j-1];
}
}
}
void print(int i)
{
cout<<sch[i].num<<setw(10)<<sch[i].name<<setw(8)<<sch[i].score<<setw(9)
<<sch[i].male<<setw(10)<<sch[i].female<<endl;
}
void bianhao() //按编号排序
{
int i,j;
school t;
for(i=1;i<n;i++)
{
for(j=i;j<=n;j++)
if(sch[i].num>sch[j].num)

}
printf("\n按编号排列:\n");
printf("编号 学校名称 总分 男子总分 女子总分\n");
for(i=1;i<=n;i++)
print(i);
}
void zongfen() //按学校总分排序
{
int i,j;
school t;
for(i=1;i<n;i++)
{
for(j=i;j<=n;j++)
if(sch[i].score<sch[j].score)

}
printf("\n按学校总分排列:\n");
printf("编号 学校名称 总分 男子总分 女子总分\n");
for(i=1;i<=n;i++)
print(i);
ofstream fout;
fout.open("运动会分数统计.txt");
fout<<"编号 学校名称 总分 男子总分 女子总分"<<endl;
for(i=1;i<=n;i++)
{fout<<sch[i].num<<setw(13)<<sch[i].name<<setw(8)<<sch[i].score<<setw(9)
<<sch[i].male<<setw(10)<<sch[i].female<<endl; }
fout.close();
}
void malezf() //按学校男总分排序
{
int i,j;
school t;
for(i=1;i<n;i++)
{
for(j=i;j<=n;j++)
if(sch[i].male<sch[j].male)

}
printf("\n按学校男子总分排列:\n");
printf("编号 学校名称 总分 男子总分 女子总分\n");
for(i=1;i<=n;i++)
print(i);
}
void femalezf() //按学校女总分排序
{
int i,j;
school t;
for(i=1;i<n;i++)
{
for(j=i;j<=n;j++)
if(sch[i].female<sch[j].female)

}
printf("\n按学校女子总分排列:\n");
printf("编号 学校名称 总分 男子总分 女子总分\n");
for(i=1;i<=n;i++)
print(i);
cout<<endl;
}
void cxsch() //查询学校信息
{
int i,y,s;
printf("输入需要查询的学校编号:");
y=0;
while(1)
{
scanf("%d",&s);
if(s>=1&&s<=n)y=1;
if(y)break;
else printf("输入数据有误,请重新输入:");
}
printf("该学校相关信息:\n");
printf("编号 学校名称 总分 男子总分 女子总分\n");
for(i=1;i<=n;i++)
{
if(sch[i].num==s)
{
print(i);
break;
}
}
cout<<endl;
}
void cxxm() //查询项目信息
{
int i,y,s;
printf("输入需要查询的项目编号:");
y=0;
while(1)
{
scanf("%d",&s);
if(s>=1&&s<=n)y=1;
if(y)break;
else printf("输入数据有误,请重新输入:");
}
cout<<p[s].name<<"前5名学校编号及名称为:"<<endl;
printf("名次 编号 学校名称\n");
for(i=1;i<=5;i++)
cout<<" "<<i<<" "<<p[s].snum[i]<<setw(12)<<sch[ p[s].snum[i] ].name<<endl;
cout<<endl;
}

void solve() //菜单函数
{
int z;
while(1)
{
printf("\n选择您需要的操作(选择序号):\n");
printf("1.按学校编号排序输出\n");
printf("2.按学校总分排序输出\n");
printf("3.按学校男总分排序输出\n");
printf("4.按学校女总分排序输出\n");
printf("5.查询某个学校成绩\n");
printf("6.查询某个项目成绩\n");
printf("7.结束\n\n");
scanf("%d",&z);
if(z==1)bianhao();
if(z==2)zongfen();
if(z==3)malezf();
if(z==4)femalezf();
if(z==5)cxsch();
if(z==6)cxxm();
if(z==7)break;
}
}
int main() //主函数
{
input();
solve();
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2011-09-24
展开全部
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0
#define MaxSize 30

typedef struct athletestruct /*运动员*/
{
char name[20];
int score; /*分数*/
int range; /**/
int item; /*项目*/
}ATH;
typedef struct schoolstruct /*学校*/
{
int count; /*编号*/
int serial; /**/
int menscore; /*男选手分数*/
int womenscore; /*女选手分数*/
int totalscore; /*总分*/
ATH athlete[MaxSize]; /**/
struct schoolstruct *next;
}SCH;

int nsc,msp,wsp;
int ntsp;
int i,j;
int overgame;
int serial,range;
int n;
SCH *head,*pfirst,*psecond;
int *phead=NULL,*pafirst=NULL,*pasecond=NULL;

input ()
{
char answer;
head = (SCH *)malloc(sizeof(SCH)); /**/
head->next = NULL;
pfirst = head;
answer = 'y';
while ( answer == 'y' )
{
Is_Game_DoMain:
printf("\nGET Top 5 when odd\nGET Top 3 when even");
printf("\n输入运动项目序号 (x<=%d):",ntsp);
scanf("%d",pafirst);
overgame = *pafirst;
if ( pafirst != phead )
{
for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )
{
if ( overgame == *pasecond )
{
printf("\n这个项目已经存在请选择其他的数字\n");
goto Is_Game_DoMain;
}
}
}
pafirst = pafirst + 1;
if ( overgame > ntsp )
{
printf("\n项目不存在");
printf("\n请重新输入");
goto Is_Game_DoMain;
}
switch ( overgame%2 )
{
case 0: n = 3;break;
case 1: n = 5;break;
}
for ( i = 1 ; i <= n ; i++ )
{
Is_Serial_DoMain:
printf("\n输入序号 of the NO.%d (0<x<=%d): ",i,nsc);

scanf("%d",&serial);
if ( serial > nsc )
{
printf("\n超过学校数目,请重新输入");
goto Is_Serial_DoMain;
}
if ( head->next == NULL )
{
create();
}
psecond = head->next ;
while ( psecond != NULL )
{
if ( psecond->serial == serial )
{
pfirst = psecond;
pfirst->count = pfirst->count + 1;
goto Store_Data;
}
else
{
psecond = psecond->next;
}
}
create();
Store_Data:

pfirst->athlete[pfirst->count].item = overgame;
pfirst->athlete[pfirst->count].range = i;
pfirst->serial = serial; ("Input name:) : ");

scanf("%s",pfirst->athlete[pfirst->count].name);
}
printf("\n继续输入运动项目(y&n)?");
answer = getch();
printf("\n");
}
}

calculate() /**/
{
pfirst = head->next;
while ( pfirst->next != NULL )
{
for (i=1;i<=pfirst->count;i++)
{
if ( pfirst->athlete[i].item % 2 == 0 )
{
switch (pfirst->athlete[i].range)
{
case 1:pfirst->athlete[i].score = 5;break;
case 2:pfirst->athlete[i].score = 3;break;
case 3:pfirst->athlete[i].score = 2;break;
}
}
else
{
switch (pfirst->athlete[i].range)
{
case 1:pfirst->athlete[i].score = 7;break;
case 2:pfirst->athlete[i].score = 5;break;
case 3:pfirst->athlete[i].score = 3;break;
case 4:pfirst->athlete[i].score = 2;break;
case 5:pfirst->athlete[i].score = 1;break;
}
}
if ( pfirst->athlete[i].item <=msp )
{
pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;
}
else
{
pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;
}
}
pfirst->totalscore = pfirst->menscore + pfirst->womenscore;
pfirst = pfirst->next;
}
}

output()
{
pfirst = head->next;
psecond = head->next;
while ( pfirst->next != NULL )
{
clrscr();
printf("\n第%d号学校的结果成绩:",pfirst->serial);
printf("\n\n项目的数目\t学校的名字\t分数");
for (i=1;i<=ntsp;i++)
{
for (j=1;j<=pfirst->count;j++)
{
if ( pfirst->athlete[j].item == i )
{

printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;

}
}
}
printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");
getch();
pfirst = pfirst->next;
}
clrscr();
printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");
pfirst = head->next;
while ( pfirst->next != NULL )
{
printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);
pfirst = pfirst->next;
}
printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");
getch();
}

create()
{

pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));
pfirst->next = head->next ;
head->next = pfirst ;

pfirst->count = 1;
pfirst->menscore = 0;
pfirst->womenscore = 0;
pfirst->totalscore = 0;
}
void Save()
{FILE *fp;
if((fp = fopen("school.dat","wb"))==NULL)
{printf("can't open school.dat\n");
fclose(fp);
return;
}
fwrite(pfirst,sizeof(SCH),10,fp);
fclose(fp);
printf("文件已经成功保存\n");
}

main()
{
system("cls");
printf("\n\t\t\t 运动会分数统计\n");
printf("输入学校数目 (x>= 5):");
scanf("%d",&nsc);
printf("输入男选手的项目(x<=20):");
scanf("%d",&msp);
printf("输入女选手项目(<=20):");
scanf("%d",&wsp);
ntsp = msp + wsp;

phead = calloc(ntsp,sizeof(int));
pafirst = phead;
pasecond = phead;
input();
calculate();
output();
Save();
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
qianz1998
2011-09-03 · TA获得超过4684个赞
知道小有建树答主
回答量:534
采纳率:0%
帮助的人:306万
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
258aa33
2011-09-21 · TA获得超过100个赞
知道小有建树答主
回答量:334
采纳率:0%
帮助的人:608万
展开全部
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class School{
private:
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(10)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式