### CSC 533: Organization of Programming Languages Spring 2008 HW5: Scheme Programming

For this assignment, you are to define the following Scheme functions. For simplicity, place all of your function definitions in a single file named hw5.scm. Be sure to comment each function as to its behavior.

1. Define functions for converting between inches and centimeters, and between pounds and kilograms. Recall that 1 inch = 2.54 centimeters and 1 pound = 0.45359237 kilograms.

For example, (in->cm 10) should evaluate to 25.4, while (kg->lb 10) should evaluate to 22.0462262.

2. Define functions for converting between square feet and square meters. Note that this is not a straightforward conversion. You must first calculate the square root of the area, convert that square root from one unit to the other, then square the result. Recall that there are 12 inches in a foot and 100 centimeters in a meter.

For example, (ft^2->m^2 100) should evaluate to 9.290304, since the square root of 100 is 10, 10 feet converts to 3.048 meters, and 3.0482 is 9.290304.

3. The Mosteller Formula is often used by doctors and dieticians in estimating the surface area of a person's body given their height and weight. The formula is as follows, where height is assumed to be in centimeters, weight is in kilograms, and surface area is in square meters:
```    area = (height * weight / 3600)1/2
```

Define a function named surface-area-Metric that takes two inputs, a person's height (in centimeters) and weight (in kilograms), and returns their surface area (in square meters).

For example, (surface-area-Metric 168 59) should evaluate to approximately 1.659.

4. Define a function named surface-area-American that takes two inputs, a person's height (in inches) and weight (in pounds), and returns their surface area (in square feet). The functions you have previously written should prove useful here.

For example, (surface-area-American 66 130) should evaluate to approximately 17.836.

5. Define a function named leap-year that takes one input, a positive integer representing a year, and returns #t if it is a leap year (otherwise, #f). In general, years that are evenly divisible by 4 are leap years, unless they are divisible by 100 but not 400.

For example, (leap-year 2008) and (leap-year 2000) should evaluate to #t, but (leap-year 2009) and (leap-year 2100) should evaluate to #f.

6. Define a function named days-in-year that takes one input, a positive integer representing a year, and returns the number of days in that year.

For example, (days-in-year 2008) should evaluate to 366 since it is a leap year, but (days-in-year 2100) should evaluate to 365 since it is not.

7. Define a function named total-days that takes two inputs, the starting and ending years in a range, and returns the total number of days in that range. You may assume that both inputs are positive integers, and that the first input is less than or equal to the second.

For example, (total-days 2008 2010) should evaluate to 1096 since the years in the range consist of 366, 365, and 365 days, respectively.

8. Define functions for converting roman numerals to numbers and back. One function, roman->num will have one input, a list of characters representing a roman numeral. It should return the number value represented by that roman numeral. For example, (roman->num '(X V I)) should evaluate to 16. Conversely, the function num->roman will have an integer as input, and should return the list of characters representing the appropriate roman numeral. The following is a list of the roman letters and numbers they represent: M = 1000, D = 500, C = 100, L = 50, X = 10, V = 5, I = 1.

You may assume the old roman style of writing letters, where 4 is represented IIII and 90 is represented LXXXX. A harder problem, which you may attempt if you like, is to use the modern roman style where 4 is IV and 90 is XC.