CIS071 Lab05: Expandable House Due in one week, as usual

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 5. 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 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.

Email your submission to Mike Mays. Use a subject of Lab05 in the email.  Attach source and script/capture files to the email.


Sample Output:     

Enter house width (0 to exit)>7

   *
  * *
 *   *
*     *
*******
*     *
*     *
*     *
*     *
*     *
*******

Enter house width (0 to exit)>5

  *
 * *
*   *
*****
*   *
*   *
*   *
*****

Enter house width (0 to exit)>0

Important Notes:
  1. You don't have to hand in your program decomposition this week. But that doesn't mean you don't have to do it. In fact, the TAs have been instructed to ask for it and make sure it is correct before working on your C code with you. (This will be true for every lab.)
    1. For problem-solving help, see Frank Friedman's "Display Triangle" reference for Lecture 5 (reachable from the syllabus).
  2. 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 1 + width/2
  3. To print a certain number of spaces (or asterisks), loop through printf("%c", ' ') or printf("%c", '*') for the required number of spaces or asterisks. Then printf("\n") to end the line.
  4. Be sure your main program uses a loop to allow the user to display more than one house figure without having to re-run your program. A sentinel-controlled while loop should work nicely (see lecture notes).
  5. For extra credit, have getWidth() check for valid input, i.e., either at least 5 or exactly 0. See the code presented in class that does a similar task for the stick figures example.