#include<iostream>
using namespace std;
class Student{
public:
Student(int i,int s)
{id=i;
score=s;
}
private:
int id;
int score;
friend void max(Student *p);
};
void max(Student *p)
{int b,i,x;
b=p[0].score;
for(i=0;i<6;i++)
{if(b<p[i].score)
b=p[i].score;
x=i;
}
cout<<"The id is:"<<p[x].id<<endl;
}
int main()
{Student stu[6]={Student(1,91),Student(2,92),Student(3,93),Student(4,94),Student(5,95),Student(6,96)};
max(stu);
return 0;
}
程序运行结果如下: