|
|
@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
#include<stdio.h> //编译预处理命令
|
|
|
|
|
|
|
|
#include<stdlib.h> //定义杂项函数及内存分配函数
|
|
|
|
|
|
|
|
#include<string.h> //字符串处理
|
|
|
|
|
|
|
|
#include <time.h> //用到了time函数
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int num=0;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
load();
|
|
|
|
|
|
|
|
printf("|----歌唱比赛管理系统----\n");
|
|
|
|
|
|
|
|
printf("\n ----------------------\n");
|
|
|
|
|
|
|
|
printf("| [1] 参赛歌手信息录入 |\n");
|
|
|
|
|
|
|
|
printf("| [2] 参赛歌手信息显示 |\n");
|
|
|
|
|
|
|
|
printf("| [3] 查询参赛歌手信息 |\n");
|
|
|
|
|
|
|
|
printf("| [4] 修改评委打分 |\n");
|
|
|
|
|
|
|
|
printf("| [5] 查询出场次序 |\n");
|
|
|
|
|
|
|
|
printf("| [6] 比赛结果排序 |\n");
|
|
|
|
|
|
|
|
printf("| [7] 退出系统 |\n");
|
|
|
|
|
|
|
|
printf(" ----------------------\n");
|
|
|
|
|
|
|
|
printf("请选择要进行的操作:");
|
|
|
|
|
|
|
|
scanf("%d",&num);
|
|
|
|
|
|
|
|
switch(num)//菜单
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1 : info_sign();break;//录入
|
|
|
|
|
|
|
|
case 2 : info_show();break;//显示
|
|
|
|
|
|
|
|
case 3 : info_find();break;//查找
|
|
|
|
|
|
|
|
case 4 : grade_modify();break;//修改
|
|
|
|
|
|
|
|
case 5 : find_order();break;
|
|
|
|
|
|
|
|
case 6 : result_sort();break;
|
|
|
|
|
|
|
|
case 7 : exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct node{
|
|
|
|
|
|
|
|
int id;//编号
|
|
|
|
|
|
|
|
char name[20];//姓名
|
|
|
|
|
|
|
|
double score[11];//成绩
|
|
|
|
|
|
|
|
double sum;//平均分
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}st[100],s;
|
|
|
|
|
|
|
|
int snum=0;
|
|
|
|
|
|
|
|
int load() /********************************************加载文件数据到内存 *************************************/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
snum=0;
|
|
|
|
|
|
|
|
FILE *fp; //声明文件指针
|
|
|
|
|
|
|
|
fp=fopen("info.txt","r"); //以读的方式打开文件
|
|
|
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("数据文件加载失败,疑似info.dat文件丢失,或者未导入数据\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
while(!feof(fp)){//遍历 文件数据
|
|
|
|
|
|
|
|
fread(&st[snum++],sizeof(struct node),1,fp); //snum是参赛选手的数量,每读取一条数据加一次。
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(snum>0)
|
|
|
|
|
|
|
|
snum--;
|
|
|
|
|
|
|
|
else snum=0;
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("数据条数:%d\n",snum);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int save() /**********************************将内存数据写入文件******************************************/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
int i,t=0;
|
|
|
|
|
|
|
|
fp=fopen("info.txt","w");//以写的方式打开参赛选手信息文件
|
|
|
|
|
|
|
|
for(i=0;i<snum;i++){
|
|
|
|
|
|
|
|
fwrite(&st[i],sizeof(struct node),1,fp);
|
|
|
|
|
|
|
|
//依次将数据读入st结构体
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("保存成功!\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//printf("%d\n",snum);//输出保存后的参赛选手数目,和课程数目
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int info_sign() /*************************添加参赛选手信息 *********************/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("数据条数:%d\n",snum);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("编号:");
|
|
|
|
|
|
|
|
scanf("%d",&st[snum].id);
|
|
|
|
|
|
|
|
printf("姓名:");
|
|
|
|
|
|
|
|
scanf("%s",st[snum].name);
|
|
|
|
|
|
|
|
printf("依次输入十位评委成绩:\n");
|
|
|
|
|
|
|
|
st[snum].sum=0;
|
|
|
|
|
|
|
|
double mi=0xffffff,ma=0;
|
|
|
|
|
|
|
|
for( i=0;i<10;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
scanf("%lf",&st[snum].score[i]);
|
|
|
|
|
|
|
|
if(mi>st[snum].score[i])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mi=st[snum].score[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ma<st[snum].score[i])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ma=st[snum].score[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
st[snum].sum+=st[snum].score[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
st[snum].sum=st[snum].sum-mi-ma;
|
|
|
|
|
|
|
|
st[snum].sum/=8;//求平均分
|
|
|
|
|
|
|
|
snum++;
|
|
|
|
|
|
|
|
save();//由于结构体里的数据有新的添加 ,所有这里调用一下保存函数
|
|
|
|
|
|
|
|
getchar();getchar();
|
|
|
|
|
|
|
|
}
|