On this page:
1 Booleans and conditionals
2 Intervals
3 Enumerations
8.6.0.14

Lecture 6: Multiple cases

This assignment is due on Tuesday, September 6 at 11:59pm. Submit it using Handin as assignment lecture6.

1 Booleans and conditionals

Exercise 1. Copy the three conditionals below into your Definitions Window. What are their results?
; Exercise 1
 
    (cond [(< 100 32) "solid"]
          [(<= 32 100 212) "liquid"]
          [(> 100 212) "gas"])
; = ???
; = ...
; = "liquid"
 
    (cond [(< -40 32) "solid"]
          [(<= 32 -40 212) "liquid"]
          [(> -40 212) "gas"])
; = ???
; = ...
 
    (cond [(< 450 32) "solid"]
          [(<= 32 450 212) "liquid"]
          [(> 450 212) "gas"])
; = ???
; = ...
Show step-by-step calculations by adding comments. Use the Stepper to confirm that your steps are correct.

Optional: Learn about more features of the Stepper.

Exercise 2. Design a function called bp-points to convert the patient’s systolic blood pressure into a coded value. Use the same table we used for the respiratory rate: Remember to follow the design recipe whenever you design or write a function. In particular, every type mentioned in a signature must be introduced by a data definition, except for these well-known types: Number, Image, String, Color, Boolean. Hint: If you need to review how to write a signature and a purpose statement, you can watch this additional video.

The code written in the videos above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

2 Intervals

start the problem set early. templates seem overrated at first, but very helpful. do all parts of a lecture. office hours help a ton. on youtube, DrRacket Academy has great videos that give further explanation for things we do in class.

The code written in the video above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Exercise 3. Let’s design an animation of a rocket landing. This animation should have two parts: first, the rocket falls from the sky; second, the rocket stops at ground level and stays there.

So, design a function called land-rocket that takes a time t as input and returns a scene that contains a rocket. The scene should be an image that is 200 tall. Horizontally, the rocket should be centered in the scene. Vertically, the distance between the rocket and the top of the scene should be t. But if t is greater than 200, then the rocket should have landed so it should be at the bottom of the scene.

Hint: to begin with the design recipe, write a new data definition for what a Time is.

3 Enumerations

The code written in the video above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Exercise 4. Design a function called next-tl that takes a traffic light as input and returns the next traffic light. Hint: you can reuse the data definition and template written in the video above.

Exercise 5. In order to handle clicking and dragging and moving of the mouse, we will need to design functions that take a MouseEvent as input. Here is the data definition for a MouseEvent:
; A MouseEvent is one of:
; - "button-down"
; - "button-up"
; - "move"
; - "drag"
; - "enter"
; - "leave"
Write the template for a function that processes a MouseEvent. Make your template look like a function called process-mouseevent, and do not put it in a comment.

Hint: The data definition for a MouseEvent is an enumeration. Review how to write a template for an enumeration by watching this additional video.

Optional: Read Chapter 4 of the textbook.