Assignment: #squares Due: 10/06/2017 Points: 5

Specification

Using a repetition control statement, query the user to enter in the length of the side of a square and then print a hollow square of that length using plus symbols in its corners, dashes across the top and bottom, vertical bars | down the sides, and space characters in the center.

Your program should use the following prompt:

   Enter length between 0 and 64 (-1 to exit): _

If a length of -1 is entered, then terminate the query loop.

An error message should be issued when a length less than -1 or greater than 64 is entered.

Prior to printing a square, print the length entered.

Be sure your program knows how to print squares having lengths of 0, 1 and 2, respectively. [A square of length 0 should result in the printing of a blank line.]

Prior to terminating the program, print the number of squares printed and the average length.

Your program must use all three of the repetition control statements.

Your program must be modularized into the following functions.

int getInput(void); //function prototype

This function prompts the user to enter an integer. After extracting data from cin, if cin.fail() is true, then print an error message and return -1. If a negative integer is entered, then print an error message and re-prompt the user; otherwise, return the integer.

If getInput() returns a -1, then the calling function should print the number of squares printed along with their average length using the printStats() function and terminate the program.

void printLine(char, char, int); //function prototype

This function prints a line for the square. The first char parameter is the end character. The second char parameter is the interior character. The third parameter is the line length.

Example usage.

   int length = ...;  //variable storing the square length

   // print top line 
   printLine('+', '-', length);
   
   // print interior line
   printLine('|', ' ', length);
void printStats(int, int); //function prototype

This functions prints the number of squares printed and their average length. The first int parameter is the number of squares printed. The second int parameter is the total of the printed square lengths. This function prints a line having the following format.

   X squares printed.  Average length:  Y.YY
Program Output

The following provides an example of how your program output should be formatted. User inputs are enclosed in brackets <>.

   Enter length between 0 and 64 (-1 to exit): <4>
   length entered:  4
   +--+
   |  |
   |  |
   +--+

   Enter length between 0 and 64 (-1 to exit): <0>
   length entered:  0


   Enter a length between 0 and 64 (-1 to  exit): <-2>
   length entered:  -2 is invalid
   Length must be between 0 and 64 inclusive, or enter -1 to exit.
   
   Enter a length between 0 and 64 (-1 to  exit): <1>
   length entered:  1
   +

   Enter a length between 0 and 64 (-1 to  exit): <2>
   length entered:  2
   ++
   ++

   Enter a length between 0 and 64 (-1 to  exit): <6>
   length entered: 6
   +----+
   |    |
   |    |
   |    |
   |    |
   +----+

   Enter a length between 0 and 64 (-1 to  exit): <-1>
   5 squares printed.  Average length: 2.6