CIS071 Lab05 - Expandable House Figure                                                                       DUE: (Noon, Fri, Feb 24, 2006)  


Objectives:    Use of loops, Use of functions. Function input arguments used in loops and in other ways inside functions.  Problem solving!

Expandable House Figure:
Document and write a program to display a variable-sized (in width) house figure (see example below). The user supplies the width (in characters) of the figure. The house consists of an inverted “V” (constructed using the "*” character) over a square (framed using “*” characters).
Write functions to perform the following activities:
1.     getWidth queries the user and returns the desired house width.  The width must be an odd number greater than or equal to five.  If the user fails to enter a valid integer, return the value 0 (which will cause the main program to terminate).
2.     printInvVee prints an inverted “V” whose last line is the desired width ( input argument)
3.     printSquare prints a square framed in “*” characters of the specified width ( input argument)

The program repeats the cycle of requesting a width and printing a “house” until the user supplies a width <= 0.

Compile and test the program with values which demonstrate the correct operation of the program (as you specified in your test plan).  Be sure to explain your algorithm in the documentation.

Sample Output:     

supply house width, 0 to exit:7
 
   *
  * *
 *   *
*     *
*******
*     *
*     *
*     *
*     *
*     *
*******
 
supply house width, 0 to exit:0
 
 
Hints: 
1. The width supplied by the user determines how many rows are required for the roof and the 
   square. The number of rows for the roof is width/2. 
2. To print a certain number of spaces (or asterisks), loop thru 
             printf(“%c”, ’ ‘) or printf(“%c”,’*’) 
   the required number of spaces or asterisks. Then printf(“\n”) to end the line.
3. Be sure to have the program repeat the cycle of prompting for width, reading width, 
   printing house until the user supplies width <= 0.
4. Feel free to use the function displayNchars (int, char); as discussed in class.