问题描述
- 给一段简单的编程加结构体
- #include
#includeint ijxttn=-1f[100]={0};
float a1[100]a2[100]a3[100]a[100]t;
char num[100][5]cla[100][5]name[100][11]
x1[100]=""yes""x2[100]=""yes""x3[100]=""yes""temp[100];void menu();
void input();
void inputonce();
void delete();
void deleteonce();
void select();
void selectonce();
void order();
void swap(intint);
void output();int main()
{
menu();
return 0;
}void menu()
{
printf(""1.inputn"");
printf(""2.deleten"");
printf(""3.selectn"");
printf(""4.ordern"");
printf(""5.outputn"");
printf(""6.quitn"");
printf(""please input your optionn"");
scanf(""%d""&x); getchar();
switch(x)
{
case 1:input(); break;
case 2:delete(); break;
case 3:select(); break;
case 4:order(); break;
case 5:output(); menu(); break;
case 6:return;
}}
void input()
{
while (strcmp(x1no"")!=0) inputonce();
menu();
}void inputonce()
{
n++;
printf(""Id "");
gets(num[n]);
printf(""class "");
gets(cla[n]);
printf(""name "");
gets(name[n]);
printf(""score1 "");
scanf(""%f""&a1[n]); getchar();
printf(""score2 "");
scanf(""%f""&a2[n]); getchar();
printf(""score3 "");
scanf(""%f""&a3[n]); getchar();
a[n]=a1[n]+a2[n]+a3[n];
printf(""continue?n"");
gets(x1);
}void delete()
{
while (strcmp(x2no"")!=0) deleteonce();
menu();}
void deleteonce()
{
gets(temp);
for (i=0;i<=n;i++)
if ((strcmp(num[i]temp)==0)||(strcmp(name[i]temp)==0))
f[i]=1;
output();
printf(""continue?n"");
gets(x2);
}void select()
{
while (strcmp(x3no"")!=0) selectonce();
menu();
}void selectonce()
{
gets(temp);
for (i=0;i<=n;i++)
if (((strcmp(num[i]temp)==0)||(strcmp(cla[i]temp)==0))&&(f[i]==0))
printf(""%s%s%s%4.1f%4.1f%4.1f%5.1fn""num[i]cla[i]name[i]a1[i]a2[i]a3[i]a[i]);
printf(""continue?n"");
gets(x3);
}void order()
{
for (i=0;i for (j=i+1;j if ((strcmp(cla[i]cla[j])>0) || ((strcmp(cla[i]cla[j])==0) && (a[i]<a[j])))
swap(ij);
output();
menu();
}void swap(int iint j)
{
strcpy(tempnum[i]);
strcpy(num[i]num[j]);
strcpy(num[j]temp);strcpy(tempname[i]);strcpy(name[i]name[j]);strcpy(name[j]temp);strcpy(tempcla[i]);strcpy(cla[i]cla[j]);strcpy(cla[j]temp);t=a[i];a[i]=a[j];a[j]=t;t=a1[i];a1[i]=a1[j];a1[j]=t;t=a2[i];a2[i]=a2[j];a2[j]=t;t=a3[i];a3[i]=a3[j];a3[j]=t;tt=f[i];f[i]=f[j];f[j]=tt;
}
void output()
{
for (i=0;i<=n;i++)
if (f[i]==0)
printf(""%s%s%s%4.1f%4.1f%4.1f%5.1fn""num[i]cla[i]name[i]a1[i]a2[i]a3[i]a[i]);
}