/* All rights reserved.
* 文件名称:test.cpp
* 作者:陈丹妮
* 完成日期:2015年 6 月 21 日
* 版 本 号:v1.0
*/
#include <iostream>
#include <iomanip>
using namespace std;
class Student
{
private:
int num;
double s;
public:
void input();
void display();
double get_s()
{
return s;
}
int get_num()
{
return num;
}
};
void Student::input()
{
cin>>num>>s;
}
void Student::display()
{
cout<<num<<" "<<s<<endl;
}
void max(Student *p ,int n)
{
int i,d=-1;
double max=0;
for(i=0; i<n; i++)
{
if((p+i)->get_s()>max)
{
max=(p+i)->get_s();
d++;
}
}
cout<<(p+d)->get_num()<<" "<<max;
}
int main()
{
void max(Student* ,int);
const int NUM=10;
Student stud[NUM];
int n,i;
cin>>n;
for(i=0; i<n; i++)
stud[i].input();
cout<<setiosflags(ios::fixed);
cout<<setprecision(2);
Student *p=&stud[0];
max(p,n);
return 0;
}
学习心得:刷题,刷题,继续努力啦!!!相信自己!!
第十五周oj刷题——Problem E: C++习题 对象数组求最大值
原文:http://blog.csdn.net/nufangdongde/article/details/46581235