parent
e53481fccb
commit
9d53e36f33
@ -0,0 +1,162 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
struct Student
|
||||
{
|
||||
char id[20];
|
||||
char Class[20];
|
||||
char name[50];
|
||||
float gs;
|
||||
float dw;
|
||||
float yy;
|
||||
float all;
|
||||
};
|
||||
struct Student stu[20];
|
||||
int n=0;
|
||||
void menu()
|
||||
{
|
||||
printf("1.input\n");
|
||||
printf("2.delect\n");
|
||||
printf("3.select\n");
|
||||
printf("4.order\n");
|
||||
printf("5.output\n");
|
||||
printf("6.quit\n");
|
||||
printf("please input your optition\n");
|
||||
}
|
||||
void print()
|
||||
{
|
||||
int i=0;
|
||||
for(i;i<n;i++)
|
||||
{
|
||||
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].id,stu[i].Class,stu[i].name,stu[i].gs,stu[i].dw,stu[i].yy,stu[i].all);
|
||||
}
|
||||
}
|
||||
void input()//
|
||||
{
|
||||
char ch[20];//chioce选择是否进行继续input操作
|
||||
int i=1;
|
||||
while(i=1)
|
||||
{
|
||||
printf("Id:");
|
||||
scanf("%s",&stu[n].id);
|
||||
printf("Class:");
|
||||
scanf("%s",&stu[n].Class);
|
||||
printf("Name:");
|
||||
scanf("%s",&stu[n].name);
|
||||
printf("score1:");
|
||||
scanf("%f",&stu[n].gs);
|
||||
printf("score2:");
|
||||
scanf("%f",&stu[n].dw);
|
||||
printf("score3:");
|
||||
scanf("%f",&stu[n].yy);
|
||||
n++;
|
||||
printf("continue?\n");
|
||||
scanf("%s",ch);
|
||||
if(strcmp(ch,"no")==0)
|
||||
{
|
||||
i=0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
i=1;
|
||||
ch[20]='\0';//将choice数组中的字符清零以便进行下一次的判断
|
||||
}
|
||||
}
|
||||
}
|
||||
void del()
|
||||
{
|
||||
int i,d;
|
||||
char key[20],op[20];
|
||||
while(1)
|
||||
{
|
||||
i=0,d=0;
|
||||
scanf("%s",key);
|
||||
while(i<n)
|
||||
{
|
||||
if(strcmp((stu+i)->id,key)==0||strcmp((stu+i)->name,key)==0)
|
||||
{
|
||||
d++;n--;
|
||||
*(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,j;
|
||||
char key[20],op[20];
|
||||
while(1)
|
||||
{
|
||||
j=0;
|
||||
scanf("%s",key);
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if(strcmp((stu+i)->id,key)==0||strcmp((stu+i)->Class,key)==0)
|
||||
{
|
||||
j=1;
|
||||
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].id,stu[i].Class,stu[i].name,stu[i].gs,stu[i].dw,stu[i].yy,stu[i].all);
|
||||
}
|
||||
}
|
||||
if(j==0)
|
||||
{
|
||||
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 Student swap;
|
||||
for(i=0;i<n;i++)//对班级排序
|
||||
{
|
||||
for(j=0;j<n-i-1;j++)
|
||||
{
|
||||
if(strcmp((stu+j)->Class,(stu+j+1)->Class)==1||(strcmp((stu+j)->Class,(stu+j+1)->Class)==0)&&stu[j].all<stu[j].all)
|
||||
{
|
||||
swap=*(stu+j);
|
||||
*(stu+j)=*(stu+j+1);
|
||||
*(stu+j+1)=swap;
|
||||
}
|
||||
}
|
||||
}
|
||||
print();
|
||||
return ;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int choice;
|
||||
while(1)
|
||||
{
|
||||
menu();
|
||||
scanf("%d",&choice);
|
||||
switch(choice)
|
||||
{
|
||||
case 1:input();break;
|
||||
case 2:del();break;
|
||||
case 3:select();break;
|
||||
case 4:order();break;
|
||||
case 5:print();break;
|
||||
case 6:return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue