This is my assignment and im pretty confused. Our book is a horrible book, and i cant seem to understand much of it. So i was hoping maybe someone could point me in the right direction in getting started. tHis is what we are expected to do.

Write a program that displays a rectangle of given the length (an integer size less
than or equal to 21) and the width (an integer less than or equal to 79). Your
program should accept as input from the keyboard the character used to form the
rectangle, and the two values for the length and width of the rectangle.

Out of range input values should result in an informative error message.

Your program should process only one input case, legal or not. Termination occurs
after either the error message is printed or the diamond is drawn.

It is necessary that the program be written using loops.

Sample runs:

Rectangle drawing program
Enter the character, and length and width (eg. x 7):A 7 12
AAAAAAAAAAAA
A A
A A
A A
A A
A A
AAAAAAAAAAAA

Rectangle drawing program
Enter the character, and length and width (eg. x 7):R 3 5
RRRRR
R R
RRRRR

Rectangle drawing program
Enter the character, and length and width (eg. x 7):A 27 32
You have entered an illegal value for the length. It must be between 1 and 21.

You should use a named constant (const) to define and refer to the box size limits.
This will make it easy to modify the program at a later date if the size restriction is
changed. Write a class called Rectangle. Have the appropriate data members for
that class. Also have a constructor and a function to output the rectangle.

So you print your chosen character in all columns for the first row or last row, or in all rows for the first column or the last column; otherwise you print a space. And at the end of the line you print a newline.

for ( int r = 0; r < rows; ++r )
   {
      for ( int c = 0; c < cols; ++c )
      {
         if ( r == 0 || r == rows - 1 || c == 0 || c == cols - 1 )
         {
            std::cout << ch;
         }
         else
         {
            std::cout << ' ';
         }
      }
      std::cout << '\n';
   }
This article has been dead for over six months. Start a new discussion instead.