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

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


#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

#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
    vector<float> a{istream_iterator<float>(cin), istream_iterator<float>()};
    cout << "max: " << *max_element(a.begin(), a.end()) << '\n'
         << "min: " << *min_element(a.begin(), a.end()) << '\n'
         << "avg: " << accumulate(a.begin(), a.end(), 0.0) / a.size() << '\n';
    return 0;
}

可以使用结构体吧
struct{

};