Hello guyz!
Im conducting a debugging contest...
Im writing some questions... I wrote a code implementing virtual functions..
Im not sure where to include bugs here.. Can anyone help me add bugs to this code??
Please bugs must make people think.. THey must not just be syntactical errors..
Thank you..
Output wil be given to the debugger.. and he will asked to debug the code to produce desired result Thanks!
#include <iostream>
using namespace std;
class Shape
{
public:
Shape()
{}
virtual long GetArea()
{
cout<<"Area";
}
virtual long GetPerimeter()
{
cout<<"Perimeter";
}
virtual void Draw() = 0;
};
void Shape::Draw()
{
cout << "Shape Drawn!!";
}
class Circle : public Shape
{
private:
int radius;
int circumference;
public:
Circle(int rad):radius(rad)
{
}
long GetArea() {
return 3 * radius * radius;
}
long GetPerim() {
return 9 * radius;
}
void Draw()
{
cout << "Circle drawing routine here!\n";
}
};
class Rectangle : public Shape
{
private:
int Width;
int Length;
public:
Rectangle(int len, int width):
Length(len), Width(width)
{}
long GetArea()
{
return Length * Width;
}
long GetPerim()
{
return 2*Length + 2*Width;
}
virtual int GetLength()
{
return Length;
}
virtual int GetWidth()
{
return Width;
}
void Draw()
{
for (int i = 0; i<Length; i++)
{
for (int j = 0; j<Width; j++)
cout << "x ";
cout << "\n";
}
}
};
class Square : public Rectangle
{
public:
Square(int len):
Rectangle(len,len)
{}
Square(int len, int width):
Rectangle(len,width)
{
if (GetLength() != GetWidth())
cout << "Error, not a square... a Rectangle??\n";
}
long GetPerim() {
return 4 * GetLength();
}
};
int main()
{
int choice;
Shape * sp;
while (1)
{
cout << "1.Circle\n2.Rectangle\n3.Square\n4.Quit\nEnter Choice.. ";
cin >> choice;
switch (choice)
{
case 1: sp = new Circle(5);
break;
case 2: sp = new Rectangle(4,6);
break;
case 3: sp = new Square (5);
break;
}
if (choice==4)
break;
sp*Draw();
cout << "\n";
}
return 0;
}