m0_67499995 2022-03-01 17:40 采纳率: 100%
浏览 45
已结题

c++程序编写:输入学生成绩;统计最高分数;统计最低分数及平均成绩 程序怎么写啊越简单越好 c++

c++程序编写:输入学生成绩;统计最高分数;统计最低分数及平均成绩 程序怎么写啊越简单越好
c++

  • 写回答

3条回答 默认 最新

  • 不爱熬夜的Coder 成都裕泰晟通科技有限公司官方账号 2022-03-01 17:51
    关注
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
        vector<float> scores = {99.5, 78.5, 67.5, 56.5, 45.5, 84.5, 83.5, 72.5, 91.5, 90.5};
    
        float sum = 0, avg = 0, max = 0, min = 100;
    
        sort(scores.begin(), scores.end());
        max = scores[scores.size() - 1];
        min = scores[0];
    
        for (auto score : scores)
        {
            sum += score;
        }
    
        avg = sum / scores.size();
    
        cout << "The average score is: " << avg << endl;
        cout << "The highest score is: " << max << endl;
        cout << "The lowest score is: " << min << endl;
        cout << "The scores are: ";
        for (auto score : scores)
        {
            cout << score << " ";
        }
        cout << endl;
    }
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月13日
  • 已采纳回答 3月5日
  • 创建了问题 3月1日