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.
#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;
}
Comments
Leave a comment