##水平有限,仅供参考
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 200
void input(char name[][20],double score[],int id[],int n)
{
int i;
for(i=0;i<n;i++)
{
getchar();
printf("请输入第%d个学生姓名:\n",i+1);
gets(name[i]);
printf("请输入第%d个学生学号:\n",i+1);
scanf("%d",&id[i]);
printf("请输入第%d个学生成绩:\n",i+1);
scanf("%lf",&score[i]);
}
}
void show(char name[][20],double score[],int id[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("姓名:%10s 学号:%10d 成绩:%5.3lf\n",name[i],id[i],score[i]);
}
}
void search(char name[][20],double score[],int id[],int n)
{
char ss[20];
int i,x=0;
printf("请输入搜索姓名:\n");
getchar();
gets(ss);
for(i=0;i<n;i++)
{
if(strcmp(name[i],ss)==0)
{
printf("姓名:%10s 学号:%10d 成绩:%5.2lf\n",name[i],id[i],score[i]);
x=1;
}
}
if(x==0)
printf("查询无结果!\n");
}
void sort(char name[][20],double score[],int id[],int n)
{
int i,j,t,a[n],m;
for(i=0;i<n;i++)
a[i]=i;
for(j=0,m=0;j<n;j++,m++)
{
for(i=0;i<n-1-j;i++)
{
if(score[i]>score[i+1])
{t=score[i];score[i]=score[i+1];score[i+1]=t;t=a[i];a[i]=a[i+1];a[i+1]=t;}
}
}
for(j=0;j<n;j++)
printf("姓名:%s\t 学号:%d\t成绩:%.2lf\n",name[a[j]],id[a[j]],score[j]);
}
void tongji(double score[],int n)
{
int i,t;
for(i=0;i<n-1;i++)
{
if(score[i]>score[i])
{t=score[i];score[i]=score[i+1];score[i]=t;}
}
printf("最高成绩为:%.2lf\n",score[n-1]);
for(i=n-1;i>0;i--)
if(score[i]<score[i-1])
{t=score[i];score[i]=score[i-1];score[i-1]=t;}
printf("最低成绩为: %.2lf\n",score[0]);
}
int main()
{
int id[N],n,ord=1;
char name[N][20];
double score[N];
while(ord!=0)
{
printf("---------------学生成绩信息管理---------------\n");
printf("1.录入 2.显示 3.查找 4.排序 5.统计 0.退出\n");
printf("----------------------------------------------\n");
printf("请输入选择项:");
scanf("%d",&ord);
switch(ord)
{
case 1:printf("请输入学生个数n\n");scanf("%d",&n);input(name,score,id,n);break;
case 2:show(name,score,id,n);break;
case 3:search(name,score,id,n);break;
case 4:sort(name,score,id,n);break;
case 5:tongji(score,n);break;
case 0:;break;
}
system("pause");
system("cls");
}
return 0;
}
}