该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
# include
# include
# include
# include
# include
struct student
{
int no;
char name[20];
float score[2];
float avg;
};
struct student input( );
void display(struct student[],int);
void sort(struct student[],int );
int find(struct student[],int ,int );
void query(struct student[],int );
void update(struct student[],int);
void remove1(struct student[],int *);
void main()
{
struct student stu[20];
int count =0;
char sel='1',flag;
while(sel!='7')
{
system("cls");
printf("\t_________________学员信息管理系统______________________\n\n");
printf("\t1.录入\t2.显示\t3.排序\t4.查询\t5.修改\t6.删除\t7.退除\t\n");
printf("\t_______________________________________________________\n\n");
printf("\t\t\t欢迎你使用学员信息管理系统\n");
printf("\n\t\t\t\t\t\t\t\t设计员/追梦\n");
printf("\n请选择你要的操作 ");
sel=getchar();
switch(sel)
{
case '1':
system("cls");
do
{
stu[count]=input();
count++;
printf("'是否继续输入(y/n):");
fflush(stdin);
flag=getchar();
}while(flag=='y'||flag=='Y');
break;
case '2':
display(stu,count);
break;
case '3':
sort(stu,count);
break;
case '4':
query(stu,count);
break;
case '5':
update(stu,count);
break;
case '6':
remove1(stu,&count);
break;
}
}
getch();
}
/*单个学员信息录入*/
struct student input()
{
struct student stu;
float sum;
char k=0;
int j;
char ch[20];
do{
printf("\n请输入学号:");
scanf("%s",ch);
k=0;
stu.no=0;
for(j = strlen(ch)-1;j>=0;j--)
{
if(ch[j]'9')
{
k=1; break;
}
stu.no+=(ch[j]-48)*pow(10,j);
}
/*printf("请输入数字\n"); */
}while(k==1);
printf("\n请输入姓名:");
scanf("%s",&stu.name);
printf("\n请输入两门成绩:\n");
sum=0;
for(j=0;j<2;j++)
{
printf("成绩%d:",j+1);
scanf("%f",&stu.score[j]);
sum=sum+stu.score[j];
}
stu.avg=sum/2.0;
return stu;
}
/*显示所有学员信息*/
void display (struct student stud[],int count)
{
int i;
system("cls");
printf("\t\n%-8s %-12s %-12s %-12s %-12s\n","学 号","姓 名","成绩一","成 绩二","平均成绩");
printf("\t\n%-8s %-12s %-12s %-12s %-12s\n","______","_______","_______","______","_________");
for(i=0;i
{
printf("%-12d",stud[i].no);
printf("%-12s",stud[i].name);
printf("%-12.2f",stud[i].score[0]);
printf("%-12.2f",stud[i].score[1]);
printf("%-.2f\n",stud[i].avg);
printf("\n");
}
printf("\n按任意键返回主菜单:");
getch();
}
/*排序*/
void sort(struct student stud[],int count)
{
struct student t;
int i,j;
for(i=0;i
{
for(j=count-1;j>i;j--)
{
if(stud[j].avg>stud[j-1].avg)
{
t=stud[j];
stud[j]=stud[j-1];
stud[j-1]=t;
}
}
}
system("cls");
printf("\n排序已经完成,按任意键返返回主菜单:");
getch();
}
/*根据学号查找学员信息函数,找到返回该学员在数组中的上标,没找到返回*/
int find (struct student stud[],int count ,int no)
{
int i;
for(i=0;i
{
if(stud[i].no==no)
{
return i;
}
}
return -1;
}
/*根据学号查询并显示学员信息*/
void query(struct student stud[],int count)
{
int dno,i;
system("cls");
printf("\n主输入要查询的学员的学号:");
scanf("%d",&dno);
i=find(stud,count,dno);
if(i==-1)
{
printf("\n你所要查询的学员不存在!按任意键返回主菜单:");
getch();
return;
}
printf("\n%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("\n%-8s%-12s%-12s%-12s%s\n","____","______","_______","______","_______","___________","_____________");
printf("%-8d",stud[i].no);
printf("%-12s",stud[i].name);
printf("%-12.2f",stud[i].score[0]);
printf("%-12.2f",stud[i].score[1]);
printf("%-.2f",stud[i].avg);
printf("\n");
printf("\n按任意键返回主菜单:");
getch();
}
/*修改学员信息*/
void update(struct student stud[],int count)
{
int dno,i;
system("cls");
printf("\n请输入要修改的学员的学号:");
scanf("%d",&dno);
i=find(stud,count,dno);
if(i==-1)
{
printf("\n你所要查询的学员不存在!按任意键返回主菜单:");
getch();
return;
}
stud[i]=input();
printf("\n修改成功!按任意键返回主菜单:");
getch();
}
/*删除学员信息 */
void remove1(struct student stud[],int *count)
{
int dno,i,j;
system("cls");
printf("\n请输入要删除的学员的学号:");
scanf("%d",&dno);
i=find(stud,*count,dno);
if(i==-1)
{
printf("\n你所要查询的学员不存在!按任意键返回主菜单:");
getch();
return;
}
for(j=i;j
{
stud[j]=stud[j+1];
}
(*count)--;
printf("/n删除成功!按任意我键返回主菜单:");
}