C++ Program to find the area of a rectangle using class and object


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


area = length * width


Example: How to find the area of a rectangle using class and object in C++

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

class Test {
public:
    int length, width, area;

    void input() {
        cout << "Enter length of rectangle : ";
        cin >> length;
        cout << "\nEnter width of rectangle : ";
        cin>>width;
    }

    void findArea() {
        area = length * width;
    }

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

int main() {

    Test obj;

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

    return 0;
}

Output:

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