Program to find area of circle

Q. Write a C++ program to find the area of circle using class circle which have following details:

a. Accept radius from the user
b. Calculate the area
c. Display the result


Answer:

Class is a blueprint for the object. Objects are instances of a class. Class holds its own data member function, accessed and used by creating instance of that class. Object holds the data variables declared in a class and the member function work on these class objects.

Following program is calculating the area of circle using class circle.

#include<iostream>
using namespace std;

class circle
{
        float radius, area;   //data members
    public:
        circle()
        {
                cout<<"\n Enter the value of Radius : ";
                cin>>radius;
        }
        void calculate();   //member function
        void display();     //member function
};
inline void circle :: calculate()  //accessing data members of a class circle
{
        area = 3.14 * radius * radius;
}
inline void circle :: display()
{
        cout<<"\n Area of Circle : "<<area;
}
int main()
{
        circle cr;   //object created
        cr.calculate();   //calling function
        cr.display();  //calling function
        return 0;
}


Output:

area of circle