CS 3520 Homework 0

Due: Friday, August 25th, 2023 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 shplait at the start of your program, so that it’s implemented in the Shplait language.

Part 1 — Implement to_the_3rd

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

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

Example use: to_the_3rd(17) should produce 4913.

Part 2 — Implement to_the_42nd

Define the function to_the_42nd (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 to_the_3rd to build up to to_the_42nd.

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

Example use: to_the_42nd(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 check forms to check plural on a few inputs.

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

Part 4 — Implement electricity_usage

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

  type Light
  | bulb(watts :: Int,
         technology :: Symbol)
  | candle(inches :: Int)

Implement the function electricity_usage, which takes a Light and produces the number of watthours of electricity that the light uses in 24 hours. Your function will need to use match with bulb and candle cases.

As always, include relevant check forms.

Example uses: electricity_usage(bulb(100, #'halogen)) should produce 2400, while electricity_usage(candle(10)) should produce 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 light bulb is the same after one hour of use.

Example uses: use_for_one_hour(bulb(100, #'halogen)) should produce bulb(100, #'halogen), while use_for_one_hour(candle(10)) should produce candle(9).

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 to_the_3rd, to_the_42nd, plural, electricity_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 shplait 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: Thursday, November 9th, 2023
mflatt@cs.utah.edu