CIS 1057: Homework 4

Handed out: 09/21/2010
Due: by 10:00am on 09/27/2010
Email program to TA

Write a program that prompts the user to enter a positive integer, say X, and then prints out a square centered on the line (which you can assume to be 80 columns wide).

Do the assignment by defining and using the function

     void drawSquare(int size);
The main program will just prompt the user to enter the size of the square and then call the drawSquare function.

Here is a sample run of your program [notice that rows look "bigger" than the columns]:


Enter value for the side of the square: 30
                           XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           X                            X
                           XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
If the user enters a value less than one, a warning should be printed. If the user enters a value greter than 80, the program will act as if the user had entered 80.

For the ambitious: could you print a diamond instead than a square? for ecample, if the side size were 5 you would print

                                         X
                                        X X
                                       X   X
                                      X     X
                                     X       X
                                      X     X
                                       X   X
                                        X X
                                         X