CIS071 Lab07 - Expandable House Figure                                       DUE: (NOON, Tue Mar 13, 2007)


 

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 of the figure. The house consists of a roof (or, inverted “V”) that is constructed using the "*” character, and a base in the shape of a square that is framed using “*” characters.

 

You should start from the solution to the previous assignment (Lab06, its solution can be found in notes for Lecture 11) and modify it to display inverted. To do so, you should
1.  Write a new function
printRoof that prints the roof of a house. Its prototype is:

void printRoof (int w);
For example, if w = 5, the following will be printed:

  *

 * *

*   *

 

2.  Modify the main function to print roof of width w (using function printRoof), before printing of house base of width w (this can be done by calling function printSquare that you already have).

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:7
 
   *
  * *
 *   *
*     *
*******
*     *
*     *
*     *
*     *
*     *
*******
 
 
Hint: Please, observe that printRoof function is very similar to printTriangle function we covered in class (you can find the C code in notes for Lecture 11). The main differences are in the following:
- the first line of the roof (it has a single star) is different from the remaining lines (they have two stars)
- each line, starting from the second line, can be described by the following sequence: nspaces1 spaces, 1 star, nspaces2 spaces, 1 star. You should only figure out how nspaces1 and nspaces2 is being changed from line to line