E33 Answer


Area: 12

Comments: The file rect.c is like an object of object oriented programming. It can be thought of as a "rectangle object." Its global static variables are similar to the private instance variables of an object. The functions in the file are like the methods of an object. The set and get functions are like the "setter" and "getter" methods of an object.

However, there can only be one "rectangle object" per program with this style of programming.


/* --- rect.h --- */ void setWidth( int w ); void setHeight( int h ); int getArea();
/* --- rect.c --- */ static int width = 0; static int height = 0; void setWidth( int w ) { width = w; } void setHeight( int h ) { height = h; } int getArea() { return height*width; }
/* --- mainRect.c --- */ #include "rect.h" int main() { setHeight( 4 ); setWidth( 3 ); printf("Area: %d\n", getArea() ); system("pause"); }