Problem D: C++类实现最大数的输出
Description
输入n个数,找出最大的数并输出。
Input
输入n,并输入n个数。
Output
输出的最大的数,每个输出结果占一行。
Sample Input
10 1 2 3 4 5 6 7 8 9 10
Sample Output
10
HINT
#include <iostream>
using namespace std;
class Q
{
public: //此处声明需要的成员函数
void set_value();
int get_Max();
private:
int n;
int i;
int a[100];
};
//下面定义成员函数
void Q::set_value()
{
cin>>n;
{
for( i=0;i<n;i++)
{
cin>>a[i];
}
}
}
int Q::get_Max()
{
int max=a[0];
for(i=1;i<n;i++)
{
if(max<a[i])
{
max=a[i];
}
}
return max;
}
//用main()函数测试,完成输入输出
int main()
{
Q b1;
b1.set_value();
cout<<b1.get_Max()<<endl;
return 0;
}