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.
171 lines
2.9 KiB
171 lines
2.9 KiB
1 year ago
|
#include<stdio.h>
|
||
|
#include<string.h>
|
||
|
#include<stdlib.h>
|
||
|
int N=0;
|
||
|
void menu();
|
||
|
struct stu_info
|
||
|
{
|
||
|
int cls,flag;
|
||
|
char name[10],num[10];
|
||
|
float maths,physics,english;
|
||
|
}
|
||
|
stu[20];
|
||
|
void output()
|
||
|
{
|
||
|
int i;
|
||
|
for(i=0;i<N;i++)
|
||
|
printf("%s %d %s %.1f %.1f %.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
|
||
|
}
|
||
|
void sort(struct stu_info *stu,int n)
|
||
|
{
|
||
|
int i,j;
|
||
|
struct stu_info tmp;
|
||
|
for(i=0;i<n;i++)
|
||
|
{
|
||
|
for(j=0;j<n-i-1;j++)
|
||
|
{
|
||
|
if(((stu+j)->cls>(stu+j+1)->cls)||((stu+j)->cls==(stu+j+1)->cls)&&((stu+j)->num>(stu+j+1)->num))
|
||
|
{
|
||
|
tmp = *(stu+j);
|
||
|
*(stu+j) = *(stu+j+1);
|
||
|
*(stu+j+1) = tmp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
void input()
|
||
|
{
|
||
|
int i;
|
||
|
char y[5];
|
||
|
for(i=0;;i++)
|
||
|
{
|
||
|
printf("Id ");scanf("%s",stu[i].num);
|
||
|
printf("class ");scanf("%d",&stu[i].cls);
|
||
|
printf("name ");scanf("%s",stu[i].name);
|
||
|
printf("score1 ");scanf("%f",&stu[i].maths);
|
||
|
printf("score2 ");scanf("%f",&stu[i].physics);
|
||
|
printf("score3 ");scanf("%f",&stu[i].english);
|
||
|
printf("Continue?\n");
|
||
|
again1:
|
||
|
scanf("%s",y);
|
||
|
if(strcmp(y,"yes")==0) continue;
|
||
|
else if(strcmp(y,"no")==0)
|
||
|
{
|
||
|
N=i+1;
|
||
|
menu();
|
||
|
break;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("wrong input\n");
|
||
|
goto again1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
void del(struct stu_info* stu)
|
||
|
{
|
||
|
char key[10];char y[5];
|
||
|
scanf("%s",key);
|
||
|
int i;
|
||
|
for (i=0;i<N;i++)
|
||
|
{
|
||
|
if(strcmp((stu+i)->num,key)==0||strcmp((stu+i)->name,key)==0)
|
||
|
{
|
||
|
N--;
|
||
|
for(int j=i;j<N;j++)
|
||
|
{
|
||
|
*(stu+j)=*(stu+j+1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
output();
|
||
|
printf("Continue?\n");
|
||
|
again2:
|
||
|
scanf("%s",y);
|
||
|
if(strcmp(y,"yes")==0) del(stu);
|
||
|
else if(strcmp(y,"no")==0)
|
||
|
{
|
||
|
N=i;
|
||
|
menu();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("wrong input\n");
|
||
|
goto again2;
|
||
|
}
|
||
|
}
|
||
|
void sel(struct stu_info* stu)
|
||
|
{
|
||
|
char key[10];char y[5];int e=1,i;
|
||
|
scanf("%s",key);
|
||
|
for (i=0;i<N;i++)
|
||
|
{
|
||
|
if(strcmp((stu+i)->num,key)==0||strcmp((stu+i)->name,key)==0)
|
||
|
{
|
||
|
e=0;
|
||
|
printf("%s %d %s %.1f %.1f %.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
|
||
|
}
|
||
|
}
|
||
|
if(e) printf("there is no eligible student\n");
|
||
|
printf("Continue?\n");
|
||
|
again3:
|
||
|
scanf("%s",y);
|
||
|
if(strcmp(y,"yes")==0) sel(stu);
|
||
|
else if(strcmp(y,"no")==0)
|
||
|
{
|
||
|
menu();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("wrong input\n");
|
||
|
goto again3;
|
||
|
}
|
||
|
}
|
||
|
void order()
|
||
|
{
|
||
|
sort(stu,N);
|
||
|
output();
|
||
|
menu();
|
||
|
}
|
||
|
void menu()
|
||
|
{
|
||
|
int in;
|
||
|
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");
|
||
|
scanf("%d",&in);
|
||
|
switch(in)
|
||
|
{
|
||
|
case(1):
|
||
|
input();
|
||
|
break;
|
||
|
case(2):
|
||
|
del(stu);
|
||
|
break;
|
||
|
case(3):
|
||
|
sel(stu);
|
||
|
break;
|
||
|
case(4):
|
||
|
order();
|
||
|
break;
|
||
|
case(5):
|
||
|
output();
|
||
|
menu();
|
||
|
break;
|
||
|
case(6):
|
||
|
exit(0);
|
||
|
default:
|
||
|
printf("Wrong input\n");
|
||
|
}
|
||
|
}
|
||
|
int main()
|
||
|
{
|
||
|
menu();
|
||
|
return 0;
|
||
|
}
|