Sams Teach Yourself C in 21 Days

(singke) #1
Worse, you could call these draw_circle(),draw_circle2(), anddraw_circle3().
This is not very practical. Take a look at Listing B1.1. You will notice something odd
about this listing which draws two squares. You should notice that there is more than one
square()function. Squares are being used because the code is simpler than that for cir-
cles.

LISTINGB1.1 square.cpp. Multiple squarefunctions
1: /* A C listing with something odd - */
2: /* using a square() function twice */
3: #include <stdio.h>
4: #include <stdlib.h>
5:
6: /* square function – the first one! */
7: void square( int topleftX, int topleftY, long width )
8: {
9: int xctr = 0;
10: int yctr = 0;
11: // This listing assumes bottom values are greater than top values
12:
13: for ( xctr = 0; xctr < width; xctr++)
14: {
15: printf(“\n”);
16:
17: for ( yctr = 0; yctr < width; yctr++ )
18: {
19: printf(“*”);
20: }
21: }
22: }
23:
24: /* square function – the second one! */
25: void square( int topleftX, int topleftY, int bottomleftX, int bottomleftY)
26: {
27: int xctr = 0;
28: int yctr = 0;
29:
30: // This listing assumes bottom values are greater than top values
31:
32: for ( xctr = 0; xctr < bottomleftX - topleftX; xctr++)

632 Bonus Day 1

FIGUREB1.1
Different parameters
for drawing a circle.
(x, y)

(x, y)

(x, y)

(x, y)

(x, y) (x, y)

r

36 448201x-Bonus1 8/13/02 11:18 AM Page 632

Free download pdf