You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
2.2 KiB

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct singer
{
char id[10];
int rank;
char name[10];
int score[10];
float mark;
};
int main(void)
{
int i,b,j,s,n,t;
FILE *fp;
int sum,max,min;
struct singer a[5];
printf(" 歌手比赛系统 \n");
printf(" 菜单 \n");
printf("1:输入选手编号和姓名\n");
printf("2:评委打分\n");
printf("3:计算平均分\n");
printf("4:成绩排序\n");
printf("5:写入数据文件\n");
printf("6:查看文件数据\n");
printf("7:退出系统\n");
printf(" ");
for( ; ;)
{
printf("输入序号选择功能");
scanf("%d",&n);
switch(n)
{
case 1:
printf("输入选手编号和姓名\n");
for(i=0;i<5;i++)
{
printf("输入%d号选手的编号和名字:",i);
scanf("%s %s",a[i].id,a[i].name);
}
break;
case 2:
printf("评委打分\n");
printf("最高分为100分\n");
for(i=0;i<5;i++)
{
printf("评委给%d号歌手打分:\n",i);
for(j=0;j<5;j++)
{
printf("%d号评委给歌手打分:",j);
scanf("%d",&a[i].score[j]);
}
}
break;
case 3:
for(i=0;i<5;i++)
{
max=a[i].score[0];
min=a[i].score[0];
sum=0;
for(j=0;j<5;j++)
{
sum=sum+a[i].score[j];
if(a[i].score[j]>max)
{
max=a[i].score[j];
}
if(a[i].score[j]<min)
{
min=a[i].score[j];
}
}
printf("%d号歌手的平均分",i);
a[i].mark=(sum-min-max)/3.0;
printf("%f\n",a[i].mark);
}
break;
case 4:
for(i=0;i<=n;i++)
{
s=0;
for(j=0;j<=n;j++)
{
if(a[i].mark<a[j].mark)
s++;
}
a[i].rank=s;
}
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{
if(i==a[j].rank)
printf("%s是第%d 得分为%.2f\n",a[j].name,i,a[j].mark);
}
printf("\n");
}
break;
case 5:
if((fp=fopen("singer.txt","w"))==NULL)
{
printf("cann't open file");
}
for(i=0;i<5;i++)
{
fwrite(&a[i],sizeof(struct singer),1,fp);
}
fclose(fp);
printf("保存成功\n");
break;
case 6:
if((fp=fopen("singer.txt","rb"))==NULL)
{
printf("cann't open file");
}
for(i=0;i<5;i++)
{
fscanf(fp,"%s %s %f",a[i].id,a[i].name,&a[i].mark);
printf("%s %s %f\n",a[i].id,a[i].name,&a[i].mark);
}
break;
case 7:
exit(0);
}
}
return 0;
}