C++ Program to find largest of three numbers using parameterized constructor


In this program, You will learn how to find the largest of three numbers using a parameterized constructor in C++.


10 20 30 => 30

40 50 60 => 60

Example: How to find the largest of three numbers using parameterized constructor in C++.

#include<iostream>
using namespace std;

class Test {
    int c;
public:

    Test(int a, int b, int c) {
        if (a > b && a > c) {
            cout << "Largest is:" << a;
        } else if (b > c) {
            cout << "Largest is:" << b;
        } else {
            cout << "Largest is:" << c;
        }
    }
};

int main() {

    int a, b, c;
    cout << "Enter three numbers:";
    cin >> a >> b >> c;

    Test obj(a, b, c);

    return 0;
}

Output:

Enter three numbers:10 30 20
Largest is:30