|
|
@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#define N 3
|
|
|
|
|
|
|
|
#define M 10
|
|
|
|
|
|
|
|
int add = N - 1;
|
|
|
|
|
|
|
|
int sum[N] = { 0 }, Max[N], Min[N];
|
|
|
|
|
|
|
|
float aver[N] = { 0 };
|
|
|
|
|
|
|
|
struct player
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
char name[8];
|
|
|
|
|
|
|
|
int score[M];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void c(const unsigned short textColor)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(textColor>=0 && textColor<=15)
|
|
|
|
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textColor);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);}
|
|
|
|
|
|
|
|
void Inistplayer(struct player a[], int n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("请输入选手的序号和姓名(输入格式:序号 姓名)\n");
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scanf("%d %s", &a[i].num, a[i].name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Inputscore(int score[], int n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
|
|
scanf("%d",&score[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void sort(struct player a[], float b[], int n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i, k, j,t;
|
|
|
|
|
|
|
|
float temp;
|
|
|
|
|
|
|
|
char str[8];
|
|
|
|
|
|
|
|
for (i = 0; i < n-1; 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int flag = 1, i, m, j;
|
|
|
|
|
|
|
|
char n;
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
struct player a[20];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(flag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c(4);printf(" 歌手比赛管理系统 \n");
|
|
|
|
|
|
|
|
c(4);printf("★★★★★★★★★★★★★★★★★★★★★★★★\n");
|
|
|
|
|
|
|
|
c(1);printf(" 1)输入选手数据 \n");
|
|
|
|
|
|
|
|
c(5);printf(" 2)评委打分 \n");
|
|
|
|
|
|
|
|
c(6);printf(" 3)成绩排序 \n");
|
|
|
|
|
|
|
|
c(8);printf(" 4)数据查询 \n");
|
|
|
|
|
|
|
|
c(9);printf(" 5)追加学生数据 \n");
|
|
|
|
|
|
|
|
c(10);printf(" 6)写入数据文件 \n");
|
|
|
|
|
|
|
|
c(13);printf(" 7)退出系统 \n");
|
|
|
|
|
|
|
|
c(4);printf("★★★★★★★★★★★★★★★★★★★★★★★★\n");
|
|
|
|
|
|
|
|
c(15);printf(" \n");
|
|
|
|
|
|
|
|
printf("输入序号以选择功能:");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scanf("%d,",&n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:system("cls");
|
|
|
|
|
|
|
|
Inistplayer(a,N);printf("Press any key to continue...");
|
|
|
|
|
|
|
|
getch();system("cls");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<N;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("注意事项:所有成绩满分为10,最低分为0\n");
|
|
|
|
|
|
|
|
printf("评委给第%d位选手的分数是:",i+1);
|
|
|
|
|
|
|
|
Inputscore(a[i].score,M);
|
|
|
|
|
|
|
|
printf("第%d位的选手所有成绩:\n",i+1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(j=0;j<M;j++)
|
|
|
|
|
|
|
|
{ printf("%d\t",a[i].score[j]);}
|
|
|
|
|
|
|
|
printf("\n") ;
|
|
|
|
|
|
|
|
printf("Press any key to continue...");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("成绩计算规则:去掉最高分,去掉最低分\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\t%5.2f\n",a[i].name,aver[i]);}printf("Press any key to continue...");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
system("cls"); break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
}printf("Press any key to continue...");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
system("cls"); break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
system("cls"); printf("请输入要追加的选手数据:\n");
|
|
|
|
|
|
|
|
add=add+1;
|
|
|
|
|
|
|
|
scanf("%d %s",&a[add].num,a[add].name);
|
|
|
|
|
|
|
|
printf("Press any key to continue...");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
system("cls"); break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("将数据写入文件\n");
|
|
|
|
|
|
|
|
fp=fopen("歌手比赛数据文件.txt","w");
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
for(i<add+2;i++;)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(fp,"%d %s %d %d %d %5.2f",a[i].num,a[i].name,sum[i],Max[i],Min[i],aver[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);printf("Press any key to continue...");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
system("cls"); break;
|
|
|
|
|
|
|
|
case 7:system("cls");exit(0);
|
|
|
|
|
|
|
|
system("cls"); break;
|
|
|
|
|
|
|
|
default:flag=0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|