The United States uses the English system of (length) measurements. The rest of the world uses the metric system. So, people who travel abroad and companies that trade with foreign partners often need to convert English measurements to metric ones and vice versa.
Here is a table that shows the six major units of length measurements of the
English system:
| English | Metric | |||||
|---|---|---|---|---|---|---|
| 1 inch | = | 2.54 | cm | |||
| 1 foot | = | 12 | in. | |||
| 1 yard | = | 3 | ft. | |||
| 1 rod | = | 5.5 | yd. | |||
| 1 furlong | = | 40 | rd. | |||
| 1 mile | = | 8 | fl. |
Develop the functions inches->cm, feet->inches, yards->feet, rods->yards, furlongs->rods, and miles->furlongs.
Then develop the functions feet->cm, yards->cm, rods->inches, and miles->feet.
Hint: Reuse functions as much as possible. Use variable definitions to specify constants. Solution
Exercise 3.3.2
Develop the program volume-cylinder. It consumes the radius of a cylinder's base disk and its height; it computes the volume of the cylinder. Solution
Exercise 3.3.3
Develop area-cylinder. The program consumes the radius of the cylinder's base disk and its height. Its result is the surface area of the cylinder. Solution
Exercise 3.3.4
Develop the function area-pipe. It computes the surface area of a pipe, which is an open cylinder. The program consumes three values: the pipe's inner radius, its length, and the thickness of its wall.
Develop two versions: a program that consists of a single definition and a program that consists of several function definitions. Which one invokes more confidence? Solution
Exercise 3.3.5
Develop the program height, which computes the height that a
rocket reaches in a given amount of time. If the rocket accelerates at
a constant rate g, it reaches a speed of
in t time
units and a height of 1/2 * v * t where v is the speed at t. Solution
Exercise 3.3.6
Recall the program Fahrenheit->Celsius from
exercise
. The program consumes a temperature measured in
Fahrenheit and produces the Celsius equivalent.
Develop the program Celsius->Fahrenheit, which consumes a temperature measured in Celsius and produces the Fahrenheit equivalent.
Now consider the function
;; I : number -> number ;; to convert a Fahrenheit temperature to Celsius and back (define (I f) (Celsius->Fahrenheit (Fahrenheit->Celsius f)))Evaluate (I 32) by hand and using DrScheme's stepper. What does this suggest about the composition of the two functions? Solution