C语言实现学生成绩管理系统

C语言实现学生成绩管理系统V1.0

某班有最多不超过30人(具体人数由键盘输入),参加某门课程的考试,实现如下学生成绩管理:

  1. 录入每个学生的学号和考试成绩
  2. 计算课程的总分和平均分
  3. 按成绩由高到低排出名次表
  4. 按学号由小到大排出成绩表
  5. 按学号查询学生排名及其考试成绩
  6. 按优秀(90-100),良好(80-89),中等(70-79),及格(60-69),不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比

接下来直上代码

#include 
#include 
#define N 30
void Readscore(int id[],int score[],int n);
int Average(int score[],int n);
void Scoresort(int id[],int score[],int n);
void Idsort(int id[],int score[],int n);
int Selectsort(int id[],int score[],int n,int x);
void Scoreclass(int score[],int n);
void Showinfo(int id[],int score[],int n);
int main()
{
  int num,score[N],aver,n,sum,id[N],i,m,x,k,great=0,better=0,middle=0,low=0,lower=0;


while(1){
//首页选择
    printf("----------------\n");
    printf("1.Input record\n");
    printf("2.Caculate total and average score of course\n");
    printf("3.Sort in descending order by score\n");
    printf("4.Sort in ascending order by number\n");
    printf("5.Search by number\n");
    printf("6.Sta1tistic analysis\n");
    printf("7.List record\n");
    printf("0.Exit\n");
    printf("Please enter your choice\n");
    scanf("%d",&num);
//用户输入功能

    switch(num){
        case 0:

            break;
        case 1:
            printf("Input n:\n");
            scanf("%d",&n);
            Readscore(id,score,n);
            break;

        case 2:
            sum=Average(score,n);
            printf("Sum score is %d\n",sum);
            printf("Average score is %d\n",sum/n);
            break;
        case 3:
            Scoresort(id,score,n);
            for(i=0;i<=n-1;i++){
                printf("%3d%5d\n",id[i],score[i]);
            }
            break;
        case 4:
            Idsort(id,score,n);
            for(i=0;i<=n-1;i++){
                printf("%3d%5d\n",id[i],score[i]);
            }
            break;
        case 5:
            printf("Input id:\n");
            scanf("%d",&x);
            m=Selectsort(id,score,n,x);
            if(m==-1){
                printf("查询错误\n");
            }else{
                printf("----------------\n");
                printf("id:%3d score:%3d 排名:%3d\n",id[m],score[m],m+1);
            }
            break;
        case 6:
            Scoreclass(score,n);
            break;
        case 7:
            Showinfo(id,score,n);
            sum=Average(score,n);
            printf("----------------\n");
            printf("Sum score is %d\n",sum);
            printf("Average score is %d\n",sum/n);
            break;


        default:
            printf("Invalid operator\n");




  }
}
}
//输出分数段
void Scoreclass(int score[],int n){

    int i,j,count,k;
    double bate,m;
    m=n;
    int begin[5]={0,60,70,80,90};
    int end[5]={59,69,79,89,100};
    char* class[5]={"不及格","及格","中等","良好","优秀"};

    for(i=0,j=0;i<=n,j<5;i++,j++){
            count =0;
            bate=0;
       for(k=0;kif((begin[i]<=score[k])&&(end[i]>=score[k])){
             count+=1;
             bate=(100*count)/m;
          }

       }

       printf("%s的学生人数为:%d ,所占百分比为%.2f\n",class[j],count,bate/100);

    }

}
//输出每个学生的学号和成绩
void Showinfo(int id[],int score[],int n){
    int i;
    for(i=0;i<=n-1;i++){
        printf("id:%3d score:%3d\n",id[i],score[i]);
    }
}
//根据学号查询学生成绩
int Selectsort(int id[],int score[],int n,int x){
    int temp_score,i,j,temp_id,k;
    for(i=0;i1;i++){
        for(j=i+1;jif(score[i]for(k=0;kif(id[k]==x)
            return k;

    }return -1;




}
//根据学号从小到大打印成绩
void Idsort(int id[],int score[],int n){
    int temp_score,i,j,temp_id;
    for(i=0;i1;i++){
        for(j=i+1;jif(id[i]>id[j]){
                    temp_score = score[i];
                    score[i]=score[j];
                    score[j]=temp_score;
                    temp_id=id[i];
                    id[i]=id[j];
                    id[j]=temp_id;
            }
        }
    }


}
//从高到低打印成绩
void Scoresort(int id[],int score[],int n){
    int temp_score,i,j,temp_id;
    for(i=0;i1;i++){
        for(j=i+1;jif(score[i]//计算班级平均分
int Average(int score[],int n){
    int i,sum=0;
    for(i=0;ireturn sum;
}
//录入学生成绩
void Readscore(int id[],int score[],int n){


    int i;
    for(i=0;iprintf("Input student's id and score:");
        scanf("%d %d",&id[i],&score[i]);
        if(score[i]<0){
            printf("成绩输入错误\n");
            return 0;
        }
    }

}


这里写图片描述
扫码关注作者个人技术公众号,有关技术问题后台回复即可,不定期将有学习资源分享

你可能感兴趣的:(C语言)