面向对象程序设计上机练习七(类和对象)
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
利用类的数据成员和成员函数完成下列操作:输入三个整数,输出它们的最大值。
输入
输入三个整数。
输出
输出3个整数的最大值。
示例输入
2 8 5
示例输出
8
来源
zlh
C
#include<stdio.h>
int main()
{
int a,b,c,max;
scanf("%d %d %d",&a,&b,&c);
max=a;
if(b>max)max=b;
if(c>max)max=c;
printf("%d",max);
}
C++
#include<iostream>
using namespace std;
class num
{
private:
int a,b,c,d;
public:
void setint()
{
cin>>a>>b>>c;
max(a,b,c);
}
void max(int a,int b,int c)
{
d=a;
if(b>d)
d=b;
if(c>d)
d=c;
cout<<d<<endl;
}
};
int main()
{
num t;
t.setint();
}