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 <bits/stdc++.h>Â
using namespace std;
// 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.
class Circle
{
float Radius,PI=3.1457;
public:
float area(float r)Â
{
float A;
A = PI * r * r;
return(A);
}
float getData(void)
{
float r;
cout<<"\nEnter the radius of circle: "; cin>>r;
return(r);
}
void display(float A)
{
cout<<"\n\nArea of Circle = "<<A<<" sq. units";
}
};
main(void)
{
float Radius,CircleArea,Perimeter;
Circle C;
Radius = C.getData();
CircleArea = C.area(Radius);
C.display(CircleArea);
return(0);
}
Comments
Leave a comment