CS 210 - Fundamentals of Programming I

Spring 2006 - In-class exercise for 4/18/06

10 points

Names:

This exercise should be completed in pairs. The purpose of this exercise is to continue working with recursive functions.


0. Create a new project, then download file inclass26.cpp from the course webpage under today's date to your project folder. This program is an implementation of the main program that will read in the number of disks and call the function Hanoi to print out the solution to the Towers of Hanoi problem for that many disks.


1. (5 points) Add the prototype and a definition for the Hanoi function developed in lecture. Build and run this program. Make sure it is correct.


2. (5 points) When you are confident your program works correctly, answer the following questions:

a.
What makes the Hanoi function a recursive function?

b.
What is the base (or anchor) case of the Hanoi function?

c.
What are the recursive (or inductive) steps (i.e., what are the recursive function calls) of the Hanoi function?

d.
On the back of this sheet, list the first 10 steps to solving the Towers of Hanoi problem for 4 disks.

When you have completed this exercise, print out your program file and turn it in with one copy of this exercise sheet with your answers to the questions.


Converted using latex2html on Mon Apr 17 22:44:18 CDT 2006