#include<stdio.h>
#include<string.h>
#define N 30
struct student
{
int num;
char name[20];
float score[3];
float fountscore;
};
//学员成绩录入函数
void getStudent(struct student *p)
{
int a;
float j=0;
printf("请输入学员信息:/n");
printf("/n学号:");
scanf("%d",&(p->num));
printf("/n姓名:");
fflush(stdin);
gets(p->name);
printf("/n三门成绩:/n");
for(a=0;a<3;a++)
{
printf("成绩%d:",a+1);
scanf("%f",&(p->score[a]));
j+=p->score[a];
}
p->fountscore=(j/3);
}
//学员信息输出
void putStudent(struct student *p)
{
printf("%d/t",p->num);
printf("%s/t",p->name);
printf("%0.1f",p->fountscore);
printf("/n");
}
//学员信息排序,a为信息总数
void orderTemp(struct student p[],int a)
{
struct student temp;
int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<a-i-1;j++)
{
if(p[j].fountscore<p[j+1].fountscore)
{
temp=p[j+1];
p[j+1]=p[j];
p[j]=temp;
}
}
}
}
//插入新学员信息,a为信息总数
void insStudent(struct student p[],int a)
{
getStudent(&p[a]);
// orderTemp(p,a+1);
}
//删除学员信息,b为信息总数
void delStudent(struct student p[],int b)
{
int c,j,a;
printf("请输入你需要删除学生的学号:");
scanf("%d",&a);
for(c=0;c<b;c++)
{
if(p[c].num==a)
{
b--;
for(j=c;j<b;j++)
{
p[j]=p[j+1];
}
break;
}
}
}
void main()
{
int i=0,j;
char ch,k;
struct student stu[N];
printf("欢迎来到学员信息管理系统/n");
while(1)
{
printf("/n1 输入学员信息/n2 显示学员信息/n3 按平均成绩排序/n4 插入学员信息/n5 删除学员信息/n0 退出/n/n");
printf("请选择:");
fflush(stdin);
k=getchar();
printf("/n");
if(k<='5'&&k>='0')
{
if(k<='5'&&k>='1')
{
switch (k)
{
case '1':
{
while(1)
{
getStudent(&stu[ i ]);
i++;
printf(" 是否继续?<y or n>");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y')
{
continue;
}
else
{
break;
}
}
break;
}
case '2':
{
if(i>0)
{
printf("学号/t姓名/t平均成绩/n");
for(j=0;j<i;j++)
{
putStudent(&stu[j]);
}
break;
}
else
{
printf("现在没有学员信息!请先输入学员信息!/n");
break;
}
}
case '3':
{
if(i!=0)
{
orderTemp(stu,i);
printf("排序完成!/n");
break;
}
else
{
printf("现在还没有学员信息!请先输入学员信息!/n");
break;
}
}
case '4':
{
while(1)
{
insStudent(stu,i);
i++;
printf(" 是否继续?<y or n>");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y')
{
continue;
}
else
{
break;
}
}
break;
}
case '5':
{
if(i>0)
{
while(1)
{
delStudent(stu,i);
i--;
if(i>0)
{
printf(" 是否继续?<y or n>");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y')
{
continue;
}
else
{
break;
}
}
else
{
break;
}
}
break;
}
else
{
printf("现在还没有学员信息!请先输入学员信息!/n");
break;
}
}
}
}
else
{
break;
}
}
else
{
printf("您的输入错误,请重新输入!/n/n");
continue;
}
}
}