1. Engineering
  2. Computer Science
  3. c make this class generic so that the sides of...

Question: c make this class generic so that the sides of...

Question details

C++

Make this class generic so that the sides of the shape may be integer or float

#include <iostream>
using namespace std;

// shape is square
class shape
{
int side;

public: int getSide()
{
return side;
}

bool setSides(int s)
{
if(s > 0)
{
side = s;
return true;
}
else
return false;
}

int getArea()
{
return side*side;
}

int getPerimeter()
{
return side*4;
}

void display()
{
cout<<"Side: "<<getSide()<<endl;
cout<<"Area: "<<getArea()<<endl;
cout<<"Perimeter: "<<getPerimeter();
}
};

int main()
{
shape S;
int num;

cout<<"Enter side: ";
cin>>num;

if(!S.setSides(num))
cout<<"Entered side is not valid\n";

S.display();

return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution