C++
Make this class generic so that the sides ofthe shape may be integer orfloat.
---------------shape.h------------
class Shape
{
public:
Shape();
virtual int getSide();
virtual bool setSide(int x);
virtual int getArea();
virtual int getPerimeter();
void display();
~Shape();
protected:
private:
int side;
// T_sides[numSides];
};
----------------shape.cpp----------
#include \"Shape.h\"
#include
using namespace std;
Shape::Shape()
{
}
void Shape::display()
{
cout<<\"side: \"<cout<<\" area: \"<cout<<\"perimeter: \"<}
bool Shape::setSide(int x)
{
if(x>0){
side = x;
return true;
}else
return false;
}
int Shape::getSide()
{
return side;
}
int Shape::getArea()
{
return side*side;
}
int Shape::getPerimeter()
{
return side*4;
}
Shape::~Shape()
{
//dtor
}
int main()
{
int num;
Shape s1;
cout<<\"Enter side of shape: \";
cin>>num;
if (!s1.setSide(num))
{
cout<<\"Please enter a valid side.\"<}
s1.display();
return 0;
}