C++ Make this class generic so that the sides of the shape may be integer or float. ---------------shape.h------------ class Shape { public: Shape(); virtual...

90.2K

Verified Solution

Question

Programming

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;
}

Answer & Explanation Solved by verified expert
3.7 Ratings (723 Votes)
template class Shape public Shape virtual T getSide    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students