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.

169 lines
2.8 KiB

#include<stdio.h>
#include<string.h>
#define N 100
struct stu_info
{
char num[20];
char cls[20];
char name[20];
float math,physics,english,total;
};
struct stu_info stu[N];
int top=0;
void print_menu()
{
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 print()
{
int i;
for(i=0;i<top;i++) printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].math,stu[i].physics,stu[i].english,stu[i].total);
}
void input()
{
char op[20];
while(1)
{
printf("Id ");
scanf("%s",stu[top].num);
printf("class ");
scanf("%s",&stu[top].cls);
printf("name ");
scanf("%s",stu[top].name);
printf("score1 ");
scanf("%f",&stu[top].math);
printf("score2 ");
scanf("%f",&stu[top].physics);
printf("score3 ");
scanf("%f",&stu[top].english);
stu[top].total=stu[top].math+stu[top].physics+stu[top].english;
top++;
printf("continue?\n");
do{
scanf("%s",op);
}while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0);
if(strcmp(op,"no")==0) return;
}
}
void del()
{
int i,d;
char key[20],op[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++;
}
}
print();
printf("continue?\n");
do{
scanf("%s",op);
}while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0);
if(strcmp(op,"no")==0) return;
}
}
void select()
{
int i,flag;
char key[20],op[20];
while(1)
{
flag=0;
scanf("%s",key);
for(i=0;i<top;i++)
{
if(strcmp((stu+i)->num,key)==0||strcmp((stu+i)->cls,key)==0)
{
flag=1;
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].math,stu[i].physics,stu[i].english,stu[i].total);
}
}
if(!flag)
{
printf("there is no eligible student\n");
return;
}
printf("continue?\n");
do{
scanf("%s",op);
}while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0);
if(strcmp(op,"no")==0) return;
}
}
void order()
{
int i,j;
struct stu_info tmp;
for(i=0;i<top;i++)
{
for(j=0;j<top-i-1;j++)
{
if(strcmp((stu+j)->cls,(stu+j+1)->cls)==1||strcmp((stu+j)->cls,(stu+j+1)->cls)==0&&((stu+j)->total<(stu+j+1)->total))
{
tmp = *(stu+j);
*(stu+j) = *(stu+j+1);
*(stu+j+1) = tmp;
}
}
}
print();
return;
}
int main()
{
int op;
while(1)
{
print_menu();
scanf("%d",&op);
switch(op)
{
case(1):
input();
break;
case(2):
del();
break;
case(3):
select();
break;
case(4):
order();
break;
case(5):
print();
break;
case(6):
return 0;
}
}
}