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