How to Calculate Circle Area using Object Oriented Programming | Calculate Area of Circle
In This Post We Learn How to Calculate Circle Area using Classes and Objects . Different Concept of Polymorphism and Abstract Classes
Source Code Program
#include <iostream>
using namespace std;
class shape
{
protected:
double x,y;
public:
virtual void get_data()=0;
virtual void display_area()=0;
};
class circle:public shape{
public:
void get_data()
{
cout<<"\n=====Data Entry for Circle=====\n";
cout<<"Enter Radius of circle : ";
cin>>x;
}
void display_area(void)
{
cout<<"\n=====Area of Circle=====\n";
double aoc;
aoc = 3.14 * x * x; //area = 3.14*radius*radius
cout<<"Area of circle is "<<aoc<<endl;
}
};
main(){
circle crl;
shape *list;
list=&crl;
list->get_data();
list->display_area();
}
using namespace std;
class shape
{
protected:
double x,y;
public:
virtual void get_data()=0;
virtual void display_area()=0;
};
class circle:public shape{
public:
void get_data()
{
cout<<"\n=====Data Entry for Circle=====\n";
cout<<"Enter Radius of circle : ";
cin>>x;
}
void display_area(void)
{
cout<<"\n=====Area of Circle=====\n";
double aoc;
aoc = 3.14 * x * x; //area = 3.14*radius*radius
cout<<"Area of circle is "<<aoc<<endl;
}
};
main(){
circle crl;
shape *list;
list=&crl;
list->get_data();
list->display_area();
}
Related Video
Post a Comment