C++问题 定义一个结构体学生,有三个成员:学号,姓名name和成绩score,定义如下

定义一个结构体学生,有三个成员:学号,姓名name和成绩score,定义如下:

struct STUDENT
 {   int  no;  //学号
     string  name;  //姓名
     int  score;    //成绩
 };

在主函数中创建一个有5个元素的结构数组,输出其中成绩最高的学生的姓名。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

直接参考一下代码:

#include <iostream>
#include <string>
using namespace std;

struct STUDENT
{
    int no;  //学号
    string name;  //姓名
    int score;    //成绩
};

int main()
{
    STUDENT student[5] = {
        {1, "A", 88},
        {2, "B", 99},
        {3, "C", 88},
        {4, "D", 98},
        {5, "E", 68}
    };
    int maxScore = 0;
    string maxName;
    for (int i=0; i<5; i++)
    {
        if (student[i].score > maxScore)
        {
            maxScore = student[i].score;
            maxName = student[i].name;
        }
    }
    cout << "The highest score student is " << maxName << endl;

    return 0;
}