Weight: 100 points. Please hand in via online
dropbox.
-
Book problems: 2.2.3, 2.2.5 (Part 2 only), 2.3.1.
-
Use the design recipe from lecture 2 to develop the following program:
It takes one number as input. If the input is even, we square it, and
if the number is odd, we return 0. However, the program CANNOT use
conditionals, and can only use arithmetic operations (addition,
multiplication, division, exponentiation, etc).
Follow the recipe carefully and in the correct order. This means,
first, write down the contract and purpose. Second, develop examples
(hand in 5). Third, write the actual function. Finally, test the function
(using at least the examples you developed ahead of time).
For this exercise, AFTER you have written your examples, you can discuss
how the function can be written with other students.
Hint: Exponentiation of negative numbers should be very useful!