C++ Program to find the area of circle using constructor


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


area = 3.14 * r * r


Example: How to find the area of circle using constructor in C++

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

class Test {
public:
    float r, area;

    Test() {
        cout << "Enter radius of a circle : ";
        cin >> r;

        area = 3.14 * r * r;
    }

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

int main() {

    Test obj;

    obj.display();

    return 0;
}

Output:

Enter radius of a circle : 3
Area of circle is : 28.26