Tutorial 3: Structs and Symbols and Predicates (oh my!) (September 26-28, 2007)Tutorial this week attempts to cover most of the material from lecture module 3 ("New Types of Data") in preparation for your first midterm. The pace may be a little quicker than previous weeks, so be prepared, and be sure to work out problems on your own and check the solutions when they are posted on Friday afternoon. Good luck on your first exam! Remember the new first step in the design recipe, Data Analysis and Design. It'll be necessary for most of the examples here.
A simple way to represent a date in some unspecified year is by a pair of numbers for the month and the day. The following functions should work with dates specified in this way. Write a function Write a function Write a function Although they have many nice properties, the numbers represented by Scheme do have the limitation that they are finite. To overcome this limitation, define the symbols The square of positive or negative infinity is always positive infinity. Using this fact, write a function Now write two functions, Write a function For the purposes of this tutorial, a weather reading consists of four pieces of information: air temperature (in degrees Celcius), wind speed (in km/hr), humidity (as a percentage), and an indication of whether or not precipitation is currently falling from the sky. This is entirely inaccurate, but assume that the type of precipitation which falls depends only upon the air temperature, as follows: Under -1 degrees, it will be snow, greater than 2 degrees it will be rain, and in between it will be sleet. So write a function In Canada, two measures are used to indicate how hot or cold it "feels" outside when the air temperature is not sufficient. These are called the humidex and the wind chill. If the air temperature is T, the humidity is H and the wind speed is V, then the wind chill Wand humidex U are calculated as follows: W = w1(T) + w2(T) V0.16 The functions w1, w2, u1 and u2 are coded in Scheme and given as follows: (define (w1 T) (+ 13.12 (* 0.6215 T))) (define (w2 T) (- (* 0.3965 T) 11.37)) (define (u1 T) (- T (* (/ 5 9) 10))) (define (u2 T) (* (/ 5 9) 6.112 (expt 10 (/ (* 7.5 T) (+ 237.7 T))) (/ 1 100))) Now design and write a function Some weather data has been lost and we're trying to recover it. We have the actual air temperature and the temperature it "felt like" at the time (according to the function you just wrote), but the complete weather reading has been lost. So write a function Also, some values wouldn't make sense, such as a humidity less than 0 or greater than 100, or a wind speed less than 0. If there is no weather reading that could possibly be consistent with the values given, return the symbol |
This file generated Monday, December 17th, 2007 using PLT Scheme and WebIt!