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.ss. Be sure to comment each function as to its behavior.
- Define functions for converting temperatures from Fahrenheit to Celsius,
and vice versa. The formula for converting from Fahrenheit to Celsius is:
tempInCelsius = (5/9) * (tempInFahrehneit - 32)
For example, (fahr->celsius 212) should evaluate to
100, while (celsius->fahr 0) should evaluate to 32.
- Define a function named wind-chill that takes two inputs, a
temperature (in degrees Fahrenheit) and a wind-speed (in miles per hour), and
returns the corresponding wind-chill factor. The formula for computing the
wind chill is:
wind-chill =
| {
| temperature
| if windSpeed <= 3
|
35.74 + 0.6215*temperature +
(0.4275*temperature-35.75)*windSpeed0.16
| otherwise
|
For example, (wind-chill 38 2) should evaluate to 38 since a
wind-speed of only 2 miles per hour has no effect on the temperature of
38 degrees Fahrenheit.
- 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.
- 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.
- 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.
- 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.