On this page:
1 The origin of parentheses
2 Designing a function with 1 input
3 Designing an animation
8.12

Lecture 4: The design recipe🔗

This assignment is due on Tuesday, January 16 at 11:59pm. Submit it using Handin as assignment lecture4. Your submission is only accepted if the message “Handin successful” appears.

1 The origin of parentheses🔗

Exercise 1. Put the missing closing parenthesis in the right place:

(place-image (scale 2 bicycle horizontal-position 150 (empty-scene 300 300))

Put the fixed expression in a comment.

Exercise 2. Answer each problem below with one arithmetic formula. Indent each formula properly.
  1. At the market, I bought an apple for $1 and a sandwich for $5. What is the total that I spent? The answer to this problem is (+ 1 5), so put this in your Definitions Window:
    (define part1 (+ 1 5))

  2. At the market, I bought an apple for $1 and a sandwich for $5. Because a sandwich is a prepared food item, it is taxed 7%. What is the total that I spent? Define a constant named part2 with your formula.

  3. At the market, I bought a baked apple for $1 and a sandwich for $5. Because both are prepared food items, both are taxed 7%. What is the total that I spent? Define a constant named part3 with your formula.

  4. At the restaurant, I ordered a baked apple for $1 and a sandwich for $5. Both are taxed 7%, and I also decided to pay 20% tip on the amount before tax was added. The tip is not taxed. What is the total that I spent? Define a constant named part4 with your formula.

  5. At the restaurant, I ordered a baked apple for $1 and a sandwich for $5. Both are taxed 7%, and I also decided to pay 20% tip on the amount after tax was added. What is the total that I spent? Define a constant named part5 with your formula.

  6. Like the last probem, but what if I rounded up the final amount to the nearest dollar (using the ceiling function)? Define a constant named part6 with your formula.

2 Designing a function with 1 input🔗

Always follow the design recipe.

Exercise 3. Design a function named ctok that converts a temperature in Celsius to a temperature in Kelvin. Start by copying the following list of steps into your Definitions Window:
; Exercise 3
 
; 1. Data definitions
 
; 2. Signature, purpose, header
 
; 3. Function examples
 
; 4. Function template
 
; 5. Function definition
 
; 6. Testing

Submit your work using Handin as assignment lecture3. Be sure to submit on time. Submit early and submit often, any number of times until the deadline!

Important Note Whenever you write a function in this class, you need to follow the design recipe.

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.

Exercise 4. Turn all your function examples from comments into automatic tests.

Keep submitting your work any number of times until the deadline. Be sure to submit on time. Watch out for submitting to the wrong assignment.

Optional: Learn more about automatic testing.

3 Designing an animation🔗

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.

Optional: Read Chapter 3 of the textbook.