Due: Tuesday, August 30th, 2011 10:45am
After installing cs5510-handin.plt as described in the course web page, select the Manage CS 5510 Handin... menu item from DrRacket's File menu. Change to the New User panel, and pick a username and password. (Use your real name and real Utah student ID, so that we can connect your homework submissions with you.)
You will have to install cs5510-handin.plt for DrRacket on each different filesystem that you use to get a Handin button. However, after creating a handin account once from any machine, you can use DrRacket's Handin button on any other machine.
Define the function 42nd-power, which takes a number and raises it to the 42nd power. You'll need to use the expt operator.
Your program should include test forms to check 42nd-power on a few inputs.
Example use: (42nd-power 17) should produce 4773695331839566234818968439734627784374274207965089.
Define string+ (in the same program), which takes two arguments. Each argument can be either a number or a string, and the result is always a string. Numbers should be converted to strings using number->string, and the string form of the two arguments should be appended using string-append.
Your program should include test forms to check string+ on a few inputs.
Example use: (string+ "hello" 17) should produce "hello17".
Use the following type definition (add it to your program):
(define-type Light [bulb (watts number?) (technology symbol?)] [candle (inches number?)])
Implement the function enery-usage, which takes a Light and produces the number of kilowatthours of electricity that the light uses in 24 hours. Your function will need to use (type-case Light ....).
As always, include relevant test forms.
Example uses: (energy-usage (bulb 100.0 'halogen)) should produce 2.4, while (energy-usage (candle 10.0)) should produce 0.
Implement the function use-for-one-hour, which takes a Light and produces another Light that represents the given light source after it is used for another hour. Assume that a candle burns one inch per hour (unless it is already gone), and assume that a lightbulb is the same after one hour of use.
Example uses: (use-for-one-hour (bulb 100.0 'halogen)) should produce (bulb 100.0 'halogen), while (use-for-one-hour (candle 10.0)) should produce (candle 9.0).
Click the Handin button in DrRacket to submit your homework. The Handin button submits whatever is in DrRacket's definitions area, so click Handin after you ave defined 42nd-power, string+, energy-usage, and use-for-one-hour, all in the same program. The submission process will check that you have defined the right names.
Last update: Friday, August 5th, 2011mflatt@cs.utah.edu |