Answer to Question #173885 in C++ for P. Gokul

Question #173885

Declare the base class circle with attribute radius. Assign the values in default constructor, member functions are getdata() to get input values for data members, develop member function area() to find the area of circle and display() to print the area of circle using multilevel inheritance.


1
Expert's answer
2021-03-22T09:49:37-0400
#define _USE_MATH_DEFINES


#include <iostream>
#include <math.h>


using namespace std;


class Circle
{
private:
    double radius;


public:
    Circle()
    {
        this->radius = 0;
    }
    void getData()
    {
        cout << "Enter a radius: ";
        cin >> radius;
    }
    double area()
    {
        return M_PI*radius*radius;
    }
    void display()
    {
        cout << "Area of circle is: " << area() << endl;
    }


};


int main()
{
    Circle circle;
    circle.getData();
    circle.display();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS