#include<iostream>
using namespace std;
class Student
{public:
Student(int i,int s):id(i),score(s){}
friend void max(Student *);
private:
int id,score;
};
void max(Student *p)
{
Student *x;
int i,temp;
temp=p->score;
for(i=0;i<5;i++)
{
if(temp<(p+i)->score)
{
temp=(p+i)->score;
x=(p+i);
}
}
cout<<"成绩最高者的学号为: "<<x->id<<endl;
}
int main()
{
Student stu[5]={Student(1001,96),Student(1002,82),Student(1003,69),Student(1004,98),Student(1005,100)};
Student *p=stu;
max(p);
return 0;
}
运行结果: