C++对象数组并用上指针

如何建立一个对象数组,内放5个学生的数据(学号、成绩),设立一个函数max ,用指向对象的指针作函数参数,在 max 函数中找出5个学生中成绩最高者,并输出其学号?

img


#include <iostream>

using namespace std;

class student
{
public:
    int xh;
    int value;
};



int max(student* st) {

    int tmax = st->value;
    int th = st->xh;
    for (int i = 1; i < 5; i++)
    {
        if (tmax<st[i].value)
        {
            tmax = st[i].value;
            th = st[i].xh;
        }
    }
    return th;
}

int main() {
    student* s=new student[5];
    s[0].value = 70;
    s[0].xh = 104;
    s[1].value = 10;
    s[1].xh = 100;
    s[2].value = 91;
    s[2].xh = 101;
    s[3].value = 78;
    s[3].xh = 102;
    s[4].value = 66;
    s[4].xh = 103;

    cout<<"最高分学生学号是:"<<max(s);
}

void fenshu[5]