/* * First example: shapes * 1. Bad old way, in plain C * * RunStuff:: gcc THISFILE * * Picture looks roughly like this: * * ************************* ***** * * * * * * * * * * * * * * * * * * * * * * r1 * *r2 * * * * * * * * * * * * * * * * * ************************* * * * * * * * * * * * * * * * * * * * * * * * * * c1 * * * * * * * * * * * * * * ***** */ #include /* * Data definitions */ int r1x, r1y, r1wid, r1ht; int r2x, r2y, r2wid, r2ht; int c1x, c1y, c1rad; /* * Procedure definitions */ void draw_rect (int x, int y, int wid, int ht) { printf ("Drawing rectangle at %d, %d, %d, %d\n", x, y, wid, ht); } void draw_circle (int x, int y, int rad) { printf ("Drawing circle at %d, %d, radius = %d\n", x, y, rad); } float area_rect (int x, int y, int wid, int ht) { return (float) (wid * ht); } float area_circle (int x, int y, int rad) { return (float) (rad * rad * 3.14159); } /* * Main program */ int main () { /* * Set the locations of the 3 objects */ r1x = 10; r1y = 10; r1wid = 50; r1ht = 50; r2x = 80; r2y = 10; r2wid = 10; r2ht = 100; c1x = 35; c1y = 90; c1rad = 10; /* * Draw them */ draw_rect (r1x, r1y, r1wid, r1ht); draw_rect (r2x, r2y, r2wid, r2ht); draw_circle (c1x, c1y, c1rad); /* * Compute and print total area */ printf ("Total area = %f\n", area_rect (r1x, r1y, r1wid, r1ht) + area_rect (r2x, r2y, r2wid, r2ht) + area_circle (c1x, c1y, c1rad)); return 0; }