Lecture 12:  Functions and Design

Activity:

In today's lecture we saw the functional decomposition of a program to draw a house.  Suppose we want to add features to the picture.  Think of things to add to the simple house picture.  Once you have decided on the new features of your house picture, please draw them on the diagram and add corresponding functions to the calling tree (also known as the static call graph).  Remember that the primitive drawing functions are Rectangle, Triangle, Circle, and Line.


 

(Hint:  Some features you might consider include a chimney, a fence, and shutters for the windows.)
 

After you have added features to the picture and to the calling graph, please write the C code for one or more of your new functions.  A model is the following code for draw_window.

void draw_window (int x, int y){
    /* (x,y) is the lower left corner of the window */
    rectangle(WHITE, x, y, x + WIN_W, y + WIN_H);
    line(x + MID_X, y, x + MID_X, y + WIN_H);
    line(x, y + MID_Y, x + WIN_W, y + MID_Y);
}

Prototypes for the primitive drawing functions are listed below.

void rectangle(int color, int left_lower_x, int left_lower_y, int right_upper_x,
               int right_upper_y);
void triangle(int color, int x1, int y1, int x2, int y2, int x3, int y3);
void circle(int color, int center_x, int center_y, int radius);
void line(int x1, int y1, int x2, int y2);