请大佬指点1111111111

某班有最多不超过40名学生参加期末考试,具体人数由键盘输入,考试科目为数学、英语和物理。试编程实现对学生期末考试成绩进行管理。功能和编程要求如下:

(1)用结构体存放每个学生的信息,包括学号、姓名、3门课程的成绩、总分、平均分和排名。

(2)能通过键盘录入学生信息,包括学号、姓名和3门课程的成绩。

(3)能计算每名学生的总分和平均分。

(4)能按总分成绩由高到低排出名次。(总成绩相同的学生之间排序不作具体要求)。

(5)能按总分成绩由高到低输出学生信息,输出信息顺序为:学号、姓名、数学成绩、英语成绩、物理成绩、总分、平均分、排名。

(6)能按学号升序输出学生信息,输出信息顺序与(4)同。

(7)能按姓名升序输出学生信息,输出信息顺序与(4)同。

(8)能根据学号查询并输出某学生的信息,输出信息顺序与(4)同。

(9)能根据姓名查询并输出某学生的信息,输出信息顺序与(4)同。

(10)能输出总成绩最高和最低的学生信息,输出信息顺序与(4)同。

(11)能将学生信息存储到磁盘文件中。

(12)能将学生信息从磁盘文件中读出到程序中。

(13)程序运行后先显示如下菜单,提示用户输入选项完成相应的功能。

 

#include <stdio.h>
#include <stdlib.h>
#define N 30
/**
为 struct students定义了一个新的名字 STU
与 typedef struct students STU 等价
**/
typedef struct students
{
    long id;
    char name[10];
    float score;
}STU;
 
void addscore(STU stu[],int n);
void showscore(STU stu[],int n);
void lowTOhigh(STU stu[],int n);
void highTOlow(STU stu[],int n);
int showlist(void);
int main()
{
    char choose;
    int n;
    STU stu[N];
    printf("你想输入多少名同学的信息:");
    scanf("%d",&n);
    while(1){
        choose=showlist();
        switch(choose)
    {
        case 1:addscore(stu,n);
            break;
        case 2:showscore(stu,n);
            break;
        case 3:highTOlow(stu,n);
               showscore(stu,n);
            break;
        case 4:lowTOhigh(stu,n);
                showscore(stu,n);
            break;
        default:printf("Input error!\n");
 
    }
}
   return 0;
}
 
void addscore(STU stu[],int n){
    int i;
    printf("***请输入学生的学号、姓名和成绩:\n(注意输入一项数据按一下回车键)\n");
    for(i=0;i<n;i++){
        scanf("%ld",&stu[i].id);
        scanf("%s",stu[i].name);
        scanf("%f",&stu[i].score);
    }
}
int showlist(void){
    int choose;
    printf("1.增加学生信息\n");
    printf("2.显示所有学生信息\n");
    printf("3.成绩由高到低排序\n");
    printf("4.成绩由低到高排序\n");
    printf("\n请选择:");
    scanf("%d",&choose);
    return choose;
}
 
void showscore(STU stu[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("%ld%5s%6.1f\n",stu[i].id,
                                stu[i].name,
                                stu[i].score);
    }
}
 
void highTOlow(STU stu[],int n){
    int i,j,k;
    float temp1,temp2;
    for(i=0;i<n-1;i++){
        k=i;
        for(j=i+1;j<n;j++){
            if(stu[j].score>stu[k].score) k=j;
        }
        if(k!=i){
            temp1=stu[k].score;
            stu[k].score=stu[i].score;
            stu[i].score=temp1;
 
            temp2=stu[k].id;
            stu[k].id=stu[i].id;
            stu[i].id=temp2;
        }
    }
}
 
void lowTOhigh(STU stu[],int n){
    int i,j,k;
    float temp1,temp2;
    for(i=0;i<n-1;i++){
        k=i;
        for(j=i+1;j<n;j++){
            if(stu[j].score<stu[k].score) k=j;
        }
        if(k!=i){
            temp1=stu[k].score;
            stu[k].score=stu[i].score;
            stu[i].score=temp1;
 
            temp2=stu[k].id;
            stu[k].id=stu[i].id;
            stu[i].id=temp2;
        }
    }
}