面向对象程序设计上机练习七(类和对象)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
利用类的数据成员和成员函数完成下列操作:输入三个整数,输出它们的最大值。
Input
输入三个整数。
Output
输出3个整数的最大值。
Example Input
2 8 5
Example Output
8
Hint
Author
zlh
#include <iostream>
using namespace std;
class compare
{
private:
int a[5], i, max;
public:
compare()
{
for(i=0; i<3; i++)
a[i] = 0;
max = 0;
};
void newComp();
};
void compare::newComp()
{
for(i=0; i<3; i++)
{
cin >> a[i];
}
max = a[0];
for(i=1; i<3; i++)
{
if(max < a[i])
max = a[i];
}
cout << max;
}
int main()
{
compare T;
T.newComp();
return 0;
}