C++
Use the abstract class shape to define TwoDshape and add all the functionalities to the methods.
Define the instances triangle, square and rectangle in thedriver class to test the functionality of the TwoDclass you have extended from the shape class.
CLARIFICATION:
TwoD is to be inherited from Shape class. And TwoD class methodscan be changed or we can add new methods to differentiate betweenrectangle and a triangle based on the number of sides.
#include
using namespace std;
template
// shape is square
class shape
{
T side;
public: int getSide()
{
return side;
}
bool setSides(T s)
{
if(s > 0)
{
side = s;
return true;
}
else
return false;
}
T getArea()
{
return side*side;
}
T getPerimeter()
{
return side*4;
}
void display()
{
cout<<“Side: “<
cout<<“Area: “<
cout<<“Perimeter: “<
}
};
int main()
{
shape S1;
int num1;
cout<<“Enter side(integer):
PayPal Gateway not configured
PayPal Gateway not configured