m0_63946564 2022-03-07 10:27 采纳率: 100%
浏览 195
已结题

求解基于结构体数组的学生成绩管理系统

(1)输入5个学生3门课的成绩存入结构体数组中;(2)输出学生信息;(3)求每门课最高分所对应的学生。(4)输入一个学号num,查找其学号等于num的学生。要求:用结构体数组存放学生信息,每个功能都用函数实现。

  • 写回答

4条回答 默认 最新

  • 关注

    代码如下:

    #include <stdio.h>
    struct student 
    {
        int id;
        char name[20];
        float score[3];
        float ave;
    };
    //从键盘录入5个学生的成绩
    void input(struct student stu[])
    {
        int i;
        printf("录入5名学生3门课的成绩:\n");
        for (i=0;i<5;i++)
        {
            printf("请输入学生%d的学号、姓名、3门课成绩:",i+1);
            scanf("%d %s %f %f %f",&stu[i].id,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
            stu[i].ave = (stu[i].score[0] + stu[i].score[1]+stu[i].score[2])/3.0;
        }
    }
    
    //输出学生信息
    void show(struct student stu[],int n)
    {
        int i=0;
        for (;i<n;i++)
        {
            printf("%d\t%s\t%f\t%f\t%f\n",stu[i].id,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
        }
    }
    
    //求每门课成绩最高的学生信息
    void showMax(struct student stu[],int n)
    {
        int i,j;
        int max=0;
        for (i=0;i<3;i++)
        {
            printf("第%d门成绩最高的学生信息:",i+1);
            max = 0;
            for (j=0;j<n;j++)
            {
                if(stu[j].score[i] > stu[max].score[i])
                    max = j;
            }
            printf("%d\t%s\t%f\t%f\t%f\n",stu[max].id,stu[max].name,stu[max].score[0],stu[max].score[1],stu[max].score[2]);
        }
    }
    
    
    
    
    //根据学号查找
    void search(struct student stu[],int n)
    {
        int i,j;
        int num;
        printf("请输入需要查询的学生学号:");
        scanf("%d",&num);
        for (i=0;i<n;i++)
        {
            if (stu[i].id == num)
            {
                printf("%d\t%s\t%f\t%f\t%f\n",stu[i].id,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
                break;
            }
        }
    
    }
    int main()
    {
        int op;
        struct student stu[5];
    
        input(stu);
        show(stu,5);
        showMax(stu,5);
        search(stu,5);
        
        return 0;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 3月15日
  • 已采纳回答 3月7日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答