#include <iostream>
using namespace std;
class Student
{public:
Student(int n,int s):num(n),score(s){}
void max();
private:
int num;
int score;
};
void Student::max(Student *p)
{
int max_score=p[0].score;
int k=0;
for(int i=0;i<5;i++)
{
if(p[i].score>max_score)
{
max_score=p[i].score;
k=i;
}
}
cout<<"成绩最高的学生的学号为:"<<p[k].num<<" "<<"成绩为:"<<p[k].score<<endl;
}
int main()
{
Student stud[5]=
{
Student(141,97),Student(142,75),Student(143,98),
Student(144,90),Student(145,77)
};
void max(Student *p);
Student *p=&stud[0];
max(p);
return 0;
}
<img src="https://img-blog.csdn.net/20150420142407301?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTWFvX3phaQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />