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

发布时间 2023-03-22 21:14:16作者: 悟空+

#include <iostream>
using namespace std;
class Student
{
public:
void max(int *p,float *t);
};
void Student::max(int *p,float *t)
{
int i;
int a=0, b;
for (i = 0; i < 5; i++)
{
cin >> *(p + i);
cin >> *(t + i);
if (*(t + 1) > a) { a = *(t + i); b = *(p + i); }
}
cout << b << " " << a;
}
int main()
{
Student t1;
int a[10];
float b[10];
t1.max(a,b);
return 0;
}