Problem Description
建立对象数组,内放5个学生数据(学号是字符串类型、成绩是整型),设立max函数,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号和成绩。
Input
输入5个学生数据。
Output
输出5个学生中成绩最高者的学号和成绩。
Example Input
01 89 02 78 03 56 04 92 05 76
Example Output
04 92
Hint
#include<iostream>
#include<math.h>
using namespace std;
string Maxname;
int Maxscore=-1;
class Point
{
private:
string name;
int score;
public:
Point();
void setpoint();
friend void Max(Point *);
};
Point::Point()
{
score=0;
}
void Max(Point *t)
{
if(t->score>Maxscore)
{
Maxscore=t->score;
Maxname=t->name;
}
}
void Point::setpoint()
{
cin>>name>>score;
}
void showpoint()
{
cout<<Maxname<<" "<<Maxscore<<endl;
}
int main()
{
Point a[100];
int i;
for(i=0;i<5;i++)
a[i].setpoint();
for(i=0;i<5;i++)
Max(&a[i]);
showpoint();
return 0;
}