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.

165 lines
2.6 KiB

#include<stdio.h>
#include<string.h>
int top=0;
struct stu
{
char num[20];
char c[20];
char name[20];
float m,p,e,s;
}stu[100];
void first()
{
printf("1.input\n");
printf("2.delete\n");
printf("3.select\n");
printf("4.order\n");
printf("5.output\n");
printf("6.quit\n");
printf("please input your option\n");
}
void a5()
{
int i;
for(i=0;i<top;i++) printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].num,stu[i].c,stu[i].name,stu[i].m,stu[i].p,stu[i].e,stu[i].s);
}
void a1()
{
char n[20];
while(1)
{
printf("Id ");
scanf("%s",stu[top].num);
printf("class ");
scanf("%s",&stu[top].c);
printf("name ");
scanf("%s",stu[top].name);
printf("score1 ");
scanf("%f",&stu[top].m);
printf("score2 ");
scanf("%f",&stu[top].p);
printf("score3 ");
scanf("%f",&stu[top].e);
stu[top].s=stu[top].m+stu[top].p+stu[top].e;
top++;
printf("continue?\n");
do{
scanf("%s",n);
}while(strcmp(n,"yes")!=0&&strcmp(n,"no")!=0);
if(strcmp(n,"no")==0) return;
}
}
void a2()
{
int i,d;
char key[20],n[20];
while(1)
{
i=0,d=0;
scanf("%s",key);
while(i<top)
{
if(strcmp((stu+i)->num,key)==0||strcmp((stu+i)->name,key)==0)
{
d++;top--;
*(stu+i)=*(stu+i+d);
}
else
{
*(stu+i)=*(stu+i+d);
i++;
}
}
a5();
printf("continue?\n");
while(strcmp(n,"yes")!=0&&strcmp(n,"no")!=0);{
scanf("%s",n);
}
if(strcmp(n,"no")==0) return;
}
}
void a3()
{
int i,flag;
char key[20],n[20];
while(1)
{
flag=0;
scanf("%s",key);
for(i=0;i<top;i++)
{
if(strcmp((stu+i)->num,key)==0||strcmp((stu+i)->c,key)==0)
{
flag=1;
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].num,stu[i].c,stu[i].name,stu[i].m,stu[i].p,stu[i].e,stu[i].s);
}
}
if(!flag)
{
printf("there is no eligible student\n");
return;
}
printf("continue?\n");
do{
scanf("%s",n);
}while(strcmp(n,"yes")!=0&&strcmp(n,"no")!=0);
if(strcmp(n,"no")==0) return;
}
}
void a4()
{
int i,j;
struct stu t;
for(i=0;i<top;i++)
{
for(j=0;j<top-i-1;j++)
{
if(strcmp((stu+j)->c,(stu+j+1)->c)==1||strcmp((stu+j)->c,(stu+j+1)->c)==0&&((stu+j)->s<(stu+j+1)->s))
{
t = *(stu+j);
*(stu+j) = *(stu+j+1);
*(stu+j+1) = t;
}
}
}
a5();
return;
}
int main()
{
int n;
while(1)
{
first();
scanf("%d",&n);
switch(n)
{
case(1):
a1();
break;
case(2):
a2();
break;
case(3):
a3();
break;
case(4):
a4();
break;
case(5):
a5();
break;
case(6):
return 0;
}
}
}