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

Question #177524

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-04-03T06:59:03-0400
#include <iostream>
#include <math.h>
using namespace std;


class Circle
{
    public:
        float radius;
        Circle(){
            radius =getdata();
        }
      int getdata()
      {
          float r;
          cout<<"Input Radius: ";
          cin>>r;
          return r;
      }
};


class CircleArea : public Circle
{
    public:
    int area(){
        return M_PI*radius*radius;
    }
};


class DisplayArea : public CircleArea
{
    public:
        void display(){
            cout<<"Area: "<< area();
        }
};


int main()
{
    DisplayArea obj;
    obj.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