For my programming class, I have gotten to the lesson that involves overloading constructors and what not, but I have a problem with mine that I am possitive is a very simple syntax error or something.
If anyone could be so kind as to take a look at the following code.
#include <cstdlib>
#include <iostream>
using namespace std;
class rectangle
{
public:
//constructors
rectangle();
rectangle(unsigned int width, unsigned int height);
~rectangle(){} //inline
//overloaded draw function:
void drawShape() const;
void drawShape(unsigned int aWidth, unsigned int aHeight) const;
private:
unsigned int itsWidth;
unsigned int itsHeight;
};
//1st overloaded constructor
rectangle::rectangle()
{
itsWidth = 5;
itsHeight = 12;
}
//second overloaded constructor
rectangle::rectangle(unsigned int width, unsigned int height)
{
itsWidth = width;
itsHeight = height;
}
//overloaded drawshape, which draws the rectangle based on the current value
//takes no values
void rectangle::drawShape() const
{
drawShape(itsWidth,itsHeight);
}
//overloaded drawshape, based on parameters given.
//takes two values
void rectangle::drawShape(unsigned int width, unsigned int height) const
{
for(unsigned int i = 0; i<height; i++)
{
for(unsigned int j = 0; j< width; j++)
{
//allows the drawing of superior rectangles
if(j != 0 && j != (width-1) && i != 0 && i != (height-1))
{
cout << " ";
}
else
{
cout << "*";
}
}
cout << "\n";
}
}
int main()
{
unsigned int x;
unsigned int y;
cout << "Below is a rectangle drawn with the 1st overloaded constructor." << endl;
rectangle theRect2();
theRect2.drawShape();
rectangle theRect(5,7);
theRect.drawShape();
cout << endl;
cout << "Enter a value for the width of the new rectangle to be drawn: ";
cin >> x;
cout << "Enter a value for the height of the new rectangle to be drawn: ";
cin >> y;
theRect.drawShape(x,y);
system("PAUSE");
}