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

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


class Name{
  //statement
};

int main(){
  //create obj;
}

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

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

#include<iostream>
using namespace std;

class Test {
public:
    float r, area;

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

    }

    void findArea() {
        area = 3.14 * r * r;
    }

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

int main() {

    Test obj;

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

    return 0;
}

Output:

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