|
|
/*课程设计思路:
|
|
|
参赛选手信息输入:
|
|
|
姓名 性别 年龄 学校 项目(项目中的名次,及项目中获得的分数) 总分数
|
|
|
学校信息输入:
|
|
|
学校名称 学校编号 学校参加总数 学校总分数
|
|
|
项目信息输入:
|
|
|
选择名次方案:a种还是b种
|
|
|
各名次获得者姓名:
|
|
|
先输项目信息后输学校信息最后输选手信息
|
|
|
选手最大人数:max=50;每人允许参加的项目最大数为:max=5;
|
|
|
学校最大数目:max=10;
|
|
|
项目最多数:max=15;
|
|
|
建立模块之前应做:
|
|
|
首先问今年共有多少学生参加比赛?及每人最多参加几个项目?
|
|
|
问共有多少学校参加比赛?
|
|
|
问共有多少项目?
|
|
|
菜单:
|
|
|
输入选手信息:
|
|
|
输入学校信息:
|
|
|
输入项目信息:
|
|
|
寻找并输出选手信息:
|
|
|
寻找并输出项目信息:
|
|
|
寻找并输出学校信息:
|
|
|
学校排行输出:
|
|
|
参赛选手排行输出:*/
|
|
|
#include<stdio.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<string.h>
|
|
|
#include<process.h>
|
|
|
#include<conio.h>
|
|
|
|
|
|
FILE *fp; //定义文件指针
|
|
|
|
|
|
struct xmform1{
|
|
|
char name[20];
|
|
|
char mc1[10];
|
|
|
char mc2[10];
|
|
|
char mc3[10];
|
|
|
char mc4[10];
|
|
|
char mc5[10];
|
|
|
};
|
|
|
struct xmform2{
|
|
|
char name[20];
|
|
|
char mc1[10];
|
|
|
char mc2[10];
|
|
|
char mc3[10];
|
|
|
};
|
|
|
|
|
|
struct schoolform{
|
|
|
char name[20];
|
|
|
char id[10];
|
|
|
int number;
|
|
|
int scoer=0;
|
|
|
};
|
|
|
|
|
|
struct studentform{
|
|
|
char name[20];
|
|
|
char xb[10];
|
|
|
char number[10];
|
|
|
int age;
|
|
|
char name1[20]; //name1是选手所处学校名
|
|
|
struct {
|
|
|
char name[20];
|
|
|
char mc[50]="无名次";
|
|
|
int scoer=0;
|
|
|
} xm;
|
|
|
int allscoer;
|
|
|
};
|
|
|
int ggy(struct studentform student[]){
|
|
|
printf("请输入参加比赛的选手个数\n");
|
|
|
int n;
|
|
|
scanf("%d",&n);
|
|
|
getchar();
|
|
|
int i;
|
|
|
for(i=0;i<n;i++){
|
|
|
printf("请输入第%d个选手的姓名:\n",i+1);
|
|
|
gets(student[i].name);
|
|
|
printf("输入该选手的性别:\n");
|
|
|
gets(student[i].xb);
|
|
|
printf("请输入该选手的编号:\n");
|
|
|
gets(student[i].number);
|
|
|
printf("请输入该选手的年龄:\n");
|
|
|
scanf("%d",&student[i].age);
|
|
|
getchar();
|
|
|
printf("请输入该选手的学校名称:\n");
|
|
|
gets(student[i].name1);
|
|
|
printf("请输入该学生所参加的项目名称:\n");
|
|
|
gets(student[i].xm.name);
|
|
|
printf("当前一记录%d个学生的数据\n",i+1);
|
|
|
}
|
|
|
printf("信息输入结束\n");
|
|
|
printf("********************\n");
|
|
|
printf("是否对当前信息进行存档,按'y'表示是\n");
|
|
|
char next;
|
|
|
next=getch();
|
|
|
if(next=='y'){
|
|
|
//printf("开始打开文件\n");
|
|
|
//if((fp=fopen("studentform","rb+"))==NULL){
|
|
|
printf("开始创造文件\n");
|
|
|
if((fp=fopen("studentform","wb+"))==NULL){
|
|
|
printf("文件创造未成功\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("文件创造成功\n");
|
|
|
}
|
|
|
//}else{
|
|
|
//printf("文件已打开,并开始存储信息\n");
|
|
|
//}
|
|
|
printf("开始存储信息\n");
|
|
|
for(i=0;i<n;i++){
|
|
|
|
|
|
fprintf(fp,"%10s%5s%10s%5d%10s%10s",student[i].name,student[i].xb,student[i].number,student[i].age,student[i].name1,student[i].xm.name);
|
|
|
}
|
|
|
printf("存储完成\n");
|
|
|
printf("开始创造打开密匙\n");
|
|
|
if((fp=fopen("studentrs","wb+"))==NULL){
|
|
|
printf("打开密匙创造未成功\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("打开密匙创造成功\n");
|
|
|
}
|
|
|
fprintf(fp,"%5d",n);
|
|
|
fclose(fp);
|
|
|
printf("********************\n");
|
|
|
return n;
|
|
|
}}
|
|
|
int ggy1(struct schoolform school[]){
|
|
|
printf("请输入参加比赛的学校个数\n");
|
|
|
int n;
|
|
|
scanf("%d",&n);
|
|
|
getchar();
|
|
|
int i;
|
|
|
for(i=0;i<n;i++){
|
|
|
printf("请输入第%d个学校的名称:\n",i+1);
|
|
|
gets(school[i].name);
|
|
|
printf("请输入该学校编号:\n");
|
|
|
gets(school[i].id);
|
|
|
printf("请输入该学校参赛人数:\n");
|
|
|
scanf("%d",&school[i].number);
|
|
|
getchar();
|
|
|
printf("当前一共记录了%d学校的数据\n",i+1);
|
|
|
}
|
|
|
printf("信息输入结束\n");
|
|
|
printf("********************\n");
|
|
|
printf("是否对当前信息进行存档,按'y'表示是\n");
|
|
|
char next;
|
|
|
next=getch();
|
|
|
if(next=='y'){
|
|
|
//printf("开始打开文件\n");
|
|
|
//if((fp=fopen("schoolform","rb+"))==NULL){
|
|
|
printf("开始创造文件\n");
|
|
|
if((fp=fopen("schoolform","wb+"))==NULL){
|
|
|
printf("文件创造未成功\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("文件创造成功\n");
|
|
|
}
|
|
|
//}else{
|
|
|
//printf("文件已打开,并开始存储信息\n");
|
|
|
//}
|
|
|
printf("开始存储信息\n");
|
|
|
for(i=0;i<n;i++){
|
|
|
|
|
|
fprintf(fp,"%10s%10s%3d",school[i].name,school[i].id,school[i].number);
|
|
|
}
|
|
|
printf("存储完成\n");
|
|
|
fclose(fp);
|
|
|
printf("开始创造打开密匙\n");
|
|
|
if((fp=fopen("schoolgs","wb+"))==NULL){
|
|
|
printf("打开密匙创造未成功\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("打开密匙创造成功\n");
|
|
|
}
|
|
|
fprintf(fp,"%5d",n);
|
|
|
fclose(fp);
|
|
|
printf("********************\n");
|
|
|
|
|
|
}
|
|
|
return n;
|
|
|
}
|
|
|
|
|
|
int ggy2(struct xmform1 xm1[],struct studentform student[],struct schoolform school[],int schoolgs,int studentrs){
|
|
|
printf("请输入这一类项目的个数:\n");
|
|
|
int n;
|
|
|
scanf("%d",&n);
|
|
|
getchar();
|
|
|
int i,i1,i2;
|
|
|
int a1,a2;
|
|
|
for(i=0;i<n;i++){
|
|
|
printf("请输入该类第%d个项目名称:\n",i+1);
|
|
|
gets(xm1[i].name);
|
|
|
printf("输入该个项目获奖情况:第一名 第二名 第三名 第四名 第五名(依次按顺序输入姓名,注:输一个名字按一次回城)");
|
|
|
gets(xm1[i].mc1);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm1[i].mc1,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第一名");
|
|
|
student[i1].xm.scoer+=7;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=7;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
gets(xm1[i].mc2);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm1[i].mc2,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第二名");
|
|
|
student[i1].xm.scoer+=5;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=5;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
gets(xm1[i].mc3);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm1[i].mc3,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第三名");
|
|
|
student[i1].xm.scoer+=3;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=3;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
gets(xm1[i].mc4);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm1[i].mc4,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第四名");
|
|
|
student[i1].xm.scoer+=2;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=2;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
gets(xm1[i].mc5);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm1[i].mc5,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第五名");
|
|
|
student[i1].xm.scoer+=1;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
int a2;
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
printf("已输入%d个项目的情况\n",i+1);
|
|
|
}
|
|
|
printf("输入结束\n");
|
|
|
printf("********************\n");
|
|
|
return n;
|
|
|
}
|
|
|
|
|
|
int ggy3(struct xmform2 xm2[],struct studentform student[],struct schoolform school[],int schoolgs,int studentrs){
|
|
|
printf("请输入这一类项目的个数:\n");
|
|
|
int n;
|
|
|
scanf("%d",&n);
|
|
|
getchar();
|
|
|
int i,i1,i2;
|
|
|
int a1,a2;
|
|
|
for(i=0;i<n;i++){
|
|
|
printf("请输入该类第%d个项目名称:\n",i+1);
|
|
|
gets(xm2[i].name);
|
|
|
printf("输入该个项目获奖情况:第一名 第二名 第三名 (依次按顺序输入姓名,注:输一个名字按一次回车)");
|
|
|
gets(xm2[i].mc1);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm2[i].mc1,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第一名");
|
|
|
student[i1].xm.scoer+=5;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=5;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
gets(xm2[i].mc2);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm2[i].mc2,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第二名");
|
|
|
student[i1].xm.scoer+=3;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=3;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
gets(xm2[i].mc3);
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
|
|
|
a1=strcmp(xm2[i].mc3,student[i1].name);
|
|
|
if(a1==0){
|
|
|
strcpy(student[i1].xm.mc,"第三名");
|
|
|
student[i1].xm.scoer+=2;
|
|
|
for(i2=0;i2<schoolgs;i2++){
|
|
|
|
|
|
a2=strcmp(school[i2].name,student[i1].name1);
|
|
|
if(a2==0){
|
|
|
school[i2].scoer+=2;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
printf("已输入%d个项目的情况\n",i+1);
|
|
|
}
|
|
|
printf("输入结束\n");
|
|
|
printf("********************\n");
|
|
|
return n;
|
|
|
}
|
|
|
void xscz(struct studentform student[],int studentrs){ //定义一个选手查找并输出函数 (按姓名查找)
|
|
|
printf("请输入你要查找的选手名字\n");
|
|
|
char name[20];
|
|
|
gets(name);
|
|
|
int i,a,a1=0;
|
|
|
for(i=0;i<studentrs;i++){
|
|
|
a=strcmp(student[i].name,name);
|
|
|
if(a==0){
|
|
|
printf("将依次输出该选手信息:\n");
|
|
|
printf("姓名:%s 性别:%s 年龄:%d 编号:%s \n",student[i].name,student[i].xb,student[i].age,student[i].number);
|
|
|
printf("所属学校:%s 参加项目名称:%s 名次:%s 总分数:%d \n",student[i].name1,student[i].xm.name,student[i].xm.mc,student[i].xm.scoer);
|
|
|
a1=1; //防止有些选手信息未记录而找不到
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(a1==1){
|
|
|
;
|
|
|
}else{
|
|
|
printf("没有这个选手的信息\n");
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void xscz1(struct studentform student[],int studentrs){ //定义一个选手查找并输出函数 (按编号查找)
|
|
|
printf("请输入你要查找的选手编号\n");
|
|
|
char number[20];
|
|
|
gets(number);
|
|
|
int i,a,a1=0;
|
|
|
for(i=0;i<studentrs;i++){
|
|
|
a=strcmp(student[i].number,number);
|
|
|
if(a==0){
|
|
|
printf("将依次输出该选手信息:\n");
|
|
|
printf("姓名:%s 性别:%s 年龄:%d 编号:%s \n",student[i].name,student[i].xb,student[i].age,student[i].number);
|
|
|
printf("所属学校:%s 参加项目名称:%s 名次:%s 总分数:%d ",student[i].name1,student[i].xm.name,student[i].xm.mc,student[i].xm.scoer);
|
|
|
a1=1; //防止有些选手信息未记录而找不到
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(a1==1){
|
|
|
;
|
|
|
}else{
|
|
|
printf("没有这个选手的信息\n");
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void xmcz1(struct xmform1 xm1[],int xmgs1){
|
|
|
printf("请输入你要查找的项目名称\n");
|
|
|
char name[20];
|
|
|
gets(name);
|
|
|
int i,a,a1=0;
|
|
|
for(i=0;i<xmgs1;i++){
|
|
|
a=strcmp(xm1[i].name,name);
|
|
|
if(a==0){
|
|
|
printf("将依次输出该项目信息:\n");
|
|
|
printf("项目名称是:%s\n",xm1[i].name);
|
|
|
printf("第一名:%s 第二名:%s 第三名:%s 第四名:%s 第五名:%s ",xm1[i].mc1,xm1[i].mc2,xm1[i].mc3,xm1[i].mc4,xm1[i].mc5);
|
|
|
a1=1; //防止有些选手信息未记录而找不到
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(a1==1){
|
|
|
;
|
|
|
}else{
|
|
|
printf("没有这个项目的信息\n");
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void xmcz2(struct xmform2 xm2[],int xmgs2){
|
|
|
printf("请输入你要查找的项目名称\n");
|
|
|
char name[20];
|
|
|
gets(name);
|
|
|
int i,a,a1=0;
|
|
|
for(i=0;i<xmgs2;i++){
|
|
|
a=strcmp(xm2[i].name,name);
|
|
|
if(a==0){
|
|
|
printf("将依次输出该项目信息:\n");
|
|
|
printf("项目名称是:%s\n",xm2[i].name);
|
|
|
printf("第一名:%s 第二名:%s 第三名:%s \n",xm2[i].mc1,xm2[i].mc2,xm2[i].mc3);
|
|
|
a1=1; //防止有些选手信息未记录而找不到
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(a1==1){
|
|
|
;
|
|
|
}else{
|
|
|
printf("没有这个项目的信息\n");
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void xxcz1(struct schoolform school[],int schoolgs){
|
|
|
printf("请输入你要查找的学校名称\n");
|
|
|
char name[20];
|
|
|
gets(name);
|
|
|
int i,a,a1=0;
|
|
|
for(i=0;i<schoolgs;i++){
|
|
|
a=strcmp(school[i].name,name);
|
|
|
if(a==0){
|
|
|
printf("将依次输出该学校信息:\n");
|
|
|
printf("名称:%s 编号:%s 参赛人数:%d 总分数:%d \n",school[i].name,school[i].id,school[i].number,school[i].scoer);
|
|
|
//printf("所属学校:%s 参加项目名称:%s 名次:%s 总分数:%d ",student[i].name1,student[i].xm.name,student[i].xm.mc,student.xm.score);
|
|
|
a1=1; //防止有些选手信息未记录而找不到
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(a1==1){
|
|
|
;
|
|
|
}else{
|
|
|
printf("没有这个学校的信息\n");
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void xxcz2(struct schoolform school[],int schoolgs){
|
|
|
printf("请输入你要查找的学校编号\n");
|
|
|
char number[20];
|
|
|
gets(number);
|
|
|
int i,a,a1=0;
|
|
|
for(i=0;i<schoolgs;i++){
|
|
|
a=strcmp(school[i].id,number);
|
|
|
if(a==0){
|
|
|
printf("将依次输出该选学校信息:\n");
|
|
|
printf("名称:%s 编号:%s 参赛人数:%d 总分数:%d \n",school[i].name,school[i].id,school[i].number,school[i].scoer);
|
|
|
//printf("所属学校:%s 参加项目名称:%s 名次:%s 总分数:%d ",student[i].name1,student[i].xm.name,student[i].xm.mc,student.xm.score);
|
|
|
a1=1; //防止有些选手信息未记录而找不到
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(a1==1){
|
|
|
;
|
|
|
}else{
|
|
|
printf("没有这个学校的信息\n");
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void schoolph(struct schoolform school[],int schoolgs){
|
|
|
int max=school[0].scoer;int maxnumber=0;
|
|
|
int ph[50];
|
|
|
int i,i1,t,t1;
|
|
|
t1=schoolgs;
|
|
|
for(i1=0;i1<schoolgs;i1++){
|
|
|
for(i=0;i<schoolgs;i++){
|
|
|
if(school[i].scoer>max){
|
|
|
max=school[i].scoer;
|
|
|
maxnumber=i;
|
|
|
}}
|
|
|
t=school[schoolgs-1].scoer;
|
|
|
school[schoolgs-1].scoer=max;
|
|
|
school[maxnumber].scoer=t;
|
|
|
schoolgs-=1;
|
|
|
ph[i1]=maxnumber;
|
|
|
}
|
|
|
printf("学校排行由高到低输出依次是:\n");
|
|
|
schoolgs=t1;
|
|
|
//printf("学校个数是%d\n",schoolgs);
|
|
|
for(i=0;i<schoolgs;i++){
|
|
|
printf("名称:%s 分数:%d\n",school[ph[i]].name,school[ph[i]].scoer);
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void studentph(struct studentform student[],int studentrs){
|
|
|
int max=student[0].xm.scoer;int maxnumber=0;
|
|
|
int ph[50];
|
|
|
int i,i1,t,t1;
|
|
|
t1=studentrs;
|
|
|
for(i1=0;i1<studentrs;i1++){
|
|
|
for(i=0;i<studentrs;i++){
|
|
|
if(student[i].xm.scoer>max){
|
|
|
max=student[i].xm.scoer;
|
|
|
maxnumber=i;
|
|
|
}}
|
|
|
t=student[studentrs-1].xm.scoer;
|
|
|
student[studentrs-1].xm.scoer=max;
|
|
|
student[maxnumber].xm.scoer=t;
|
|
|
studentrs-=1;
|
|
|
ph[i1]=maxnumber;
|
|
|
}
|
|
|
printf("学生排行由高到低输出依次是:\n");
|
|
|
studentrs=t1;
|
|
|
for(i=0;i<studentrs;i++){
|
|
|
printf("姓名:%s 分数:%d\n",student[ph[i]].name,student[ph[i]].xm.scoer);
|
|
|
}
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void dudan1(struct schoolform school[]){
|
|
|
int schoolgs;
|
|
|
printf("开始打开密匙\n");
|
|
|
if((fp=fopen("schoolgs","rb+"))==NULL){
|
|
|
printf("密匙未能安全打开\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("密匙已经安全打开了\n");
|
|
|
}
|
|
|
rewind(fp);
|
|
|
fscanf(fp,"%5d",&schoolgs);
|
|
|
fclose(fp);
|
|
|
int i;
|
|
|
printf("开始打开文件\n");
|
|
|
if((fp=fopen("schoolform","rb+"))==NULL){
|
|
|
printf("文件未能安全打开\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("文件已经安全打开了\n");
|
|
|
}
|
|
|
rewind(fp); //将文件指针移到最前面
|
|
|
for(i=0;i<schoolgs;i++){
|
|
|
|
|
|
fscanf(fp,"%10s%10s%3d",school[i].name,school[i].id,&school[i].number);
|
|
|
}
|
|
|
printf("读取完毕\n");
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
void dudan2(struct studentform student[]){
|
|
|
int studentrs;
|
|
|
printf("开始打开密匙\n");
|
|
|
if((fp=fopen("studentrs","rb+"))==NULL){
|
|
|
printf("密匙未能安全打开\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("密匙已经安全打开了\n");
|
|
|
}
|
|
|
rewind(fp);
|
|
|
fscanf(fp,"%5d",&studentrs);
|
|
|
fclose(fp);
|
|
|
int i;
|
|
|
printf("开始打开文件\n");
|
|
|
if((fp=fopen("schoolform","rb+"))==NULL){
|
|
|
printf("文件未能安全打开\n");
|
|
|
exit(0);
|
|
|
}else{
|
|
|
printf("文件已经安全打开了\n");
|
|
|
}
|
|
|
rewind(fp); //将文件指针移到最前面
|
|
|
for(i=0;i<studentrs;i++){
|
|
|
|
|
|
fscanf(fp,"%10s%5s%10s%5d%10s%10s",student[i].name,student[i].xb,student[i].number,&student[i].age,student[i].name1,student[i].xm.name);
|
|
|
}
|
|
|
printf("读取完毕\n");
|
|
|
printf("********************\n");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
system("cls"); //清屏
|
|
|
system("color 2F"); //调程序颜色背景 (护眼)
|
|
|
printf("<<**********欢迎来到运动会比赛计分系统**********>>\n");
|
|
|
printf("此系统有以下功能选项:\n");
|
|
|
|
|
|
struct studentform student[50];
|
|
|
struct schoolform school[10];
|
|
|
struct xmform1 xm1[15];
|
|
|
struct xmform2 xm2[15];
|
|
|
int studentrs;
|
|
|
int schoolgs;
|
|
|
int xmgs1;
|
|
|
int xmgs2;
|
|
|
char name[10];
|
|
|
int a,a1,a2; //a2为方便switch退出时用的字符
|
|
|
int i;
|
|
|
int b1=1,b2=1; ///b1和b2作为“锁”必须对程序进行初始化输入才能解开
|
|
|
//scanf("%d",&a);
|
|
|
do{
|
|
|
printf("提示:赛前请对程序进行基本信息的输入(1.即完成选手信息的输入和学校信息的输入2.对选手信息和学校信息读档 )\n");
|
|
|
printf("********************\n");
|
|
|
printf("输入选手信息并存档(请按0)\n输入学校信息并存档(请按1)\n输入项目信息(请按2)\n寻找并输出选手信息(请按3)\n寻找并输出项目信息(请按4)\n寻找并输出学校信息(请按5)\n学校排行输出(请按6)\n参赛选手排行输出(请按7)\n");
|
|
|
printf("读档(请按8)\n");
|
|
|
printf("退出(请按9)\n");
|
|
|
printf("********************\n");
|
|
|
scanf("%d",&a);
|
|
|
do{
|
|
|
if(a==0||a==1||a==8||a==9) { break ;}
|
|
|
else{
|
|
|
|
|
|
if(b1==0&&b2==0){ break;
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
printf("请先完成程序初始化操作(按提示先操作)\n");
|
|
|
printf("********************\n");
|
|
|
printf("请重新按一次(0、1、8)\n");
|
|
|
scanf("%d",&a);
|
|
|
}}}while(1);
|
|
|
switch(a){
|
|
|
case 0:
|
|
|
//struct studentform student[50];
|
|
|
printf("你选择了输入选手信息功能\n");
|
|
|
//printf("共有多少位选手参赛?\n")
|
|
|
//int n;
|
|
|
//scanf("%d",&n);
|
|
|
studentrs=ggy(student);
|
|
|
b1=0 ;
|
|
|
break;
|
|
|
case 1:
|
|
|
//struct schoolform school[10];
|
|
|
printf("你选择了输入学校信息功能\n");
|
|
|
schoolgs=ggy1(school);
|
|
|
b2=0;
|
|
|
break;
|
|
|
case 2:
|
|
|
printf("你选择了输入项目信息功能\n");
|
|
|
printf("项目有两种一种取前五名,另一种取前三名。\n");
|
|
|
printf("开始第一类项目信息输入\n");
|
|
|
xmgs1=ggy2(xm1,student,school,schoolgs,studentrs);
|
|
|
printf("开始第二类项目信息输入\n");
|
|
|
xmgs2=ggy3(xm2,student,school,schoolgs,studentrs);
|
|
|
break;
|
|
|
case 3:
|
|
|
printf("你选择了寻找并输出选手信息的功能\n");
|
|
|
printf("有两种寻找方式 第一种根据选手姓名查找(按0) 第二种根据选手编号查找(按1) 请选择其中一种:\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
a2=1;
|
|
|
do{
|
|
|
switch(a1){
|
|
|
case 0:
|
|
|
printf("你选择了按选手姓名查找\n");
|
|
|
xscz(student,studentrs);
|
|
|
a2=0;
|
|
|
break;
|
|
|
case 1:
|
|
|
printf("你选择了根据选手编号查找\n");
|
|
|
xscz1(student,studentrs);
|
|
|
a2=0;
|
|
|
break;
|
|
|
default:
|
|
|
printf("请输入(0~1)以内的数\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
}
|
|
|
}while(a2);
|
|
|
break;
|
|
|
case 4:
|
|
|
printf("你选择了寻找并输出项目功能\n");
|
|
|
printf("有两种项目:第一类(分前五名)第二类(分前三名),请选择你要查找那类项目的信息(第一类按0)(第二类按1)\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
a2=1;
|
|
|
do{
|
|
|
switch(a1){
|
|
|
case 0:
|
|
|
printf("你选择了按第一类查找\n");
|
|
|
xmcz1(xm1,xmgs1);
|
|
|
a2=0;
|
|
|
break;
|
|
|
case 1:
|
|
|
printf("你选择了按第二类查找\n");
|
|
|
xmcz2(xm2,xmgs2);
|
|
|
a2=0;
|
|
|
break;
|
|
|
default:
|
|
|
printf("请输入(0~1)以内的数\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
}
|
|
|
}while(a2);
|
|
|
break;
|
|
|
case 5:
|
|
|
printf("你选择了寻找并输出学校信息的功能\n");
|
|
|
printf("有两种寻找方式 第一种根据学校名称查找(按0) 第二种根据学校编号查找(按1) 请选择其中一种:\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
a2=1;
|
|
|
do{
|
|
|
switch(a1){
|
|
|
case 0:
|
|
|
printf("你选择了按学校名称查找\n");
|
|
|
xxcz1(school,schoolgs);
|
|
|
a2=0;
|
|
|
break;
|
|
|
case 1:
|
|
|
printf("你选择了根据学校编号查找\n");
|
|
|
xxcz2(school,schoolgs);
|
|
|
a2=0;
|
|
|
break;
|
|
|
default:
|
|
|
printf("请输入(0~1)以内的数\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
}
|
|
|
}while(a2);
|
|
|
break;
|
|
|
case 6:
|
|
|
printf("你选择了学校排行输出功能\n");
|
|
|
schoolph(school,schoolgs);
|
|
|
break;
|
|
|
case 7:
|
|
|
printf("你选择了参赛选手排行输出功能\n");
|
|
|
studentph(student,studentrs);
|
|
|
break;
|
|
|
case 8:
|
|
|
printf("你选择了读档功能\n");
|
|
|
printf("请选择对:学校数据读档(请按0) 学生数据读档(请按1) 两个都读档(请按2)\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
a2=1;
|
|
|
do{
|
|
|
switch(a1){
|
|
|
case 0:
|
|
|
printf("你选择对学校数据读档\n");
|
|
|
dudan1(school);
|
|
|
b2=0;
|
|
|
a2=0;
|
|
|
break;
|
|
|
case 1:
|
|
|
printf("你选择了对学生数据读档\n");
|
|
|
dudan2(student);
|
|
|
b1=0;
|
|
|
a2=0;
|
|
|
break;
|
|
|
case 2:
|
|
|
printf("你选择了两个都读档\n");
|
|
|
dudan1(school);
|
|
|
dudan2(student);
|
|
|
b1=0;
|
|
|
b2=0;
|
|
|
printf("都读取完毕了\n");
|
|
|
a2=0;
|
|
|
break;
|
|
|
default:
|
|
|
printf("请输入(0~2)以内的数\n");
|
|
|
scanf("%d",&a1);
|
|
|
getchar();
|
|
|
}
|
|
|
}while(a2);
|
|
|
break;
|
|
|
|
|
|
case 9:
|
|
|
printf("成功退出,感谢使用!\n");
|
|
|
return 0;
|
|
|
default:
|
|
|
printf("请按(0~9)以内的数字\n");
|
|
|
}
|
|
|
}while(1);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|