On this page:
1 Designing a function with 1 input
2 Designing a function with 2 inputs
3 Designing an animation
4 The table method
8.6.0.14

Lecture 4: The design recipe

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

1 Designing a function with 1 input

Always follow the design recipe.

Exercise 1. 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 1
 
; 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 lecture4. 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 2. 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.

2 Designing a function with 2 inputs

Exercise 3. Design a function named mftokm that converts a distance in miles and feet to a distance in kilometers. To simplify the arithmetic, assume that one mile is 1.6 kilometers, and one mile is exactly 5280 feet. Hint: If you need to review how to write a template, 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.

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.

4 The table method

The Beginning Student Tables tool is available online for your use.

Exercise 4. Use the table method to design a function ctof that converts a temperature in Celsius to a temperature in Fahrenheit. Submit your table as a screenshot, a photo, or a comment.

Exercise 5. Use the table method to design a function combine-digits that combines two digits (each an integer between 0 and 9) into an integer between 0 and 99. The first given digit should become the first digit of the output (in other words, tens). The second given digit should become the second digit of the output (in other words, ones). Submit your table as a screenshot, a photo, or a comment.