您的位置:首页 > 其它

SDUTACM 面向对象程序设计上机练习九(对象指针)

2016-10-20 15:17 204 查看


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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm 面向对象 指针