C++ Program to find the area of a rectangle using parameterized constructor


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


area = length * width


Example: How to find the area of a rectangle using parameterized constructor in C++

Run it Now
#include<iostream>
using namespace std;

class Test {
public:
    int l, w, area;

    Test(int length, int width) {
        l = length;
        w = width;
    }

    void findArea() {
        area = l * w;
    }

    void display() {
        cout << "\nArea of rectangle is : " << area;
    }
};

int main() {

    int length, width;

    cout << "Enter length of rectangle : ";
    cin >> length;
    cout << "\nEnter width of rectangle : ";
    cin>>width;

    Test obj(length, width);

    obj.findArea();
    obj.display();

    return 0;
}

Output:

Enter length of rectangle : 12
Enter width of rectangle : 2
Area of rectangle is : 24