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.

148 lines
3.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<string.h>
#define M 10 //宏定义评委人数
struct player //结构体定义选手
{
int num;
char name[8];
int score[M];
};
void Intplayer(struct player a[],int n) //输入选手数据函数
{
int i;
printf("请输入参赛歌手的人数:");
scanf("%d",&n);
printf("请输入歌手的学号和姓名:\n");
for(i=0;i<n;i++)
scanf("%d %s",&a[i].num,&a[i].name);
}
void sort(struct player a[],float b[],int n) //排序函数
{
int i,k,j,t;
float temp;
char str[8];
for(i=0;i<n;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(b[k]>b[j])
k=j;
if(k!=i)
{
temp=b[i];
b[i]=b[k];
b[k]=temp;
strcpy(str,a[i].name);
strcpy(a[i].name,a[k].name);
strcpy(a[k].name,str);
t=a[i].num;
a[i].num=a[k].num;
a[k].num=t;
}
}
}
void main()
{
system("color F4"); //白底红字
int flag=1,n,i,m,j,r;
FILE *fp;
fp = fopen("data.txt","w+"); //文件写入位置
struct player a[20];
float aver[99]={0};
int sum[99]={0};
int Max[99];
int Min[99];
int add=2;
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("*************************************************************\n\n\n\n");
while(flag)
{
printf("请输入你想进行的操作:");
scanf("%d",&r);
switch(r)
{
case 1:
Intplayer(a,n); //调用输入数据函数
break;
case 2:
printf("请输入1中人数");
scanf("%d",&n);
for(i=0;i<n;i++) //参赛人数循环
{
printf("%d号选手得分情况\n",i+1);
for(j=0;j<M;j++) //评委打分循环
{
printf("第%d位评委打分",j+1);
scanf("%d",&a[i].score[j]);
}
}
break;
case 3:
printf("请输入1中人数");
scanf("%d",&n);
for(i=0;i<n;i++)
{
Max[i]=a[i].score[0];
Min[i]=a[i].score[0];
for(j=0;j<M;j++) //判断某选手得分最大最小值
{
sum[i]+=a[i].score[j];
if(Max[i]<a[i].score[j])
Max[i]=a[i].score[j];
if(Min[i]>a[i].score[j])
Min[i]=a[i].score[j];
}
aver[i]=(float)(sum[i]-Max[i]-Min[i])/(M-2);
}
sort(a,aver,n); //调用排序函数
for(i=0;i<n;i++)
printf("%s %5.2f\n",a[i].name,aver[i]);
break;
case 4:
printf("你想查询选手的数据:");
scanf("%d",&m);
for(i=0;i<n;i++)
if(a[i].num==m)
{
printf("%d号选手%s总分:%d,最高分%d,最低分%d,平均分%5.2f",a[i].num,a[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
break;
case 5:
printf("请输入要追加的选手数据:\n");
add += 1;
scanf("%d %s",&a[add].num,&a[add].name);
break;
case 6:printf("将数据写入文件中:\n");
for (i = 0 ; i < add+1 ; i++)
{
fprintf(fp,"%d ",a[i].num);
fprintf(fp,"%s ",a[i].name);
fprintf(fp,"%d\n",a[i].score);
}
break;
case 7:exit(0);
break;
default:flag=0;
}
}
}