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.
253 lines
4.4 KiB
253 lines
4.4 KiB
#include<stdio.h>
|
|
#include<string.h>
|
|
#include<stdlib.h>
|
|
int len=0;
|
|
struct Student/*结构体尝试*//*全局变量*/
|
|
{
|
|
char id[200];
|
|
int clas;
|
|
char name[200];
|
|
double a;
|
|
double b;
|
|
double c;
|
|
double d;
|
|
}stu[10001];
|
|
int main()
|
|
{
|
|
void print();
|
|
void input();
|
|
void delet();
|
|
void selecting();
|
|
void order();
|
|
void sortclass();
|
|
void sortexam(int,int);
|
|
void judge();
|
|
void menuprint();
|
|
menuprint();
|
|
return 0;
|
|
}
|
|
void print()/*打印程序*/
|
|
{
|
|
int i;
|
|
for(i=1;i<=len;i++)
|
|
printf("%s,%d,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].a,stu[i].b,stu[i].c,stu[i].d);
|
|
}
|
|
void judge()
|
|
{
|
|
void print();
|
|
void input();
|
|
void delet();
|
|
void selecting();
|
|
void order();
|
|
void sortclass();
|
|
void sortexam(int,int);
|
|
void judge();
|
|
void menuprint();
|
|
int t;
|
|
scanf("%d",&t);
|
|
if(t==1)
|
|
input();
|
|
else if(t==2)
|
|
delet();
|
|
else if(t==3)
|
|
selecting();
|
|
else if(t==4)
|
|
order();
|
|
else if(t==5)
|
|
{
|
|
print();
|
|
menuprint();
|
|
}
|
|
else if(t!=6)
|
|
{
|
|
printf("Wrong input\nplease input again\n");
|
|
menuprint();
|
|
}
|
|
}
|
|
|
|
void menuprint()
|
|
{
|
|
printf("1.input\n");
|
|
printf("2.delet\n");
|
|
printf("3.select\n");
|
|
printf("4.order\n");
|
|
printf("5.output\n");
|
|
printf("6.quit\n");
|
|
printf("please input your option\n");
|
|
judge();
|
|
}
|
|
|
|
void input()/*输入程序*/
|
|
{
|
|
char e[1001];
|
|
len++;
|
|
printf("Id ");
|
|
scanf("%s",&stu[len].id);
|
|
|
|
printf("class ");
|
|
scanf("%d",&stu[len].clas);
|
|
printf("name ");
|
|
scanf("%s",&stu[len].name);
|
|
printf("score1 ");
|
|
scanf("%lf",&stu[len].a);
|
|
printf("score2 ");
|
|
scanf("%lf",&stu[len].b);
|
|
printf("score3 ");
|
|
scanf("%lf",&stu[len].c);
|
|
stu[len].d=stu[len].a+stu[len].b+stu[len].c;
|
|
printf("continue?\n");
|
|
scanf("%s",&e);
|
|
if(strcmp(e,"no")==0)
|
|
menuprint();
|
|
else if(strcmp(e,"yes")==0)
|
|
input();
|
|
|
|
}
|
|
void delet()/*删除程序*/
|
|
{
|
|
int i,j;
|
|
int k;/*储存长度*/
|
|
k=len;
|
|
char e[1001],f[1001];
|
|
scanf("%s",&e);
|
|
if(len>1)
|
|
{
|
|
for(i=1;i<=len;i++)
|
|
{
|
|
if(strcmp(stu[i].id,e)==0||strcmp(stu[i].name,e)==0)
|
|
{
|
|
|
|
k--;
|
|
for(j=i;j<=len;j++)
|
|
{
|
|
strcpy(stu[j].id, stu[j+1].id);
|
|
stu[j].clas=stu[j+1].clas;
|
|
strcpy(stu[j].name,stu[j+1].name);
|
|
stu[j].a=stu[j+1].a;
|
|
stu[j].b=stu[j+1].b;
|
|
stu[j].c=stu[j+1].c;
|
|
stu[j].d=stu[j+1].d;
|
|
}
|
|
}
|
|
}
|
|
if(k!=len)
|
|
len=k;
|
|
print();
|
|
}
|
|
else if(len<=1)
|
|
printf("You can't delete this one because there is only one student in it!\n");
|
|
printf("continue?\n");
|
|
scanf("%s",&f);
|
|
if(strcmp(f,"no")==0)
|
|
menuprint();
|
|
else if(strcmp(f,"yes")==0)
|
|
delet();
|
|
}
|
|
void selecting()
|
|
{
|
|
char e[1001],f[1001];
|
|
scanf("%s",&e);
|
|
int i,j;
|
|
for(i=1;i<=len;i++)
|
|
{
|
|
if(strcmp(stu[i].id,e)==0||strcmp(stu[i].name,e)==0)
|
|
{
|
|
printf("%s,%d,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].a,stu[i].b,stu[i].c,stu[i].d);
|
|
}
|
|
}
|
|
printf("continue?\n");
|
|
scanf("%s",&f);
|
|
if(strcmp(f,"no")==0)
|
|
menuprint();
|
|
else if(strcmp(f,"yes")==0)
|
|
selecting();
|
|
}
|
|
void sortclass()/*班级排序程序*/
|
|
{
|
|
int i,j;
|
|
char e[1001]="0";
|
|
int t=0;
|
|
double k=0;
|
|
for(i=1;i<=len;i++)/*冒泡*/
|
|
for(j=1;j<=len-i;j++)
|
|
{
|
|
if(stu[j].clas>stu[j+1].clas)
|
|
{
|
|
t=stu[j].clas;
|
|
stu[j].clas=stu[j+1].clas;
|
|
stu[j+1].clas=t;
|
|
strcpy(e,stu[j].id);
|
|
strcpy(stu[j].id, stu[j+1].id);
|
|
strcpy(stu[j+1].id,e);
|
|
strcpy(e,stu[j].name);
|
|
strcpy(stu[j].name, stu[j+1].name);
|
|
strcpy(stu[j+1].name,e);
|
|
k=stu[j].a;
|
|
stu[j].a=stu[j+1].a;
|
|
stu[j+1].a=k;
|
|
k=stu[j].b;
|
|
stu[j].b=stu[j+1].b;
|
|
stu[j+1].b=k;
|
|
k=stu[j].c;
|
|
stu[j].c=stu[j+1].c;
|
|
stu[j+1].c=k;
|
|
k=stu[j].d;
|
|
stu[j].d=stu[j+1].d;
|
|
stu[j+1].d=k;
|
|
}
|
|
}
|
|
}
|
|
void sortexam(int m,int h)/*班内排序程序*/
|
|
{
|
|
int i,j;
|
|
char e[1001]="0";
|
|
int t=0;
|
|
double k=0;
|
|
for(i=m;i<=h;i++)/*冒泡*/
|
|
for(j=m;j<=h-i;j++)
|
|
{
|
|
if(stu[j].d<stu[j+1].d)
|
|
{
|
|
t=stu[j].clas;
|
|
stu[j].clas=stu[j+1].clas;
|
|
stu[j+1].clas=t;
|
|
strcpy(e,stu[j].id);
|
|
strcpy(stu[j].id, stu[j+1].id);
|
|
strcpy(stu[j+1].id,e);
|
|
strcpy(e,stu[j].name);
|
|
strcpy(stu[j].name, stu[j+1].name);
|
|
strcpy(stu[j+1].name,e);
|
|
k=stu[j].a;
|
|
stu[j].a=stu[j+1].a;
|
|
stu[j+1].a=k;
|
|
k=stu[j].b;
|
|
stu[j].b=stu[j+1].b;
|
|
stu[j+1].b=k;
|
|
k=stu[j].c;
|
|
stu[j].c=stu[j+1].c;
|
|
stu[j+1].c=k;
|
|
k=stu[j].d;
|
|
stu[j].d=stu[j+1].d;
|
|
stu[j+1].d=k;
|
|
}
|
|
}
|
|
}
|
|
void order()
|
|
{
|
|
int k=0;
|
|
int i;
|
|
sortclass();
|
|
k=1;/*前端*/
|
|
for(i=1;i<=len;i++)
|
|
{
|
|
if(stu[i+1].clas!=stu[k].clas)
|
|
{
|
|
sortexam(k,i);
|
|
k=i+1;
|
|
}
|
|
print();
|
|
menuprint();
|
|
}
|
|
}
|
|
|