Saint Louis University |
Computer Science 180
|
Dept. of Math & Computer Science |
Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
You are to write a program that plays a game similar to
"Twenty Questions." The user of the program will think of a
secret item (e.g., Lisa) from a predetermined
category (e.g.,
Notice that a given decision tree may be incomplete. For example, this particular tree does not include Lisa as a possible answer. In this case, the computer's algorithm will not succeed, but we can use that failure to further adapt the decision tree. We use a simple model for "learning" based on expert advice. As an example, here is a possible round of our game (user's responses shown in bold):
The category is Simpson's characters Is the character female? Yes Is the character an adult? No Is your character Maggie? No I give up. What was your answer? Lisa What would be a good question to help me distinguish between Maggie and Lisa? Does the character play the saxophone? For Lisa, would the proper answer to that question be Yes or No? Yes Thank you.
Based upon this round, the updated decision tree would appear as:
Your goal is to write a complete program for playing rounds of such a game and for being able to save and load your internal decision tree as a data file. The overall flow of your program should offer the following menus. Upon start up, the program should offer:
Welcome. Please enter N to start a new category L to load an existing categoryFor a new category, the user should immediately be prompted for a description of the category (e.g.,
After the initial startup is complete and a new or existing tree has been loaded, the program should repeatedly offer the user the following options:
P to play a round of the game S to save the current information to a file Q to quit
None!
We've provided many drivers and classes in past assignments. This time, we'll have you do it all. Although you might consider relying on the full-blown binary tree class from the textbook or lectures, we strongly recommend that you develop a simpler tree structure specifically for this assignment.
In order to save knowledge from one session to another, we want your program to be able to save/load a decision tree to/from an underlying text file. We require that you adhere to the following unambiguous file format.
The first line of the file states the category.
As an example, here is the precise file for our decision tree involving Simpson's characters.
Simpson's characters Q: Is the character female? Q: Is the character an adult? A: Marge Q: Does the character play the saxophone? A: Lisa A: Maggie Q: Does the character ride a skateboard? A: Bart A: Homer
For your interest, we provide several larger decision tree that have been created by myself and past students.
Your program will need to deal with input and output from the user as well as from files. Fortunately, treatment of these two forms is quite similar due to the abstraction of a "stream" in C++. Standard I/O with the user is acommplished with the console streams cin and cout. Interactions with a file are accomplished with an instance of the fstream class.
Please note as well that we have designed the specifications for this project so that you can always read and write one line at a time. So for gathering input you should rely predominantly on the getline function.
Please refer to Ch. P.9 of the text and pages 15-16 of our Transition Guide for further discussion and examples about these I/O issues.
Please submit the following:
Your entire source code.
One interesting decision tree that you have created and saved.
A readme file provding a brief overview of your design.
The assignment is worth 10 points.