CS 2401 Assignment #9

Due Date: Monday, November 21 or Tuesday, November 22, depending on the day of your lab.

Objective: The goal of this assignment is to practice the use of trees.

Assignment: Solve Programming Problem 3 on pp. 640-641 of the textbook.

Comment: Let us illustrate how the textbook envisions the corresponding tree. In the beginning, this tree has the following form:

        Does it have legs?
        /               \
       /                 \
   Is it a cat?       Is it a snake?
According to the assignment, once we are in the node, the user's answer YES leads to the left child, while the answer NO leads to the right child.

When we are in a leaf, the answer YES leads to the computer's happy statement "I win! Continue?", while the answer NO triggers a computer response "I give up. What is it?"

In the book's example, after the user answered NO to the question "Is it a snake?", the computer asks the user for the new animal (earthworm) and a new question that helps distinguish snakes from earthworms. With this new information in place, the tree takes the following new form:

        Does it have legs?
        /               \
       /                 \
   Is it a cat?    Does it live underground?
                    /              \
                   /                \
          Is it an earthworm?    Is it a snake?
When the user guesses a fish, the computer adds fish as a new object prompted by the user and a new question to distinguish between fishes and snakes:
        Does it have legs?
        /               \
       /                 \
   Is it a cat?    Does it live underground?
                    /              \
                   /                \
          Is it an earthworm?   Does it live in water?
                                  /              \
                                 /                \
                            Is it a fish?     Is it a snake?
and so on.