Assignments | Class Photo | Computing Resources | Course Home | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 180
Data Structures

Michael Goldwasser

Fall 2008

Dept. of Math & Computer Science

Programming Assignment 06

Decision Trees

Due: Monday, 1 December 2008, 11:59pm

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.

Collaboration Policy

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.


Contents:


Overview

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., Simpson's Characters). The computer's tries to determine the secret by asking a series of yes/no questions such as Is the character a female? Internally, the computer relies upon a model known as a decision tree. As an example, here is a simple decision tree for Simpson's characters.

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 category
For a new category, the user should immediately be prompted for a description of the category (e.g., Simpson's Characters) and one example of an item from that category (e.g., Homer). For loading an existing category, the user should be prompted for a valid filename (we will discuss the file format below).

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


Files We Are Providing

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.


File Format

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.

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.

These files can also be found at turing.slu.edu:/Public/goldwasser/180/programs/decision/


Input/Output in C++

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.


Files to Submit

Please submit the following:


Grading Standards

The assignment is worth 10 points.


Michael Goldwasser
CSCI 180, Fall 2008
Last modified: Tuesday, 18 November 2008
Assignments | Class Photo | Computing Resources | Course Home | Lab Hours/Tutoring | Schedule | Submit