Math, asked by sumitsuthar6302, 1 year ago

Write a c++ program to calculate the area of circle, rectangle and square using runtime polymorphism

Answers

Answered by naeemtayyab01
5

Step-by-step explanation:

Write a C++ Program to calculate the area of Triangle, Circle and Square using Run Time Polymorphism. Use Shape as base class and Triangle, Ci

Answered by dreamrob
7

Program:

#include <bits/stdc++.h>  

using namespace std;

class area

{

public:

 virtual void find_area() = 0;

};

class circle:public area

{

public:

 void find_area()

 {

  int r;

  cout<<"Enter radius : ";

  cin>>r;

  cout<<"Area of the circle is : "<<((22/7)*r*r);

 }

};

class rectangle:public area

{

public:

 void find_area()

 {

  int l,b;

  cout<<"Enter length : ";

  cin>>l;

  cout<<"Enter breadth : ";

  cin>>b;

  cout<<"Area of the rectangle is : "<<(l*b);

 }

};

class square:public area

{

public:

 void find_area()

 {

  int s;

  cout<<"Enter side : ";

  cin>>s;

  cout<<"Area of the square is : "<<(s*s);

 }

};

int main()

{

int ch;

cout<<"1 for Circle\n2 for Rectangle\n3 for Square\nEnter your choice : ";

cin>>ch;

if(ch == 1)

{

 circle A;

 A.find_area();

}

else if(ch == 2)

{

 rectangle A;

 A.find_area();

}

else if(ch == 3)

{

 square A;

 A.find_area();

}

else

{

 cout<<"Invalid Choice";

}

return 0;

}

Similar questions