课题一 运动会分数统计

2024-12-17 05:23:46
推荐回答(1个)
回答1:

#include
#include
#include
#include
#include
#define NULL 0
# define N 4
# define M 3
# define W 2

struct match_data
{int Range; /*paiming*/
char name[20];
int Score; /*defen*/
}match_data[M+W];

struct school_data
{struct match_data match_data[M+W];
int m_Score; /*nan yundongyuan defen*/
int w_Score; /*nv yundongyuan defen*/
int total_Score; /*zongfen*/
}school_data[N];

Waring_message()
{
printf ("\n Wrong input value! Please try again.\n");
}

input_1(m)
{
int i,j,k,T=1;
for(i=1,k=7;i<=3;i++,k-=2)
{printf ("态雀\启世n NO.%d : %d points.",i,k);
while(T)
{printf ("\n\n School number: (1--%d)",N);
scanf ("%d",&j);
if ((j>0)&&(j<=N)) T=0;
else { Waring_message();T=1;}
}
printf ("\n Please input the athlete's name:");
scanf ("%s",&school_data[j-1].match_data[m-1].name);
if (m<=M) school_data[j-1].m_Score+=k;
else school_data[j-1].w_Score+=k;
school_data[j-1].total_Score+=k;
school_data[j-1].match_data[m-1].Range=i;
school_data[j-1].match_data[m-1].Score=k;
T=1;
}

for(i=4,k=2;i<=5;i++,k-=1)
{printf ("\n NO.%d : %d points",i,k);
while(T)
{printf ("\n\n School number: (1--%d)",N);
scanf ("%d",&j);
if ((j>0)&&(j<=N)) T=0;
else { Waring_message();T=1;}
}
printf ("\n The athlete's name:");
scanf ("%s",&school_data[j-1].match_data[m-1].name);
if (m<=M) school_data[j-1].m_Score+=k;
else school_data[j-1].w_Score+=k;
school_data[j-1].total_Score+=k;
school_data[j-1].match_data[m-1].Range=i;
school_data[j-1].match_data[m-1].Score=k;
T=1;
}
}

input_2(m)
{int i,j,k=5; int T=1;
printf ("\n NO.1 : 5 points");
while(T)
{printf ("\n\n School number: (1--%d)",N);
scanf ("%d"帆旁早,&j);
if ((j>0)&&(j<=N)) T=0;
else { Waring_message();T=1;}
}
printf ("\n The athlete's name:");
scanf ("%s",&school_data[j-1].match_data[m-1].name);
if (m<=M) school_data[j-1].m_Score+=k;
else school_data[j-1].w_Score+=k;
school_data[j-1].total_Score+=k;
school_data[j-1].match_data[m-1].Range=1;
school_data[j-1].match_data[m-1].Score=k;

for(i=2,k=3;i<=3;i++,k-=1)
{T=1;
printf ("\n NO.%d : %d points",i,k);
while(T)
{printf ("\n\n School number: (1--%d)",N);
scanf ("%d",&j);
if ((j>0)&&(j<=N)) T=0;
else { Waring_message();T=1;}
}
printf ("\n The athlete's name:");
scanf ("%s",&school_data[j-1].match_data[m-1].name);
if (m<=M) school_data[j-1].m_Score+=k;
else school_data[j-1].w_Score+=k;
school_data[j-1].total_Score+=k;
school_data[j-1].match_data[m-1].Range=i;
school_data[j-1].match_data[m-1].Score=k;
}
}

input_3(m)
{int i,j,k,T,Q,S=1;
for(i=1,T=1;T==1;i++)
{printf ("\n NO.%d\n points:",i);
scanf ("%d",&k);
while(S)
{printf ("\n School number: (1--%d)",N);
scanf ("%d",&j);
if ((j>0)&&(j<=N)) S=0;
else { Waring_message();S=1;}
}
printf ("\n The athlete's name:");
scanf ("%s",&school_data[j-1].match_data[m-1].name);
if (m<=M) school_data[j-1].m_Score+=k;
else school_data[j-1].w_Score+=k;
school_data[j-1].total_Score+=k;
school_data[j-1].match_data[m-1].Range=i;
school_data[j-1].match_data[m-1].Score=k;

printf ("\n Continue?\n key 0:yes\n key 1-9:end\n");
scanf ("%d",&Q);
T=(Q==0);
S=1;
}
}

input()
{
int i,T=1;
while(T)
{printf ("\n Please input the number of the game: (1--%d)",M+W);
scanf ("%d",&i);
if ((i>0)&&(i<=M+W)) T=0;
else {Waring_message(); T=1;}
}
return (i);
}

output_1()
{
int n,m,T=1;
while (T)
{printf ("\n Please input the school number: (1--%d)",N);
scanf ("%d",&m);
if ((m>0)&&(m<=N)) T=0;
else { Waring_message(); T=1;}
}
printf ("\n Data of school %d:",m);
printf ("\n **************************************************************");
printf ("\n Item NO. Range Score NAME");
for (n=1;n<=(M+W);n++)
{printf ("\n\n %d %d",n,school_data[m-1].match_data[n-1].Range);
printf (" %d",school_data[m-1].match_data[n-1].Score);
printf (" %s",school_data[m-1].match_data[n-1].name);
}
printf ("\n **************************************************************\n");
}

output_2()
{int m,T=1;
while (T)
{printf ("\n Please input the school number:(1--%d)",N);
scanf ("%d",&m);
if ((m>0)&&(m<=N)) T=0;
else { Waring_message();T=1;}
}
printf ("\n Team data of school %d",m);
printf ("\n ****************************************************************");
printf ("\n M_Score W_Score TOTAL_Score");
printf ("\n\n %d",school_data[m-1].m_Score);
printf (" %d",school_data[m-1].w_Score);
printf (" %d",school_data[m-1].total_Score);
printf ("\n ****************************************************************\n");
}

main()
{
clrscr();
int s,m,T=1;
while(T)
{
m=input();
printf ("\n Please input the game type: ");
printf ("\n 0 : Type1");
printf ("\n 1 : Type2");
printf ("\n 2--9:user-defined\n");
scanf ("%d",&s);
if (s==0) input_1(m);
else if (s==1) input_2(m);
else input_3(m);
printf ("\n Press key 0 to continue input.\n key 1--9 to view data.");
scanf ("%d",&s);
if(s==0) T=1;
else T=0;
}

T=1;
while(T)
{printf ("\n key 0 : View school's game data.");
printf ("\n key 1 : View school's team data.");
printf ("\n key 2--9: End the programe.");
scanf ("%d",&s);
if(s==0) output_1();
else if(s==1) output_2();
else {T=0; printf (" Thanks, goodbye!\n");}
}

}