Assignment 4
Up Assignment 1 Assignment 2 Assignment 3 Assignment 4 Assignment 5 Assignment 6 Assignment 7 Assignment 8 Assignment 9 Assignment 10

 

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 ]

 

  1. Do exercise 6.9 in the text.
     

  2. 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.
     

  3. 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".