|
|
|
|
@ -1,522 +0,0 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<conio.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#define R 100
|
|
|
|
|
int Z;
|
|
|
|
|
struct player_data
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
char name[15];
|
|
|
|
|
double score;
|
|
|
|
|
}player[R];
|
|
|
|
|
/* 设置光标 */
|
|
|
|
|
void gotoxy(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
COORD pos;
|
|
|
|
|
pos.X = x;
|
|
|
|
|
pos.Y = y;
|
|
|
|
|
SetConsoleCursorPosition(handle, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 初始化模块,将文件中的数据写入结构体后关闭文件 */
|
|
|
|
|
void beginning()
|
|
|
|
|
{
|
|
|
|
|
int A=20;
|
|
|
|
|
int i=0;
|
|
|
|
|
FILE *fp_beginning;
|
|
|
|
|
if((fp_beginning=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(A)
|
|
|
|
|
{
|
|
|
|
|
fread(&player[i],sizeof(player[0]),1,fp_beginning);
|
|
|
|
|
i++;
|
|
|
|
|
A--;
|
|
|
|
|
}
|
|
|
|
|
rewind(fp_beginning);
|
|
|
|
|
if(fclose(fp_beginning))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* 主菜单 */
|
|
|
|
|
int menu()
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
printf("\n\n\n");
|
|
|
|
|
printf("\t\t\t\t\t\t-------------------------------\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 欢迎使用歌手比赛系统 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 1.输入选手数据 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 2.评委打分 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 3.成绩排序(按平均分) |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 4.数据查询 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 5.追加学生数据 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 6.写入数据文件 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t| 7.退出程序 |\n");
|
|
|
|
|
printf("\t\t\t\t\t\t-------------------------------\n");
|
|
|
|
|
printf("\t\t\t\t\t\t 请输入你的选择 \n");
|
|
|
|
|
printf("\t\t\t\t\t\t 请优先输入选手数据再打分 \n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
system("cls") ;
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
/* 求每一个选手的平均分 */
|
|
|
|
|
void all_aver()
|
|
|
|
|
{
|
|
|
|
|
int n,i,j;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
i=0; Z=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if(fread(&player[i], sizeof(player[0]),1,fp) == 1);
|
|
|
|
|
Z++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("请以编号给选手打分\n");
|
|
|
|
|
int m;
|
|
|
|
|
printf("录入分数请按1,退出请按0\n");
|
|
|
|
|
scanf("%d",&m);
|
|
|
|
|
while(m==1)
|
|
|
|
|
{
|
|
|
|
|
printf("请输入你想要打分选手的编号\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
for(i=0;i<Z+1;i++)
|
|
|
|
|
{
|
|
|
|
|
if(n==player[i].num)
|
|
|
|
|
{
|
|
|
|
|
printf("%d %s %.lf\n",player[i].num,player[i].name,player[i].score);
|
|
|
|
|
printf("请为选手打分\n");
|
|
|
|
|
|
|
|
|
|
double scor[10];/*10个评委的成绩*/
|
|
|
|
|
double mark;/*最后得分*/
|
|
|
|
|
int max=-1;/*最高分*/
|
|
|
|
|
int min=101;/*最低分*/
|
|
|
|
|
int sum=0;/*10个评委的总分*/
|
|
|
|
|
for(j=0;j<10;j++)
|
|
|
|
|
{
|
|
|
|
|
printf("请依次输入第%d个评委的分数:",j+1);
|
|
|
|
|
scanf("%lf",&scor[j]);
|
|
|
|
|
sum=sum+scor[j];
|
|
|
|
|
}
|
|
|
|
|
for(j=0;j<10;j++)
|
|
|
|
|
{
|
|
|
|
|
if(scor[j]>max)
|
|
|
|
|
max=scor[j];
|
|
|
|
|
}
|
|
|
|
|
for(j=0;j<10;j++)
|
|
|
|
|
{
|
|
|
|
|
if(scor[j]<min)
|
|
|
|
|
min=scor[j];
|
|
|
|
|
}
|
|
|
|
|
mark=(sum-max-min)/8.0;
|
|
|
|
|
printf("该位选手的平均成绩为%.1f\n",mark);
|
|
|
|
|
player[i].score=mark;
|
|
|
|
|
}
|
|
|
|
|
else continue;
|
|
|
|
|
}
|
|
|
|
|
printf("录入分数请按1,退出请按0\n");
|
|
|
|
|
scanf("%d",&m);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
FILE *fp_all_aver;
|
|
|
|
|
if((fp_all_aver=fopen("player_data.txt","w+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<Z+1;i++)
|
|
|
|
|
{
|
|
|
|
|
fwrite(&player[i],sizeof(player[0]),1,fp_all_aver);
|
|
|
|
|
}
|
|
|
|
|
if(fclose(fp_all_aver))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 输入选手数据 */
|
|
|
|
|
void w_player_data()
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
for(Z=0;Z<R;Z++)
|
|
|
|
|
{
|
|
|
|
|
printf("按1继续输入选手数据\n");
|
|
|
|
|
printf("按任意键退出\n");
|
|
|
|
|
scanf("%d",&j);
|
|
|
|
|
if(j!=1) break;
|
|
|
|
|
printf("编号: 姓名:\n");
|
|
|
|
|
scanf("%d%s",&player[Z].num, player[Z].name);
|
|
|
|
|
player[Z].score=0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FILE *fp_w_player_data;
|
|
|
|
|
if((fp_w_player_data=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{ printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<Z;i++)
|
|
|
|
|
{
|
|
|
|
|
fwrite(&player[i],sizeof(player[0]),1,fp_w_player_data);
|
|
|
|
|
}
|
|
|
|
|
if(fclose(fp_w_player_data))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/*将选手成绩进行排名,并输出选手信息*/
|
|
|
|
|
void rank()
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
i=0; Z=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if(fread(&player[i], sizeof(player[0]),1,fp) == 1);
|
|
|
|
|
Z++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
struct player_data t;
|
|
|
|
|
for(i=0;i<Z+1;i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=i+1;j<Z;j++)
|
|
|
|
|
{
|
|
|
|
|
if(player[j].score > player[i].score)
|
|
|
|
|
{
|
|
|
|
|
t=player[i];
|
|
|
|
|
player[i]=player[j];
|
|
|
|
|
player[j]=t;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("所有歌手成绩由高到低排列如下:\n");
|
|
|
|
|
i=1;
|
|
|
|
|
for(j=0;j<Z+1;j++)
|
|
|
|
|
{
|
|
|
|
|
if(player[j].num!=0)
|
|
|
|
|
printf("NO.%d名:%d %s %.lf\n",i,player[j].num,player[j].name,player[j].score);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void query_data()
|
|
|
|
|
{
|
|
|
|
|
int n,i,b,d;
|
|
|
|
|
char j[15];
|
|
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
i=0; Z=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if(fread(&player[i], sizeof(player[0]),1,fp) == 1);
|
|
|
|
|
Z++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf("请输入所要查询的选手的其中一个信息\n");
|
|
|
|
|
printf("输入1以编号查询,输入2以姓名查询\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
do{
|
|
|
|
|
|
|
|
|
|
printf("请输入所要查询选手的编号:\n");
|
|
|
|
|
scanf("%d",&b);
|
|
|
|
|
for(i=0;i<Z+1;i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(b==player[i].num)
|
|
|
|
|
{
|
|
|
|
|
printf("选手的全部信息如下:\n");
|
|
|
|
|
printf("%d %s %.1lf\n",player[i].num,player[i].name,player[i].score);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("查询输入1,退出输入0");
|
|
|
|
|
scanf("%d",&d);
|
|
|
|
|
}
|
|
|
|
|
while(d==1); break;
|
|
|
|
|
case 2:
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
printf("请输入所要查询选手的姓名\n");
|
|
|
|
|
scanf("%s", j);
|
|
|
|
|
|
|
|
|
|
int key =0;
|
|
|
|
|
for(i=0; i<Z+1; i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(j, player[i].name)==0)
|
|
|
|
|
{
|
|
|
|
|
key = 1;
|
|
|
|
|
printf("\t\t\t\t\t\t选手的全部信息如下:\n");
|
|
|
|
|
printf("\t\t\t\t\t\t%d %s %.1lf\n",player[i].num,player[i].name,player[i].score);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(key == 0)
|
|
|
|
|
{
|
|
|
|
|
printf("你输入的选手信息有误\n");
|
|
|
|
|
}
|
|
|
|
|
printf("继续查询输入1,退出输入0\n");
|
|
|
|
|
scanf("%d",&d);
|
|
|
|
|
}
|
|
|
|
|
while(d==1); break;
|
|
|
|
|
default:printf("输入错误,自动退出\n"); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/* 追加选手数据 */
|
|
|
|
|
void add_data()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int n,i,j,k;
|
|
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
i=0; Z=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if(fread(&player[i], sizeof(player[0]),1,fp) == 1);
|
|
|
|
|
Z++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
int choice=1;
|
|
|
|
|
while(choice==1)
|
|
|
|
|
{
|
|
|
|
|
printf("请输入所要追加选手的个数\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("追加的第%d位选手数据:\n",i+1);
|
|
|
|
|
printf("请输入选手相关数据:\n");
|
|
|
|
|
printf("编号 姓名\n");
|
|
|
|
|
scanf("%d%s",&player[Z+i+1].num, player[Z+i+1].name);
|
|
|
|
|
double scor[10];/*十个评委的分数*/
|
|
|
|
|
double mark;/*最后得分*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double max=-1.0;/*最高分*/
|
|
|
|
|
double min=101.0;/*最低分*/
|
|
|
|
|
double sum=0.0;/*10个评委的总分*/
|
|
|
|
|
for(k=0;k<10;k++)
|
|
|
|
|
{
|
|
|
|
|
printf("请依次输入第%d个评委的分数",k+1);
|
|
|
|
|
scanf("%lf",&scor[k]);
|
|
|
|
|
sum=sum+scor[k];
|
|
|
|
|
}
|
|
|
|
|
for(k=0;k<10;k++)
|
|
|
|
|
{
|
|
|
|
|
if(scor[k]>max)
|
|
|
|
|
max=scor[k];
|
|
|
|
|
}
|
|
|
|
|
for(k=0;k<10;k++)
|
|
|
|
|
{
|
|
|
|
|
if(scor[k]<min)
|
|
|
|
|
min=scor[k];
|
|
|
|
|
}
|
|
|
|
|
mark=(sum-max-min)/8.0;
|
|
|
|
|
printf("\t\t\t\t\t\t该位选手的平均成绩为%.1lf\n",mark);
|
|
|
|
|
player[Z+i+1].score=mark;
|
|
|
|
|
}
|
|
|
|
|
Z+=n;
|
|
|
|
|
printf("继续追加请输入1,输入0退出\n");
|
|
|
|
|
scanf("%d",&choice);
|
|
|
|
|
}
|
|
|
|
|
if((fp=fopen("player_data.txt","w+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(i=0; i<Z+1; i++)
|
|
|
|
|
fwrite(&player[i], sizeof(player[0]), 1, fp);
|
|
|
|
|
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/* 将所有选手数据写入一个新建数据文件 */
|
|
|
|
|
void w_data_file()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("player_data.txt","a+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
i=0; Z=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if(fread(&player[i], sizeof(player[0]),1,fp) == 1);
|
|
|
|
|
Z++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FILE *fp_extra;
|
|
|
|
|
if((fp_extra=fopen("extra.txt","w+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("File open error!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<Z+1;i++)
|
|
|
|
|
{
|
|
|
|
|
if(player[i].num!=0)
|
|
|
|
|
fprintf(fp_extra,"%d %s %lf\n",player[i].num,player[i].name,player[i].score);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fclose(fp_extra))
|
|
|
|
|
{
|
|
|
|
|
printf("Can not close the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/* 主函数 */
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
printf("================================================欢迎使用歌手比赛系统===================================================\n");
|
|
|
|
|
printf("===================================================输入任意键继续======================================================\n");
|
|
|
|
|
getch();
|
|
|
|
|
system("cls");
|
|
|
|
|
beginning();
|
|
|
|
|
int op=1,OP;
|
|
|
|
|
while(op)
|
|
|
|
|
{
|
|
|
|
|
OP=menu();
|
|
|
|
|
switch(OP)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
{
|
|
|
|
|
printf("1.输入选手数据 \n");
|
|
|
|
|
printf("编号 姓名 \n");
|
|
|
|
|
w_player_data();
|
|
|
|
|
system("cls");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t\t\t\t 2.评委打分 \n");
|
|
|
|
|
printf("\t\t\t\t\t\t评分范围(1——10分) \n");
|
|
|
|
|
printf("\t\t\t\t\t\t 请输入打分分数 \n");
|
|
|
|
|
all_aver();
|
|
|
|
|
system("cls");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3:
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("\t\t\t\t\t\t3.成绩排序(按平均分) \n");
|
|
|
|
|
rank();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4:
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t\t\t\t4.数据查询 \n");
|
|
|
|
|
query_data();
|
|
|
|
|
system("cls");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 5:
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t\t\t\t5.追加学生数据 \n");
|
|
|
|
|
add_data();
|
|
|
|
|
system("cls");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 6:
|
|
|
|
|
{
|
|
|
|
|
w_data_file();
|
|
|
|
|
printf("\t\t\t\t\t\t已经写入数据文件 \n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 7:
|
|
|
|
|
{
|
|
|
|
|
printf("========================================================================================================================\n");
|
|
|
|
|
printf("\t\t\t\t\t\t\t感谢您的使用!\n");
|
|
|
|
|
printf("\t\t\t\t\t\t 正在退出歌手比赛系统!\n");
|
|
|
|
|
printf("\t\t\t\t\t\t\t按任意键退出\n");
|
|
|
|
|
printf("========================================================================================================================\n");
|
|
|
|
|
getch();
|
|
|
|
|
op=0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
printf("\t\t\t\t\t\t输入错误,请重新依据提示输入\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|