学生成绩管理系统
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define N 100
int n;
struct student
{int num;
char name[20];
int math;
int english;
int average;
}stu[N],stu1[N],stu2[N],stu3[N];
void input(int i)
{int t;
if(i>N) printf("不存在的学生");
scanf("%d,%s,%d,%d",&stu[i].num,&stu[i].name,&stu[i].math,&stu[i].english);
stu[i].average=(stu[i].math+stu[i].english)/2;
}
void luru()//录入
{int i;
printf("输入录入成绩的学生数目");
scanf("%d",&n);
for(i=1;i<=n;i++)
{printf("input %dth student record",i);
input(i);}
}
void print()
{int i;
for(i=1;i<=n;i++)
printf("%10d,%10.1s,%10d,%10d,%10d\n",stu[i].num,stu[i].name,stu[i].math,stu[i].english,stu[i].average);
}
void print1()
{int i;
for(i=1;i<=n;i++)
printf("%10d,%10.1s,%10d,%10d,%10d\n",stu1[i].num,stu1[i].name,stu1[i].math,stu1[i].english,stu1[i].average);
}
void print2()
{int i;
for(i=1;i<=n;i++)
printf("%10d,%10.1s,%10d,%10d,%10d\n",stu2[i].num,stu2[i].name,stu2[i].math,stu2[i].english,stu2[i].average);
}
void print3()
{int i;
for(i=1;i<=n;i++)
printf("%10d,%10.1s,%10d,%10d,%10d\n",stu3[i].num,stu3[i].name,stu3[i].math,stu3[i].english,stu3[i].average);
}
int partition(int low,int high)//快速排序
{int i;
stu[0]=stu[low];
i=stu[low].average ;
while(low<high)
{while(low<high&&stu[high].average>=i)
--high;
stu[low]=stu[high];
while(low<high&&stu[low].average<=i)
++low;
stu[high]=stu[low];}
stu[low]=stu[0];
return low;}
void qsort(int low,int high)
{if(low<high)
{int pivotloc=partition (low,high);
qsort(low,pivotloc-1);
qsort(pivotloc+1,high);
}}
void add()//添加
{int m,i,j;
j=N-1-n;
printf("你想增加多少学生?");
scanf("%d",&m);
if(m>j)
printf("超过一个系规定的学生数目,将不能接纳所有学生");
for(i=n+1;i<=m+n;i++)
input(i);
n=m+n;}
void paixu2()
{int i,j,k;
for(i=1;i<N;i++)
{stu[0]=stu[i];
for(j=i;j>0;)
if(stu[i].average <stu[j].average )
j--;
else
{for(k=i-1;k>0;k--)
if(stu[k].average <stu[i].average )
stu[k+1]=stu[k];
stu[k+1]=stu[i];}}}
void del()//删除
{int i,j,k;
printf("输入退学的学生学号");
scanf("%d",&j);
for(i=1;i<=n;i++)
if(stu[i].num==j)
for(k=i+1;k<=n;k++)
stu[k-1]=stu[k];
n--;}
int xiugai(int i,int m,int t)//修改
{int j;
for(j=1;j<=n;j++)
if(stu[j].num ==i)
{stu[j].math =m;
stu[j].english =t;
stu[j].average =(m+t)/2;
break;}
return j;
}
void paixu3(int i)
{int j,k;
stu[0]=stu[i];
for(j=i+1;j<=n;j++)
stu[j-1]=stu[j];
for(j=1;j<n;j++)
if(stu[j].average<stu[0].average)
for(k=n-1;k>=j;k--)
stu[k+1]=stu[k];
stu[j]=stu[0];}
void tongji(int a,int b)//统计
{
int i,j=0,k=0,p=0;
if(a==0&&b==0)
print();
else if(a==0&&b>0)
{for(i=1;i<n;i++)
if(stu[i].english>=b)
stu1[j++]=stu[i];
print1();
}
else if(b==0&&a>0)
{for(i=1;i<n;i++)
if(stu[i].math >=a)
stu2[k++]=stu[i];
print2();
}
else
{for(i=1;i<n;i++)
if(stu[i].math >=a&&stu[i].english>=b)
stu3[p++]=stu[i];
print3();
}
}
void search(int t)//搜索
{int i;
for(i=1;i<n;i++)
if(stu[i].num ==t)
printf("名次:");
printf("%10d,%10.1s,%10d,%10d,%10d",stu[i].num,stu[i].name,stu[i].math,stu[i].english,stu[i].average);
}
void main()
{int i;
luru();
qsort(1,n);
print();
add();
paixu2();
print();
del();
print();
i=xiugai(101,70,80);
paixu3(i);
print();
tongji(70,70);
search(101);
}