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.
366 lines
8.1 KiB
366 lines
8.1 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
#include<conio.h>
|
|
#include <time.h>
|
|
#define load sizeof(student)
|
|
#define N 7
|
|
void read();
|
|
void save();
|
|
|
|
int size=3;
|
|
struct student
|
|
{
|
|
char num[10];
|
|
char name[20];
|
|
int scorem,scoreq,scoreg,scorey;
|
|
char ximing[20];
|
|
}stu[N],temp;
|
|
|
|
void input()
|
|
{
|
|
system("cls");
|
|
printf("\t************输入界面************\n");
|
|
printf("请输入运动员号码,姓名,100成绩,铅球成绩,跳高成绩,跳远成绩,系名:\n");
|
|
for(int i=0;i<size;i++)
|
|
scanf("%s%s%d%d%d%d%s",&stu[i].num,&stu[i].name,&stu[i].scorem,&stu[i].scoreq,&stu[i].scoreg,&stu[i].scorey,&stu[i].ximing);
|
|
printf("输出运动员号码,姓名,100成绩,铅球成绩,跳高成绩,跳远成绩,系名:\n");
|
|
for(int i=0;i<size;i++)
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
}
|
|
void find()
|
|
{
|
|
system("cls");
|
|
printf("\t************查找界面************\n");
|
|
char fs[20];
|
|
read();
|
|
printf("输入你要查找运动员的号码或姓名:");
|
|
scanf("%s",&fs);
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
if(strcmp(stu[i].num,fs)==0)
|
|
{
|
|
printf("你要找的运动员已找到:\n");
|
|
printf("该生的号码,姓名,100米成绩,铅球成绩,跳高成绩,跳远成绩,系名:\n");
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
break;
|
|
}
|
|
else if(strcmp(stu[i].name,fs)==0)
|
|
{
|
|
printf("你要找的运动员已找到:\n");
|
|
printf("该生的号码,姓名,100米成绩,铅球成绩,跳高成绩,跳远成绩,系名:\n");
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
printf("你要找的运动员未找到:\n");
|
|
printf("该运动员缺赛或不存在!");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
void paixu()
|
|
{
|
|
system("cls");
|
|
printf("\t************排序界面************\n");
|
|
printf("对一百米的成绩排序:\n");
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
for(int j=i+1;j<size;j++)
|
|
{
|
|
if(stu[i].scorem<stu[j].scorem)
|
|
{
|
|
temp=stu[i];
|
|
stu[i]=stu[j];
|
|
stu[j]=temp;
|
|
}
|
|
}
|
|
}
|
|
printf("排序后:\n");
|
|
for(int i=0;i<size;i++)
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
}
|
|
void xiugai()
|
|
{
|
|
system("cls");
|
|
printf("\t************修改界面************\n");
|
|
char ch2[20],c;
|
|
char num[10],name[20];
|
|
int scorem,scoreq,scoreg,scorey,i;
|
|
char ximing[20];
|
|
printf("原始数据:\n");
|
|
read();
|
|
printf("输入你要修改运动员的姓名:");
|
|
scanf("%s",ch2);
|
|
for(i=0;i<size;i++)
|
|
{
|
|
if(strcmp(stu[i].name,ch2)==0)
|
|
{
|
|
printf("1.修改号码\n2.修改姓名\n3.修改100米成绩\n4.修改铅球成绩\n5.修改跳高成绩\n6.修改跳远成绩\n7.修改系名\n");
|
|
scanf("%d",&c);
|
|
switch(c)
|
|
{
|
|
case 1:
|
|
{
|
|
printf("请输入你修改的运动员号码:");
|
|
scanf("%s",&num);
|
|
strcpy(stu[i].num,num);
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
printf("输入你修改的运动员姓名:\n");
|
|
scanf("%s",&name);
|
|
strcpy(stu[i].name,name);
|
|
break;}
|
|
case 3:
|
|
{
|
|
printf("输入你修改的运动员100米成绩:");
|
|
scanf("%d",&scorem);
|
|
stu[i].scorem=scorem;
|
|
break;
|
|
}
|
|
case 4:
|
|
{
|
|
printf("输入你修改运动员铅球成绩:");
|
|
scanf("%d",&scoreq);
|
|
stu[i].scoreq=scoreq;
|
|
break;
|
|
}
|
|
case 5:
|
|
{
|
|
printf("输入你修改运动员跳高成绩:");
|
|
scanf("%d",&scoreg);
|
|
stu[i].scoreq=scoreq;
|
|
break;
|
|
}
|
|
case 6:
|
|
{
|
|
printf("输入你修改运动员跳远成绩:");
|
|
scanf("%d",&scorey);
|
|
stu[i].scorey=scorey;
|
|
break;
|
|
}
|
|
case 7:
|
|
{
|
|
printf("输入你修改运动员系名:");
|
|
scanf("%s",&ximing);
|
|
strcpy(stu[i].ximing,ximing);
|
|
break;
|
|
}
|
|
default:
|
|
printf("你的输入有误:\n");
|
|
}
|
|
printf("修改后的运动员数据:\n");
|
|
for(int i=0;i<size;i++)
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
}
|
|
}
|
|
save();
|
|
}
|
|
void defen()
|
|
{
|
|
system("cls");
|
|
printf("\t************得分界面************\n");
|
|
int x,y,z,w,o,p,q,i;
|
|
char ch1[20]="jisuanji",ch2[20]="tumu",ch3[20]="yejin";
|
|
printf("原始数据:\n");
|
|
read();
|
|
printf("各系的得分总分排序:\n");
|
|
for(i=0;i<size;i++)
|
|
{
|
|
if(stu[i].scorem==1) x=3;
|
|
else if(stu[i].scorem==2) x=2;
|
|
else if(stu[i].scorem==3) x=1;
|
|
else x=0;
|
|
|
|
if(stu[i].scoreq==1) y=3;
|
|
else if(stu[i].scoreq==2) y=2;
|
|
else if(stu[i].scoreq==3) y=1;
|
|
else y=0;
|
|
|
|
if(stu[i].scoreg==1) z=3;
|
|
else if(stu[i].scoreg==2) z=2;
|
|
else if(stu[i].scoreg==3) z=1;
|
|
else z=0;
|
|
|
|
if(stu[i].scorey==1) w=3;
|
|
else if(stu[i].scorey==2) w=2;
|
|
else if(stu[i].scorey==3) w=1;
|
|
else w=0;
|
|
}
|
|
|
|
for(i=0;i<size;i++)
|
|
{
|
|
if(strcmp(stu[i].ximing,ch1)==0)
|
|
{
|
|
o=x+y+z+w;
|
|
printf("计算机系总得分:%d\n",o);
|
|
}
|
|
else if(strcmp(stu[i].ximing,ch2)==0)
|
|
{
|
|
p=x+y+z+w;
|
|
printf("土木系总得分:%d\n",p);
|
|
}
|
|
else if(strcmp(stu[i].ximing,ch3)==0)
|
|
{
|
|
q=x+y+z+w;
|
|
printf("冶金系总得分:%d\n",q);
|
|
}
|
|
}
|
|
}
|
|
void shancchu()
|
|
{
|
|
system("cls");
|
|
printf("\t************删除界面************\n");
|
|
char ch1[20];
|
|
printf("原始数据:\n");
|
|
int i;
|
|
read();
|
|
printf("输入你要删除的运动员的姓名:\n");
|
|
scanf("%s",&ch1);
|
|
for(i=0;i<size;i++)
|
|
{
|
|
if(strcmp(stu[i].name,ch1)==0)
|
|
{
|
|
for(int j=i;j<size-1;j++)
|
|
stu[j]=stu[j+1];
|
|
}
|
|
}
|
|
printf("删除后的运动员数据:\n");
|
|
for(i=0;i<size-1;i++)
|
|
{
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
|
|
}size--;
|
|
save();
|
|
}
|
|
void charu()
|
|
{
|
|
system("cls");
|
|
int a;
|
|
printf("\t************插入界面************\n");
|
|
printf("请输入要插入的运动员个数:");
|
|
scanf("%d",&a);
|
|
for(int j=0;j<a;j++)
|
|
{
|
|
printf("输入要插入的运动员数据:\n");
|
|
printf("号码:");
|
|
scanf("%s",&stu[size].num);
|
|
printf("姓名:");
|
|
scanf("%s",&stu[size].name);
|
|
printf("100米成绩:");
|
|
scanf("%d",&stu[size].scorem);
|
|
printf("铅球成绩:");
|
|
scanf("%d",&stu[size].scoreq);
|
|
printf("跳高成绩:");
|
|
scanf("%d",&stu[size].scoreg);
|
|
printf("跳远成绩:");
|
|
scanf("%d",&stu[size].scorey);
|
|
printf("系名:");
|
|
scanf("%s",&stu[size].ximing);
|
|
for(int i=0;i<size+1;i++)
|
|
for(int j=i+1;j<size+1;j++)
|
|
if(stu[i].scorem<stu[j].scorem)
|
|
{
|
|
temp=stu[i];
|
|
stu[i]=stu[j];
|
|
stu[j]=temp;
|
|
}
|
|
size++;
|
|
}
|
|
printf("插入后运动员数据:\n");
|
|
for(int i=0;i<size;i++)
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
save();
|
|
}
|
|
void save()
|
|
{
|
|
FILE *fp;
|
|
if((fp=fopen("c:\\xiao.txt","w"))==NULL)
|
|
printf("\n保存中...Saving the file......\n");
|
|
for(int i=0;i<size;i++)
|
|
fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
fclose(fp);
|
|
printf("保存成功....Save the file successfully!\n");
|
|
}
|
|
void read()
|
|
{
|
|
FILE *fp;
|
|
if((fp=fopen("c:\\xiao.txt","r"))==NULL)
|
|
fscanf(fp,"运动员号码,姓名,100成绩,铅球成绩,跳高成绩,跳远成绩,系名:\n");
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
fscanf(fp,"%s\t%s\t%d\t%d\t%d\t%d\t%s\n",&stu[i].num,&stu[i].name,&stu[i].scorem,&stu[i].scoreq,&stu[i].scoreg,&stu[i].scorey,&stu[i].ximing);
|
|
printf("%s\t%s\t%d\t%d\t%d\t%d\t%s\n",stu[i].num,stu[i].name,stu[i].scorem,stu[i].scoreq,stu[i].scoreg,stu[i].scorey,stu[i].ximing);
|
|
}
|
|
fclose(fp);
|
|
}
|
|
void menu()
|
|
{
|
|
int ch1;
|
|
char ch2;
|
|
struct tm *pt;
|
|
time_t t;
|
|
t=time(NULL);
|
|
pt=localtime(&t);
|
|
do{
|
|
printf("\t\t当前系统日期:%d-%d-%d\n",pt->tm_year+1900,pt->tm_mon+1,pt->tm_mday);
|
|
printf("======================菜单=====================\n");
|
|
printf(" 1.输入 2.查找 \n");
|
|
printf(" 3.排序 4.修改 \n");
|
|
printf(" 5.得分 6.删除 \n");
|
|
printf(" 7.插入 8.保存 \n");
|
|
printf(" 9.显示 0.退出\n");
|
|
printf("===============================================\n");
|
|
printf("请选择功能<0-9>:[ ]\b\b");
|
|
scanf("%d",&ch1);
|
|
switch(ch1)
|
|
{
|
|
case 1:
|
|
input();
|
|
break;
|
|
case 2:
|
|
find();
|
|
break;
|
|
case 3:
|
|
paixu();
|
|
break;
|
|
case 4:
|
|
xiugai();
|
|
break;
|
|
case 5:
|
|
defen();
|
|
break;
|
|
case 6:
|
|
shancchu();
|
|
break;
|
|
case 7:
|
|
charu();
|
|
break;
|
|
case 8:
|
|
save();
|
|
break;
|
|
case 9:
|
|
read();
|
|
|
|
break;
|
|
case 0:
|
|
exit(0);
|
|
default:
|
|
printf("未进行任何操作!");
|
|
}
|
|
printf("\n");
|
|
printf("想要继续操作请按y\n");
|
|
getchar();
|
|
scanf("%2c",&ch2);
|
|
}while(ch2=='y');
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
system("color f");
|
|
menu();
|
|
}
|