#include <stdio.h>
#define M 50
struct student{
int num;
char name[10];
int chinese,english,math;
int sum;
double average;
};
void new_student(struct student students[]);
void search_student(struct student students[],int num);
void row_student(struct student students[]);
void delete_student(struct student students[],int num);
int count=0;
int main(void)
{
int choice,num,num1;
struct student students[M];
printf("
学生成绩管理系统\n");
printf("
*********************************************************\n");
printf("
*
*\n");
printf("
*
**********************请选择**************************\n");
printf("
*1:输入学生信息
*\n");
printf("
*2:查询成绩
*\n");
printf("
*3:成绩排序
*\n");
printf("
*4:删除成绩
*\n");
printf("
*0:退出系统
*\n");
printf("
*********************************************************\n");
printf("\n");
do{
printf("
*
1:输入
2:查询
3:排序
4:删除
0:退出
*\n");
scanf("%d",&choice);
switch(choice){
case 1:new_student(students);break;
case 2:printf("请输入查询学生的学号num\n");
scanf("%d",&num);
search_student(students,num);
break;
case 3:row_student(students);break;
case 4:printf("请输入要删除学生的学号\n");
scanf("%d",&num1);
delete_student(students,num1);
break;
case 0:break;
}
}while(choice!=0);
printf("结束\n");
return 0;
}
void new_student(struct student students[])
{
struct student s;
if(count==M){
printf("已满\n");
return;
}
printf("请输入第%d个学生学号,姓名,语文,英语,数学成绩:\n",count+1);
scanf("%d%s%d%d%d",&s.num,s.name,&s.chinese,&s.english,&s.math);
s.sum=s.chinese+s.english+s.math;
s.average=s.sum/3.0;
students[count]=s;
count++;
}
void search_student(struct student students[],int num)
{
int i;
for(i=0;i<count;i++)
{
if(students[i].num==num)
{
printf("该学生总分是:%d\n",students[i].sum);
printf("该学生平均分是:%.2f\n",students[i].average);
break;
}
if(i==count-1) printf("无此学生信息\n");
}
}
void row_student(struct student students[])
{
int i,j,index;
struct student temp;
for(i=0;i<count-1;i++)
{
index=i;
for(j=i+1;j<count;j++)
{
if(students[j].sum>students[index].sum)
{
index=j;
temp=students[index];
students[index]=students[i];
students[i]=temp;
}
}
}
printf("成绩排序如下:\n");
printf ("学号
姓名
语文
英语
数学
总分\n");
for(i=0;i<count;i++)
printf("%-8d%-8s%-8d%-8d%-8d%-8d\n",students[i].num,students[i].name,students[i].chinese,students[i].english,students[i].math,students[i].sum);
}
void delete_student(struct student students[],int num)
{
int i;
for(i=0;i<count;i++)
{
if(students[i].num==num)
printf("删除成功\n");
do
{
students[i]=students[i+1];
i++;
}while(i<count-1);
}
[b]}
8)能修改学生信息这个部分不会