1、include
2、 Item { int Inum[6]; //获奖项目编号 int Iscore[21][21]; //项目成绩 int Isum; //项目总数 }Item11; Item11 Item1[21]; School11 School1[21];; void Putscore() //输入成绩函数 { int m,w,k,b,j,h; printf("\n"); printf("\n *********请输入各项目信息 *********\n\n"); prin
3、tf(" 输入学校总数:"); scanf("%d",&School1[0].n); while(School1[0].n<=0||School1[0].n>20) { printf(" 输入错误,请重新输入。\n"); printf(" 输入学校总数:"); scanf("%d",&School1[0].n); } printf(" 输入男子项目
4、总数:"); scanf("%d",&m); while(m<=0||m>=20) { printf(" 输入错误,请重新输入。\n"); printf(" 输入男子项目总数:"); scanf("%d",&m); } printf(" 输入女子项目总数:"); scanf("%d",&w); while(w<=0||w>20) { printf("
5、 输入错误,请重新输入。\n"); printf(" 输入女子项目总数:"); scanf("%d",&w); } Item1[0].Isum=m+w; printf(" 男子项目编号为1至%d\n",m); printf(" 女子项目编号为%d至%d\n",m+1,m+w); for(k=1;k<=School1[0].n;k++) { printf("
6、 输入第%d个学校名称:",k); scanf("%s",&School1[k].name); School1[k].sumscore=0; School1[k].man=0; School1[k].woman=0; School1[k].num=k; } printf(" 输入项目编号,以-1作为结束:"); scanf("%d",&b); while(b!=EOF) //以-1为结束 { printf("
7、 前三名按3,前五名按5:"); scanf("%d",&j); while(j!=3&&j!=5) { printf(" 输入错误,请重新输入。\n"); printf(" 前三名按3,前五名按5:"); scanf("%d",&j); } if(j==3) { printf(" 输入获得第一名的学校编号:");
8、 scanf("%d",&h); Item1[0].Iscore[h][b]=5; Item1[b].Inum[1]=h; School1[h].score=School1[h].score+5; if(b<=m) School1[h].man=School1[h].man+5; else School1[h].woman=School1[h].woman+5; printf(" 输入获得第二名的学校编号:"); scanf("%d"
9、h); Item1[0].Iscore[h][b]=3; Item1[b].Inum[2]=h; School1[h].score=School1[h].score+3; if(b<=m) School1[h].man=School1[h].man+3; else School1[h].woman=School1[h].woman+3; printf(" 输入获得第三名的学校编号:"); scanf("%d",&h); Item1[
10、0].Iscore[h][b]=2; Item1[b].Inum[3]=h; School1[h].score=School1[h].score+2; if(b<=m) School1[h].man=School1[h].man+2; else School1[h].woman=School1[h].woman+2; } if(j==5) { printf(" 输入获得第一名的学校编号:"); scanf("%d",&h);
11、 Item1[0].Iscore[h][b]=7; Item1[b].Inum[1]=h; School1[h].score=School1[h].score+7; if(b<=m) School1[h].man=School1[h].man+7; else School1[h].woman=School1[h].woman+7; printf(" 输入获得第二名的学校编号:"); scanf("%d",&h); Item1[0].Isc
12、ore[h][b]=5; Item1[b].Inum[2]=h; School1[h].score=School1[h].score+5; if(b<=m) School1[h].man=School1[h].man+5; else School1[h].woman=School1[h].woman+5; printf(" 输入获得第三名的学校编号:"); scanf("%d",&h); Item1[0].Iscore[h][b]=3;
13、 Item1[b].Inum[3]=h; School1[h].score=School1[h].score+3; if(b<=m) School1[h].man=School1[h].man+3; else School1[h].woman=School1[h].woman+3; printf(" 输入获得第四名的学校编号:"); scanf("%d",&h); Item1[0].Iscore[h][b]=2; Item1[b].I
14、num[4]=h; School1[h].score=School1[h].score+2; if(b<=m) School1[h].man=School1[h].man+2; else School1[h].woman=School1[h].woman+2; printf(" 输入获得第五名的学校编号:"); scanf("%d",&h); Item1[0].Iscore[h][b]=1; Item1[b].Inum[5]=h; S
15、chool1[h].score=School1[h].score+1; if(b<=m) School1[h].man=School1[h].man+1; else School1[h].woman=School1[h].woman+1; } printf(" 输入项目编号,以-1作为结束:"); scanf("%d",&b); } system("pause"); printf("按任意键返回"); getchar(
16、); system("cls"); } void save() //存储数据文件 { FILE *fp1,*fp2; int i,j; if((fp1=fopen("a1","wb"))==NULL) //打开文件 { printf("cannot open this file\n"); return; } for(i=0;i<20;i++) if(fwrite(&Item1[i],sizeof(struct Item),1,fp1)!=1) //写数据块 printf("file write error\n")
17、 fclose(fp1); //关闭文件 if((fp2=fopen("a2","wb"))==NULL) //打开文件 { printf("cannot open this file\n"); return; } for(j=0;j<20;j++) if(fwrite(&School1[j],sizeof(struct School),1,fp2)!=1) //写数据块 printf("file write error\n"); fclose(fp2); //关闭文件 } void totalscore(School
18、11 r[]) //统计各学校总分 { int k; printf("\n\n ****** 输出各学校总分 ******\n"); printf(" 学校编号 学校总分\n"); for(k=1;k<=r[0].n;k++) { School1[k].sumscore=School1[k].man+School1[k].woman; printf("
19、 %d %d",School1[k].num,School1[k].sumscore);
printf("\n");
}
system("pause");
printf("按任意键返回");
getchar();
system("cls");
}
void schoolname(School11 School1[20]) //按名称排序
{
int i,j;
School11 t;
for(i=1;i 20、or(j=i+1;j<=School1[0].n;j++)
if(strcmp(School1[i].name,School1[j].name)>0)
{
t=School1[i];
School1[i]=School1[j];
School1[j]=t;
}
}
printf("\n ******按名称排列:******\n");
printf(" 学校编号 学校名称 21、 总分 男子总分 女子总分\n");
for(i=1;i<=School1[0].n;i++)
{
printf(" %2d%8s%7d%8d%8d\n", School1[i].num,School1[i].name,School1[i].man+School1[i].woman,School1[i].man,School1[i].woman);
}
system("pause");
printf("按任意键返回");
getchar();
system("cls" 22、);
}
void schoolnum(School11 School1[20],Item11 Item1[20]) //按编号排序
{
int i,j;
School11 t;
for(i=1;i 23、 School1[j]=t;
}
}
printf("\n ******按编号排列:******\n");
printf(" 学校编号 学校名称 总分 男子总分 女子总分\n");
for(i=1;i<=School1[0].n;i++)
{
printf(" %2d%8s%7d%8d%8d\n",School1[i].num,School1[i].name,School1[i].man+Sc 24、hool1[i].woman,School1[i].man,School1[i].woman);
}
system("pause");
printf("按任意键返回");
getchar();
system("cls");
}
void bubble1(School11 r[],int n) //总分冒泡法排序
{
School11 a;
int i,j,flag=1;
for(i=1;i 25、)
if(r[j+1].man+r[j+1].woman 26、or(j=1;j<=n-1;j++)
if(r[j+1].man 27、n-1;j++)
if(r[j+1].woman 28、 按学校总分排序结果为:\n");
printf(" ********************************************************\n");
printf(" * 学校名称 编号 总成绩 男团总成绩 女团总成绩 *\n");
for(i=n;i>=1;i--)
printf(" * %s\t %d\t%d\t %d\t\t %d\t *\n",r[i].name,r[i].nu 29、m,r[i].man+r[i].woman,r[i].man,r[i].woman);
printf(" ********************************************************\n");
system("pause");
printf("按任意键返回主菜单......");
getchar();
system("cls");
}
void man(School11 r[],int n) //男子团体总分排序
{
int i;
maopao2(r, n); 30、 //执行冒泡法排序2
printf(" 按男子团体总分排序结果为:\n"); //
printf(" ********************************************************\n");
printf(" * 学校名称 编号 总成绩 男团总成绩 女团总成绩 *\n");
for(i=n;i>=1;i--)
printf(" * %s\t 31、 %d\t%d\t %d\t\t %d\t *\n",r[i].name,r[i].num,r[i].man+r[i].woman,r[i].man,r[i].woman);
printf(" ********************************************************\n");
system("pause");
printf("按任意键返回");
getchar();
}
void woman(School11 r[],int n) //女子团体总分排序
32、{
int i;
maopao3(r, n); //执行冒泡法排序3
printf(" 按女子团体总分排序结果为:\n"); //
printf(" ********************************************************\n");
printf(" * 学校名称 编号 总成绩 男团总成绩 女团总成绩 *\n");
fo 33、r(i=n;i>=1;i--)
printf(" * %s\t %d\t%d\t %d\t\t %d\t *\n",r[i].name,r[i].num,r[i].man+r[i].woman,r[i].man,r[i].woman);
printf(" ********************************************************\n");
system("pause");
printf("按任意键返回");
getchar(); 34、
system("cls");
}
void search1(School11 School1[],Item11 Item1[]) //根据学校信息查询某个项目情况
{
int i,j;
printf("\n");
printf("\n");
printf("\n ******根据学校信息查询某个项目情况******\n");
printf("\n");
printf("\n");
printf(" 请输入要查询学校编号:");
scanf("%d",&i) 35、
printf("\n");
if(i<=0||i>School1[0].n)
{
printf(" 输入有误,请重新输入:");
scanf("%d",&i);
}
printf(" 输入要查询的项目编号:");
scanf("%d",&j);
printf("\n");
printf(" 学校编号:%d 项目%d:得%d分\n",i,j,Item1[0].Iscore[i][j]);
36、 system("pause");
printf("按任意键返回");
getchar();
system("cls");
}
void search2(School11 School2[20],Item11 Item2[20]) //根据项目信息查询学校情况
{
int i,j;
printf("\n");
printf("\n");
printf("\n ******根据项目信息查询学校情况******\n");
printf("\n");
print 37、f("\n");
printf(" 请输入要查询项目编号:");
scanf("%d",&i);
printf("\n");
if(i<=0||i>Item1[0].Isum)
{
printf(" 输入有误,请重新输入:");
scanf("%d",&i);
}
for(j=1;j<=School1[0].n;j++) //所有的学校
{
if (Item1[0].Iscore[j][i]!=0)
{
38、
printf(" 项目编号:%d 学校编号%d,得分%d\n",i,j,Item1[0].Iscore[j][i]);
}
}
system("pause");
printf("按任意键返回");
getchar();
system("cls");
}
void screen() //主菜单
{
printf("\n");
printf("\n");
printf(" ********************** 39、\n");
printf(" 运动会分数统计系统\n");
printf(" ***********************************************************\n");
printf(" * *\n");
pri 40、ntf(" * *\n");
printf(" * 1.输入成绩 *\n");
printf(" * 2.统计各学校总分 *\n");
printf(" * 3.按 41、学校编号排序输出 *\n");
printf(" * 4.按学校名称排序输出 *\n");
printf(" * 5.按学校总分排序输出 *\n");
printf(" * 6.统计男团体总分 *\n");
printf( 42、" * 7.统计女团体总分 *\n");
printf(" * 8.按学校编号查询学校某个项目情况 *\n");
printf(" * 9.按项目编号查询某个学校情况 *\n");
printf(" * 0.退出 43、 *\n");
printf(" * *\n");
printf(" * *\n");
printf(" **************************************************************\n");
pri 44、ntf("\n");
printf("\n");
printf(" 选择编号:");
}
void main()
{
int t;
while(1)
{
screen();
loop:scanf("%d",&t);
system("cls");
switch(t)
{
case 1:Putscore();save();break;
case 2:totalscore(School1);break; 45、
case 3:schoolnum(School1,Item1);break;
case 4:schoolname(School1);break;
case 5:zongfen(School1,School1[0].n);break;
case 6:man(School1,School1[0].n);break;
case 7:woman(School1,School1[0].n);break;
case 8:search1(School1,Item1);break;
case 9:search2(School1,Item1);break;
case 0:exit(0);
default:
{
printf("输入有误,请重新选择:");
goto loop;
}
}
}
}






