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;
}
本文介绍了一个使用C++编程语言实现的学生信息管理系统片段,该系统能够接收5个学生的学号和成绩数据,通过定义一个max函数来找出成绩最高的学生,并输出其学号及成绩。代码中采用了面向对象的方法设计学生类。

被折叠的 条评论
为什么被折叠?



