CS 130 HW 9

Winter 1997

Due: Wednesday, 12 March at 5:00 P.M.

1. Do self-review exercises 4.1-4.3 (you do not need to hand in your answers).

2. Do problems 4.6, 4.7, 4.8, 4.12, 4.15. Hand in your answers.

3. Write a function that takes as parameters an array of floats and an int n that indicates how many values are stored in the array. Return the value of the largest number in the array. Write other functions that return the smallest value, the mean (average) of all the values, and the median (half the values are <= than the median, and half are >=).

Test those functions by writing a program that reads up to 20 numbers into an array, then calls each of the functions, and prints the answers (largest, smallest, mean, median).

4. Write a function that takes as parameters two arrays of floats, x and y, and an int n that indicates how many values are stored in the arrays. The arrays store the (x,y) coordinates of the vertices of a closed polygon, with x[0] = x[n-1] and y[0]=y[n-1]. The function returns the area of the polygon. The area of a polygon can be computed:

area = 0.5 * | (x0*y1 - x1*y0) + (x1*y2 - x2*y1) + . . . + (x{n-2}*y{n-1} - x{n-1}*y{n-2} |

Write a function that prompts for the vertices of a polygon, and prints the area. Test it on the polygon with vertices:

1,1

10,1

10,10

8,12

1,10

1,1