Write a program to find a maximum number between/among two and three numbers using constructor
overloading
#include <iostream>
using namespace std;
class FindMax
{
int number;
public:
int getNumber()const
{
return number;
}
FindMax(int a, int b)
{
if(a >= b)
number = a;
else
number = b;
}
FindMax(int a, int b, int c)
{
if(a >= b && a > c)
number = a;
else if(b >= c && b > a)
number = b;
else
number = c;
}
};
int main()
{
FindMax maximalOfTwo(5, 6);
cout << maximalOfTwo.getNumber();
FindMax maximalOfThree(5, 5, 6);
cout << maximalOfThree.getNumber();
return 0;
}
Comments
Dear pashadacoder, yes
Is function overloading being used?
Leave a comment