Mega Code Archive
Class with only virtual methods
#include
class Shape
{
public:
Shape(){}
virtual ~Shape(){}
virtual long GetArea() = 0;
virtual long GetPerim()= 0;
virtual void Draw() = 0;
};
class Circle : public Shape
{
public:
Circle(int radius):itsRadius(radius){}
~Circle(){}
long GetArea() { return 3 * itsRadius * itsRadius; }
long GetPerim() { return 9 * itsRadius; }
void Draw();
private:
int itsRadius;
int itsCircumference;
};
void Circle::Draw()
{
std::cout << "Circle drawing \n";
}
class Rectangle : public Shape
{
public:
Rectangle(int len, int width):
itsLength(len), itsWidth(width){}
virtual ~Rectangle(){}
virtual long GetArea() { return itsLength * itsWidth; }
virtual long GetPerim() {return 2*itsLength + 2*itsWidth; }
virtual int GetLength() { return itsLength; }
virtual int GetWidth() { return itsWidth; }
virtual void Draw();
private:
int itsWidth;
int itsLength;
};
void Rectangle::Draw()
{
for (int i = 0; iDraw();
sp = new Rectangle(4,6);
sp->Draw();
sp = new Square(5);
sp->Draw();
return 0;
}
Circle drawing
x x x x x x
x x x x x