Answer to Question #179957 in C++ for bryan

Question #179957

Write a program to find a maximum number between/among two and three numbers using constructor

overloading



1
Expert's answer
2021-04-10T06:55:52-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
15.11.21, 20:02

Dear pashadacoder, yes


pashadacoder
15.11.21, 19:16

Is function overloading being used?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS