Set up an object array, put 5 students (student number, score), set up a function of max, with pointers to objects as function parameters, in the Max function to find the highest scores of 5 students, and output its number.
#include <iostream>
using namespace std;
Class Student
{public:
Student (int=10,int=0);
int number;
int score;
void display ();
student::student (int num,int SCO): Number (num), score (SCO) {
}
void Student::d isplay ()
{
cout <<number<< "" <<score<<endl;
}
void Max (Student *p)
{
int maxi=p[0].score;
int temp=0;
for (int i=1;i<5;i++)
if (P[i].score>maxi)
{
maxi=p[i].score;
temp=i;
}
cout<<p[temp].number<< "" <<maxi<<endl;
}
int main ()
{
Student stu[5]={
student{1001,90},
student{1002,80},
student{1003,99},
student{1004,84},
student{1005,85}
};
Student *p=&stu[0];
Max (p);
return 0;
}
Above this C + + and object after class exercises simple example is small series to share all the content, hope to give you a reference, also hope that we support cloud habitat community.