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.
206 lines
3.1 KiB
206 lines
3.1 KiB
#include<stdio.h>
|
|
#include<string.h>
|
|
struct student
|
|
{
|
|
char id[20];
|
|
char name[20];
|
|
char clas[20];
|
|
double Math;
|
|
double Physic;
|
|
double English;
|
|
double sum;
|
|
}s[20];
|
|
int T=0;
|
|
void 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 inputstudent(struct student *t)
|
|
{
|
|
printf("Id ");
|
|
scanf("%s",&(t->id));
|
|
printf("class ");
|
|
scanf("%s",&(t->clas));
|
|
printf("name ");
|
|
scanf("%s",&(t->name));
|
|
printf("score1 ");
|
|
scanf("%lf",&(t->Math));
|
|
printf("score2 ");
|
|
scanf("%lf",&(t->Physic));
|
|
printf("score3 ");
|
|
scanf("%lf",&(t->English));
|
|
t->sum=t->Math+t->Physic+t->English;
|
|
T++;
|
|
}
|
|
void outputstudent(struct student *t)
|
|
{
|
|
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",t->id,t->clas,t->name,t->Math,t->Physic,t->English,t->sum);
|
|
}
|
|
void deletestudent(struct student *t)
|
|
{
|
|
char de[10];
|
|
scanf("%s",de);
|
|
int i=0;
|
|
while(i<T)
|
|
{
|
|
if(strcmp((t+i)->id,de)==0||strcmp((t+i)->name,de)==0)
|
|
{
|
|
for(int j=i;j<T-1;j++)
|
|
{
|
|
*(t+j)=*(t+j+1);
|
|
}
|
|
i--;
|
|
T--;
|
|
}
|
|
i++;
|
|
}
|
|
printf("\n");
|
|
for(int m=0;m<T;m++)
|
|
outputstudent((t+m));
|
|
}
|
|
void findstudent(struct student *t)
|
|
{
|
|
char f[10];
|
|
scanf("%s",f);
|
|
int p=0;
|
|
for(int i=0;i<T;i++)
|
|
{
|
|
if(strcmp((t+i)->id,f)==0||strcmp((t+i)->clas,f)==0)
|
|
{
|
|
outputstudent((t+i));
|
|
p=1;
|
|
}
|
|
if(i==T-1&&p==0)
|
|
printf("there is no eligible student\n");
|
|
}
|
|
}
|
|
void orderstudent(struct student *t)
|
|
{
|
|
for(int i=0;i<T;i++)
|
|
{
|
|
for(int j=i;j<T;j++)
|
|
{
|
|
if(strlen((t+i)->clas)>strlen((t+j)->clas))
|
|
{
|
|
struct student o;
|
|
o=*(t+i);
|
|
*(t+i)=*(t+j);
|
|
*(t+j)=o;
|
|
}
|
|
}
|
|
}
|
|
for(int i=0;i<T;i++)
|
|
{
|
|
for(int j=i;j<T;j++)
|
|
{
|
|
if(strlen((t+i)->clas)==strlen((t+j)->clas)&&strcmp((t+i)->clas,(t+j)->clas)>0)
|
|
{
|
|
struct student o;
|
|
o=*(t+i);
|
|
*(t+i)=*(t+j);
|
|
*(t+j)=o;
|
|
}
|
|
}
|
|
}
|
|
for(int i=0;i<T;i++)
|
|
{
|
|
for(int j=i;j<T;j++)
|
|
{
|
|
if(strcmp((t+i)->clas,(t+j)->clas)==0&&(t+i)->sum<(t+j)->sum)
|
|
{
|
|
struct student o;
|
|
o=*(t+i);
|
|
*(t+i)=*(t+j);
|
|
*(t+j)=o;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
menu();
|
|
int OS;
|
|
flag1:
|
|
scanf("%d",&OS);
|
|
if(OS==1)
|
|
{
|
|
flag2:
|
|
inputstudent(&s[T]);
|
|
printf("continue?\n");
|
|
char p[10];
|
|
scanf("%s",p);
|
|
if(p[0]=='y')
|
|
{
|
|
goto flag2;
|
|
}
|
|
else
|
|
{
|
|
menu();
|
|
goto flag1;
|
|
}
|
|
}
|
|
if(OS==2)
|
|
{
|
|
flag3:
|
|
deletestudent(&s[0]);
|
|
printf("continue?\n");
|
|
char p2[10];
|
|
scanf("%s",p2);
|
|
if(p2[0]=='y')
|
|
{
|
|
goto flag3;
|
|
}
|
|
else
|
|
{
|
|
menu();
|
|
goto flag1;
|
|
}
|
|
}
|
|
if(OS==3)
|
|
{
|
|
flag4:
|
|
findstudent(&s[0]);
|
|
printf("continue?\n");
|
|
char p3[10];
|
|
scanf("%s",p3);
|
|
if(p3[0]=='y')
|
|
{
|
|
goto flag4;
|
|
}
|
|
else
|
|
{
|
|
menu();
|
|
goto flag1;
|
|
}
|
|
}
|
|
if(OS==4)
|
|
{
|
|
orderstudent(&s[0]);
|
|
printf("\n");
|
|
for(int i=0;i<T;i++)
|
|
outputstudent(&s[i]);
|
|
printf("\n");
|
|
menu();
|
|
goto flag1;
|
|
}
|
|
if(OS==5)
|
|
{
|
|
printf("\n");
|
|
for(int i=0;i<T;i++)
|
|
outputstudent(&s[i]);
|
|
printf("\n");
|
|
menu();
|
|
goto flag1;
|
|
}
|
|
if(OS==6)
|
|
{
|
|
printf("\nquit\n");
|
|
}
|
|
return 0;
|
|
} |