Introductory Programming
Fall 2004

Homework 5

Due: Thursday 14 October.

The reading for this assignment is Chapter 5 of How to think....

Fruitful Amoebas

The object of this assignment is to rewrite your solution to Homework 4 using fruitful functions. Your solution should include at least the following functions:

  1. A function named distance that takes two Amoebas and returns the distance between the.

  2. A boolean function named are_close that takes two Amoebas and returns True if the distance between them is less than 1.0, and False otherwise.

  3. A function named bound that takes a coordinate x and a limit and that returns:


    $\displaystyle x$ $\textstyle \rm {if}$ $\displaystyle -limit \le x \le limit$ (1)
    $\displaystyle -limit$ $\textstyle \rm {if}$ $\displaystyle x < -limit$  
    $\displaystyle limit$ $\textstyle \rm {if}$ $\displaystyle x > limit$  
           

And, of course, your solution should use these functions!

WHAT TO TURN IN: Before you turn in your program, please clean it up by removing unnecessary code and other detritus. Add a comment at the beginning of the file that has your name in it, and add a comment to each function that explains what it does (but not how it does it).

Make sure that every line in the file has fewer than 80 lines so that it does not wrap around when you print it. Then print the file using a2ps with the -1 option. See Chapter 3 of the Olinux manual for more details.