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.

793 lines
18 KiB

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NMAX 4 //学院每个项目最多4人
#define MAX 3 //个人最多三项
#define PEOPLE_MAX 6 //参赛人数得分以6为分界线
struct baoming
{
char number[12];
char school[15];
char name[12];
char sex[10];
char sport1[10];
char sport2[10];
char sport3[10];
};
void sign(struct baoming com,FILE *fp1,char d[])
{
printf("\t请输入您的学号:\n");
scanf("%s",com.number);
printf("\n请输入您的姓名");
scanf("%s",com.name);
char a[]={""};
char b[]={""};
printf("\t请输入您的性别\n");
printf("\t1.男 2.女");
int sex1;
scanf("%d",&sex1);
if(sex1==1)
{
strcpy(com.sex,a);
printf("男生的项目有:");
printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远");
printf("\n请输入您要报名的项目,没有填无");
scanf("%s",com.sport1);
printf("请再次输入");
scanf("%s",com.sport2);
printf("请再次输入");
scanf("%s",com.sport3);
fprintf(fp1,"%s %s %s %s %s %s %s\n ",com.number,d,com.name,com.sex,com.sport1,com.sport2,com.sport3);
}
else
{
strcpy(com.sex,b);
printf("女生的项目有:");
printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远");
printf("\n请输入您要报名的项目,没有填无");
scanf("%s",com.sport1);
printf("请再次输入");
scanf("%s",com.sport2);
printf("请再次输入");
scanf("%s",com.sport3);
fprintf(fp1,"%s %s %s %s %s %s %s\n",com.number,d,com.name,com.sex,com.sport1,com.sport2,com.sport3);
}
fclose(fp1);
printf("再见");
}
void sign_up()
{
printf("请选择学院:");
printf("1.计算机学院 2.电气学院");
printf("3.文新学院 4.机械学院");
printf("5.土木学院 6.经贸学院");
int choice;
scanf("%d",&choice);
switch(choice)
{
case 1:
{
FILE *fp;
char a[]="计算机学院";
struct baoming stu;
fp=fopen("computer.txt","a+");
if(fp==NULL)
printf("打开文件失败!");
sign(stu,fp,a);
break;
}
case 2:
{
FILE *fp;
char b[]="电气学院";
struct baoming stu;
fp=fopen("dianqi.txt","a+");
if(fp==NULL)
printf("打开文件失败!");
sign(stu,fp,b);
break;
}
case 3:
{
FILE *fp;
char c[]="文新学院";
struct baoming stu;
fp=fopen("wenxin.txt","a+");
if(fp==NULL)
printf("打开文件失败!");
sign(stu,fp,c);
break;
}
case 4:
{
FILE *fp;
char d[]="机械学院";
struct baoming stu;
fp=fopen("jixie.txt","a+");
if(fp==NULL)
printf("打开文件失败!");
sign(stu,fp,d);
break;
}
case 5:
{
FILE *fp;
char e[]="土木学院";
struct baoming stu;
fp=fopen("tumu.txt","a+");
if(fp==NULL)
printf("打开文件失败!");
sign(stu,fp,e);
break;
}
case 6:
{
FILE *fp;
char f[]="经贸学院";
struct baoming stu;
fp=fopen("jingmao.txt","a+");
if(fp==NULL)
printf("打开文件失败!");
sign(stu,fp,f);
break;
}
}
}
void chaxun(struct baoming stu,FILE *fp1)
{
char numbers[12];
int flag=0;
printf("\t请输入要查询的学号");
scanf("%s",numbers);
while(!feof(fp1)&&flag==0)
{
fscanf(fp1,"%s%s%s%s%s%s%s%s",&stu.number,stu.school,stu.name,stu.sex,stu.sport1,stu.sport2,stu.sport3);
if(strncmp(numbers,stu.number,11)==0)
{
printf("%s %s %s %s %s %s %s",stu.number,stu.name,stu.sex,stu.sport1,stu.sport2,stu.sport3);
flag=1;
printf("\t查询成功");
}
}
fclose(fp1);
}
void bmchaxun()
{
int x;
printf("请选择您的学院");
printf("1.计算机学院 2.电气学院");
printf("3.文新学院 4.外国语学院");
printf("5.土木学院 6.经贸学院");
scanf("%d",&x);
switch(x)
{
case 1:
{
struct baoming com;
FILE *fp=fopen("computer.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
}
chaxun(com,fp);
break;
}
case 2:
{
struct baoming com;
FILE *fp=fopen("dianqi.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
}
chaxun(com,fp);
break;
}
case 3:
{
struct baoming com;
FILE *fp=fopen("wenxin.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
}
chaxun(com,fp);
break;
}
case 4:
{
struct baoming com;
FILE *fp=fopen("jixie.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
}
chaxun(com,fp);
break;
}
case 5:
{
struct baoming com;
FILE *fp=fopen("tumu.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
}
chaxun(com,fp);
break;
}
case 6:
{
struct baoming com;
FILE *fp=fopen("jingmao.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
}
chaxun(com,fp);
break;
}
}
}
struct jianlu
{
char number[12];
char school[15];
char name[10];
char sex[5];
char sport[10];
};
void xie_ru(struct baoming stu,FILE *fp,FILE *fp1,char a[])
{
long last,h;
fseek(fp1,0L,SEEK_END);
last=ftell(fp1);
rewind(fp1);
while((h=ftell(fp1))<last-20)
{
fscanf(fp1,"%s%s%s%s%s%s%s",stu.number,stu.school,stu.name,stu.sex,stu.sport1,stu.sport2,stu.sport3);
if((strcmp(a,stu.sport1)==0)||(strcmp(a,stu.sport2)==0)||(strcmp(a,stu.sport3)==0))
{
fprintf(fp,"%s %s %s %s %s\n",stu.school,stu.number,stu.name,stu.sex,a);
}
}
fclose(fp1);
}
void jianlu(struct jianlu stu,FILE *fp)
{
fseek(fp,0L,SEEK_END);
long k;
long last=ftell(fp);
rewind(fp);
while((k=ftell(fp))<last-20)
{
fscanf(fp,"%s%s%s%s%s",stu.school,stu.number,stu.name,stu.sex,stu.sport);
printf("%s %s %s %s %s\n",stu.school,stu.number,stu.name,stu.sex,stu.sport);
}
}
void jianlu() //与上一个函数名字相同!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
int x;
printf("请选择项目");
printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远");
scanf("%d",&x);
FILE *fp1,*fp2,*fp3,*fp4,*fp5,*fp6;
struct baoming stu;
char a[]="标枪";
FILE *fp=fopen("标枪.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,a);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,a);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,a);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,a);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,a);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,a);
fclose(fp);
char b[]="跳高";
fp=fopen("跳高.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,b);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,b);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,b);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,b);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,b);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,b);
fclose(fp);
char c[]="100米";
fp=fopen("100米.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,c);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,c);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,c);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,c);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,c);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,c);
fclose(fp);
char d[]="400米";
fp=fopen("400米.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,d);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,d);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,d);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,d);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,d);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,d);
fclose(fp);
char e[]="1000米";
fp=fopen("1000米.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,e);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,e);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,e);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,e);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,e);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,e);
fclose(fp);
char f[]="5000米";
fp=fopen("5000米.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,f);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,f);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,f);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,f);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,f);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,f);
fclose(fp);
char g[]="跳远";
fp=fopen("跳远.txt","w+");
fp1=fopen("computer.txt","r");
xie_ru(stu,fp,fp1,g);
fp2=fopen("dianqi.txt","r");
xie_ru(stu,fp,fp2,g);
fp3=fopen("wenxin.txt","r");
xie_ru(stu,fp,fp3,g);
fp4=fopen("jixie.txt","r");
xie_ru(stu,fp,fp4,g);
fp5=fopen("tumu.txt","r");
xie_ru(stu,fp,fp5,g);
fp6=fopen("jingmao.txt","r");
xie_ru(stu,fp,fp6,g);
fclose(fp);
switch(x)
{
case 1:
{
fp=fopen("标枪.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
case 2:
{
fp=fopen("跳高.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
case 3:
{
fp=fopen("100米.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
case 4:
{
fp=fopen("400米.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
case 5:
{
fp=fopen("1000米.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
case 6:
{
fp=fopen("5000米.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
case 7:
{
fp=fopen("跳远.txt","r");
struct jianlu stu;
jianlu(stu,fp);
break;
}
}
}
struct dengji
{
char number[13];
char school[15];
char name[8];
char sex[6];
char sport[8];
int defen;
};
int dj(FILE *fp,FILE *fp1,struct dengji stu)
{
long h,last;
int k=0;
fseek(fp,0L,SEEK_END);
last=ftell(fp);
rewind(fp);
while(h=ftell(fp)<last-20)
{
fscanf(fp,"%s%s%s%s%s",stu.school,stu.number,stu.name,stu.sex,stu.sport);
k++;
}
rewind(fp);
if(k<=PEOPLE_MAX)
{
while(h=ftell(fp)<last-20)
{
fscanf(fp,"%s%s%s%s%s",stu.school,stu.number,stu.name,stu.sex,stu.sport);
printf("请输入%s的%s排名",stu.name,stu.sport);
scanf("%d",&stu.defen);
switch(stu.defen)
{
case 1:
fprintf(fp1,"%s %s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,5);
break;
case 2:
fprintf(fp1,"%s %s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,3);
break;
case 3:
fprintf(fp1,"%s %s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,2);
break;
}
}
}
if(k>PEOPLE_MAX)
{
while(h=ftell(fp)<last-20)
{
fscanf(fp,"%s%s%s%s%s",stu.school,stu.number,stu.name,stu.sex,stu.sport);
printf("请输入%s的%s排名",stu.name,stu.sport);
scanf("%d",&stu.defen);
switch(stu.defen)
{
case 1:
fprintf(fp1,"%s %s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,7);
break;
case 2:
fprintf(fp1,"%s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,5);
break;
case 3:
fprintf(fp1,"%s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,3);
break;
case 4:
fprintf(fp1,"%s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,2);
break;
case 5:
fprintf(fp1,"%s %s %s %s %d\n",stu.school,stu.number,stu.name,stu.sex,stu.sport,1);
break;
}
}
}
}
void dengji()
{
int x;
printf("请选择项目:\n");
printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远");
scanf("%d",&x);
switch(x)
{
case 1:
{
struct dengji stu;
FILE *fp=fopen("标枪.txt","r");
FILE *fp1=fopen("标枪排名.txt","w+");
dj(fp,fp1,stu);
break;
}
case 2:
{
struct dengji stu;
FILE *fp=fopen("跳高.txt","r");
FILE *fp1=fopen("跳高排名.txt","w+");
dj(fp,fp1,stu);
break;
}
case 3:
{
struct dengji stu;
FILE *fp=fopen("100米.txt","r");
FILE *fp1=fopen("100米排名.txt","w+");
dj(fp,fp1,stu);
break;
}
case 4:
{
struct dengji stu;
FILE *fp=fopen("400米.txt","r");
FILE *fp1=fopen("400米排名.txt","w+");
dj(fp,fp1,stu);
break;
}
case 5:
{
struct dengji stu;
FILE *fp=fopen("1000米.txt","r");
FILE *fp1=fopen("1000米排名.txt","w+");
dj(fp,fp1,stu);
break;
}
case 6:
{
struct dengji stu;
FILE *fp=fopen("5000米.txt","r");
FILE *fp1=fopen("5000米排名.txt","w+");
dj(fp,fp1,stu);
break;
}
case 7:
{
struct dengji stu;
FILE *fp=fopen("跳远.txt","r");
FILE *fp1=fopen("跳远排名.txt","w+");
dj(fp,fp1,stu);
break;
}
}
}
void shuchu(FILE *fp,struct dengji stu)
{
fseek(fp,0L,SEEK_END);
long k;
long last=ftell(fp);
rewind(fp);
while((k=ftell(fp))<last-20)
{
fscanf(fp,"%s%s%s%s%s%d",stu.number,stu.school,stu.name,stu.sex,stu.sport,&stu.defen);
printf("%s %s %s %s %s %d\n",stu.number,stu.school,stu.name,stu.sex,stu.sport,stu.defen);
}
fclose(fp);
}
void cjcx()
{
printf("请选择查询方式");
printf("1.竞赛项目 2.参赛学校(暂未实现) 3.参赛运动员(暂未实现)");
int x;
scanf("%d",&x);
switch(x)
{
case 1:
{
int d;
printf("请选择项目:\n");
printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远");
scanf("%d",&d);
switch(d)
{
case 1:
{
FILE *fp=fopen("标枪排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
case 2:
{
FILE *fp=fopen("跳高排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
case 3:
{
FILE *fp=fopen("100米排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
case 4:
{
FILE *fp=fopen("400米排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
case 5:
{
FILE *fp=fopen("1000米排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
case 6:
{
FILE *fp=fopen("5000米排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
case 7:
{
FILE *fp=fopen("跳远排名.txt","r");
struct dengji stu;
shuchu(fp,stu);
break;
}
}
break;
}
case 2:
{
break;
}
}
}
struct pai
{
char school[15];
int zf;
};
int hehe(FILE *fp,struct dengji stu,char a[])
{
long h,last;
int k=0;
fseek(fp,0L,SEEK_END);
last=ftell(fp);
rewind(fp);
while(h=ftell(fp)<last-20)
{
fscanf(fp,"%s%s%s%s%s%d",stu.school,stu.number,stu.name,stu.sex,stu.sport,&stu.defen);
if(strcmp(stu.school,a)==0)
{
k+=stu.defen;
}
}
return k;
}
int zongfen(char a[])
{
struct dengji stu;
int k=0;
FILE *fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7;
fp1=fopen("标枪排名.txt","r");
k+=hehe(fp1,stu,a);
fp2=fopen("跳高排名.txt","r");
k+=hehe(fp2,stu,a);
fp3=fopen("100米排名.txt","r");
k+=hehe(fp3,stu,a);
fp4=fopen("400米排名.txt","r");
k+=hehe(fp4,stu,a);
fp5=fopen("1000米排名.txt","r");
k+=hehe(fp5,stu,a);
fp6=fopen("5000米排名.txt","r");
k+=hehe(fp6,stu,a);
fp7=fopen("跳远排名.txt","r");
k+=hehe(fp7,stu,a);
return k;
}
void paixu()
{
int a=0,am=0,aw=0,b=0,bm=0,bw=0,c=0,cm=0,cw=0,d=0,dm=0,dw=0,e=0,em=0,ew=0,f=0,fm=0,fw=0;
FILE *fp=fopen("学院排序.txt","w+");
char z[]="计算机学院";
char y[]="电气学院";
char x[]="文新学院";
char w[]="机械学院";
char v[]="土木学院";
char u[]="经贸学院";
a=zongfen(z);
b=zongfen(y);
c=zongfen(x);
d=zongfen(w);
e=zongfen(v);
f=zongfen(u);
fprintf(fp,"%s的总分是%d\n",z,a);
fprintf(fp,"%s的总分是%d\n",y,b);
fprintf(fp,"%s的总分是%d\n",x,c);
fprintf(fp,"%s的总分是%d\n",w,d);
fprintf(fp,"%s的总分是%d\n",v,e);
fprintf(fp,"%s的总分是%d\n",u,f);
fclose(fp);
printf("%s的总分是%d\n",z,a);
printf("%s的总分是%d\n",y,b);
printf("%s的总分是%d\n",x,c);
printf("%s的总分是%d\n",w,d);
printf("%s的总分是%d\n",v,e);
printf("%s的总分是%d\n",u,f);
}
void menu()
{
int choice1;
char choice2;
do{
printf(" =====================运动员信息管理系统======================\n\n");
printf("\t1.报名 2.参赛信息查询\n");
printf("\t3.检录 4.成绩登记\n");
printf("\t5.成绩查询 6.排序\n");
printf("\t7.退出 \n");
printf("\t================================================\n");
printf("\n\n请选择功能<1-8>:");
scanf("%d",&choice1);
switch(choice1)
{
case 1:
system("cls");
sign_up();
break;
case 2:
system("cls");
bmchaxun();
break;
case 3:
system("cls");
jianlu();
break;
case 4:
system("cls");
dengji();
break;
case 5:
system("cls");
cjcx();
break;
case 6:
system("cls");
paixu();
break;
}
}while(0);
}
int main(void)
{
system("color 3f");
menu();
}