User-Defined Methods and Recursion
Due: Monday, Oct 8, 5:00 PM
[ Note: the due date has
been postponed till Thursday, Oct 11, 5:00 PM ]
-
Do exercise 6.9 in the text.
-
Do exercise 6.14 in the text. Your method should be of
the form "GenerateQuestion (num1, num2)", where num1 and num2 are
the two random numbers for a given round. GenerateQuestion should then
print the question to the user, get the response, see if it's right, query
again if it's wrong, and eventually terminate when the user gets it
right. Then some outer loop will start the process again by generating
two more random numbers and calling GenerateQuestion again.
-
Do exercise 6.15 in the text. Your recursive method
should have the form "Hanoi (n, first, second, third)", where:
 |
"n" is the number of disks, and |
 |
"first", "second", and
"third" indicate peg numbers, and are each either 1, 2, or 3. |
So a call "Hanoi (10, 3, 1, 2)" should be
interpreted as "Move 10 disks from peg 3 to peg 1 using peg 2 as a
temporary holding area".
|