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.

162 lines
3.2 KiB

#include <stdio.h>
#include <string.h>
struct stu {
char num[6];
char class[3];
char name[6];
float grade1;
float grade2;
float grade3;
float grade;
}s[10],ss;
int main()
{
int bb=0;
while(1)
{
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 intput your option\n");
int input;
scanf("%d",&input);
if(input==1)
{
char ch[6];
int i=0;
while(1)
{
printf("Id ");
scanf("%s",s[i].num);
printf("class ");
scanf("%s",s[i].class);
printf("name ");
scanf("%s",s[i].name);
printf("score1 ");
scanf("%f",&s[i].grade1);
printf("score2 ");
scanf("%f",&s[i].grade2);
printf("score3 ");
scanf("%f",&s[i].grade3);
printf("continue?\n");
i++;
for(int j=0;j<i;j++)
{
s[i].grade=s[i].grade1+s[i].grade2+s[i].grade3;
}
scanf("%s",ch);
if(strcmp(ch,"no")==0)
break;
}
}
else if(input==2)
{
bb=1;
char de[6];
while(1)
{
scanf("%s",de);
for(int i=0;i<3;i++)
{
if(strcmp(s[i].num,de)==0&&i<2)
{
for(int j=i;j<2;j++)
s[j]=s[j+1];
}
}
for(int i=0;i<2;i++)
{
printf("%s %s %s %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3);
}
printf("continue?\n");
char ch[6];
scanf("%s",ch);
if(strcmp(ch,"no")==0)
break;
}
}
else if(input==3)
{
char in[6];
int aa=0;
while(1)
{
scanf("%s",in);
for(int i=0;i<2;i++)
{
if(strcmp(in,s[i].num)==0||strcmp(in,s[i].class)==0)
{
printf("%s %s %s %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3);
aa=1;
}
}
if(aa==0)
printf(" there is no eligible student");
printf("continue?\n");
char ch[6];
scanf("%s",ch);
if(strcmp(ch,"no")==0)
break;
}
}
else if(input==4)
{
if(bb==0)
{
strcpy(s[0].num,"10001");strcpy(s[0].class,"11");strcpy(s[0].name,"zhang");s[0].grade1=99.5;s[0].grade2=88.5;s[0].grade3=89.5;s[0].grade=277.5;
strcpy(s[2].num,"10003");strcpy(s[2].class,"11");strcpy(s[2].name,"wang");s[2].grade1=92.5;s[2].grade2=99.0;s[2].grade3=60.5;s[2].grade=252.0;
strcpy(s[1].num,"10002");strcpy(s[1].class,"22");strcpy(s[1].name,"li");s[1].grade1=77.9;s[1].grade2=56.5;s[1].grade3=87.5;s[1].grade=221.9;
for(int i=0;i<2;i++)
{
for(int j=i+1;j<3;j++)
{
if(strcmp(s[i].class,s[j].class)>0)
{
ss=s[i];
s[i]=s[j];
s[j]=ss;
}
}
}
for(int i=0;i<1;i++)
{
for(int j=i+1;j<2;j++)
{
if(s[i].grade<s[j].grade)
{
ss=s[i];
s[i]=s[j];
s[j]=ss;
}
}
}
}
}
else if(input==5)
{
if(bb=0)
{
for(int i=0;i<4;i++)
{
printf("%s %s %s %.1f %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3,s[i].grade);
}
}
else
{
for(int i=0;i<2;i++)
{
printf("%s %s %s %.1f %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3,s[i].grade);
}
}
}
else if(input==6)
break;
}
return 0;
}