CS 3520 Homework 0

Due: Sunday, August 30th, 2020 11:59pm

Difficulty:  ★☆☆☆

Part 0 — Create Handin Account

After installing the uu-cs3520 package as described in the course web page, select the Manage CS 3520 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 uu-cs3520 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.

Use #lang plait at the start of your program, so that it’s implemented in the Plait language.

Part 1 — Implement 3rd-power

Define the function 3rd-power, which takes a number and raises it to the 3rd power.

Your program should include test forms to check 3rd-power on a few inputs.

Example use: (3rd-power 17) should produce 4913.

Part 2 — Implement 42nd-power

Define the function 42nd-power (in the same program), which takes a number and raises it to the 42nd power.

It’s probably a good idea to use functions like 3rd-power to build up to 42nd-power.

Your program should include test forms to check 42nd-power on a few inputs.

Example use: (42nd-power 17) should produce 4773695331839566234818968439734627784374274207965089.

Part 3 — Implement plural

Define plural, which takes a string and returns a string. If the given string ends in “y”, the the result should be the same as the input but with the “y” replaced by “ies”. Otherwise, the result should be the same as the given string with “s” added to the end.

Your program should include test forms to check plural on a few inputs.

Example uses: (plural "baby") should produce "babies", while (plural "fish") should produce "fishs".

Part 4 — Implement energy-usage

Use the following type definition (add it to your program):

  (define-type Light
    (bulb [watts : Number]
          [technology : Symbol])
    (candle [inches : Number]))

Implement the function energy-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.0 or 0.

Part 5 — Implement use-for-one-hour

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).

Part 6 — Handin

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 have defined 3rd-power, 42nd-power, plural, energy-usage, and use-for-one-hour, all in the same program.

The handin process will check that you have defined the right names. It will also run some tests on your programs. If tests fail, then your handin will not be accepted—but you can override that by clicking Submit even if server reports problems. That checkbox won’t override very basic problems, however, such as not using #lang plait or submitting a program that doesn’t compile.

You can double-check that handin was successful by visiting the Solutions and your handins link at the top right of the schedule page. Log in with the account that you created for handin. You can check whether a submission has been uploaded, you can check the time of the upload, and you can download your submission. Solutions and grades for your assignments will appear later in that same place.


Last update: Monday, August 3rd, 2020
mflatt@cs.utah.edu