Exercises for Homework #4, part A.

You do not have to type these in and run them.  Just make sure they are legible (and correct!).  As with any piece of paper you turn in, include your name, ID, section number, and date.

Hints

  1. No printf or scanf allowed in any of these functions!  If you think you need printf or scanf, you're missing something.
  2. Do the problems in the order given.
  3. First decide the prototype of the function.  If you can't write the prototype, it probably means you don't understand the problem yet.  Keep working at it!  There may be more than one good solution.
  4. Assume you are working in a graphics system like that of GP142.  Concepts like "point", "color", and "origin" are pretty generic, but if in doubt, do it the way GP142 does it.
  5. You are not asked to write a main or a full program.  Just write the functions.   Try not assume anything about the program they might be used in.

The Problems

1. Write a function which tells how far a point is from the origin.

2. Write a function, which, given two points, tells you the x and y coordinates of the point closer to the origin.

3. Suppose we have 3 arrays, which together represent points.  One array contains the x-coordinates, one array contains the y-coordinates, and one array contains the color.   Write a function which, given three such arrays, gives back the x and y coordinates of the RED point closest to the origin.  If there are no RED points, give back coordinate values of the origin. (Assume RED is a known #define constant).