the only problem i have now is that when i enter the symbols to draw the border and fill for the rectangle, this is what is drawn:
lets says witdh 10 and length 5, the border is % and the fill is @.
%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%
The filling @ refuses to be drawn and it should look like this but it doesn't:
%%%%%%%%%%
%@@@@@@@@%
%@@@@@@@@%
%@@@@@@@@%
%%%%%%%%%%
This all happens in void draw() loop.
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle()/*rectangle constructor defaults the values for length, width, area, and perimeter to 1 and initializes five rectangle objects to zero*/
{
rectangleLength = rectangleWidth = 1;
rPerimeter = rArea = 1;
for ( int r = 1; r <= 5; r++)
rArray[r] = 0;
}
void setRectangleLength()// set length value between 1 to 20
{
static int lengthc = 1;
bool lengthTest = false;
while ( !lengthTest )
{
cout << "\nEnter the length of the rectangle " << lengthc << " from 1 to 20: ";
cin >> rectangleLength;
lengthc++;
if ( rectangleLength < 0 || rectangleLength > 20 )
{
cout << "The value " << rectangleLength << " is out of range.\n";
cout << "Try again.\n";
lengthTest = false;
lengthc--;
}
else
{
lengthTest = true;
}
}
}
int getRectangleLength()
{
return rectangleLength;
}
void setRectangleWidth()// set width value between 1 to 20
{
static int widthc = 1;
bool widthTest = false;
while ( !widthTest )
{
cout << "\nEnter the width of the rectangle " << widthc << " from 1 to 20: ";
cin >> rectangleWidth;
widthc++;
if ( rectangleWidth < 0 || rectangleWidth > 20 )
{
cout << "The value " << rectangleWidth << " is out of range.\n";
cout << "Try again.\n";
widthTest = false;
widthc--;
}
else
{
widthTest = true;
}
}
}
int getRectangleWidth()
{
return rectangleWidth;
}
void calculatePerimeter()
{
rPerimeter = 2 * (getRectangleLength() + getRectangleWidth());
cout << "The perimeter of the rectangle is: " << rPerimeter << endl;
}
void calculateArea()
{
rArea = getRectangleLength() * getRectangleWidth();
cout << "The area of the rectangle is: " << rArea << endl;
}
void setDrawRectangleBorder()
{
char border;
cout << "Enter the character you would like to see as the border of the rectangle:";
cin >> border;
}
char getDrawRectangleBorder()
{
return (border);
}
void setDrawRectangleFill()
{
char fill;
cout << "Enter the symbol to fill the rectangle:";
cin >> fill;
}
char getDrawRectangleFill()
{
return (fill);
}
void draw()
{
setDrawRectangleBorder();
setDrawRectangleFill();
for (int i = 0; i < rectangleLength; i++)
{
for (int j = 0; j < rectangleWidth; j++)
{
if ( i == 0 || i == rectangleLength - 1)
{
cout << getDrawRectangleBorder();
}else if ( j == 0 || j == rectangleWidth - 1)
{
cout << getDrawRectangleBorder();
}
else
{
cout << getDrawRectangleFill();
}
}
cout << "\n";
}
}
void doEverything()
{
setRectangleLength();
setRectangleWidth();
calculatePerimeter();
calculateArea();
draw();
}
/*void lengthc()// function increments the number of the rectangle when asking for length
{
static int l = 0;
l = l + 1;
cout << l << endl;
}
void widthc()// function increments the number of the rectangle when asking for width
{
static int w = 0;
w = w + 1;
cout << w << endl;
}*/
private: // length and width as private data members
int rectangleLength;
int rectangleWidth;
int rPerimeter;
int rArea;
char border;
char fill;
char rArray[5];
};
int main()
{
Rectangle rA[5];
rA[0].doEverything();
rA[1].doEverything();
rA[2].doEverything();
rA[3].doEverything();
rA[4].doEverything();
return 0;
}