Due Date: Early bonus: Tuesday, November 19 midnight (5 points)
Final Due Date: Monday, November 25, midnight
This assignment will provide practice with trees, files, reading from directories, and (optionally) inheritance.
(A Makefile and sample input files are accessible in ~ola/cps100e/animal on the acpub system. Be sure to create a subdirectory animal for this problem and to set the permissions for access by prof/uta/ta by typing fs setacl animal ola:cps100e read.)
Files accessible are:
(note: missing functions for the class GuessGame will prevent the code provided from compiling.)
In particular, questions are identified by the string #Q:
at the beginning, so that the information used in the sample run
above is given below.
The user should be allowed to play several games, or to read in a new
file and play with new data. When a new file is read in, or when the
user quits, the current tree should be written to a file in a format
that it can be re-read later. The user should be prompted for the name
of the output file; ideally the file from which the information was read
will serve as a default filename.
For extra credit you should use the DirEntry and
DirStream classes described in the Tapestry book
and used in the function LoadDirectory from Lab 4 (in
the file usepix.cc) to show the user all files that end
with .dat. The first line of a .dat file can begin
with #C: to signify a comment describing the contents of the
file. For example:
The user should be shown the names of each .dat file and
a description of the contents of the file whenever a new file name for
reading a tree is entered.
back to table of contents
Introduction
The game of Twenty Questions can be amusing, especially if the
domain of questions is one you find interesting. For this assignment
you'll write a program that permits the user to play a dynamic version
of twenty questions --- dynamic in the sense that the user can add new
questions. For example, a brief run of a simple version of the program
is shown below. Note that new questions are
added during the run reflecting new "knowledge" in the program.
prompt> guess
file: animal.dat
Does it have feathers [yes/no] yes
Does it live in a barnyard [yes/no] yes
Is it a chicken [yes/no] yes
I win!!!
play again? [y/n] y
Does it have feathers [yes/no] no
Is it a mammal [yes/no] yes
does it have stripes [yes/no] no
Is it a elephant [yes/no] no
I give up: what were you thinking of? kangaroo
please type a question
that has a yes answer for a kangaroo
and a no answer for a elephant: does it hop
play again? [y/n] y
Does it have feathers [yes/no] no
Is it a mammal [yes/no] yes
does it have stripes [yes/no] no
does it hop [yes/no] yes
Is it a kangaroo [yes/no] yes
I win!!!
play again? [y/n] n
Input/Output
The input to the program will be any file in the format below.
Question
Yes Answer (subtree)
No Answer (subtree)
#Q:Does it have feathers
#Q:Does it live in a barnyard
chicken
#Q:is it wise
owl
#Q:does it say "Nevermore!"
crow
#Q:does it gobble
turkey
eagle
#Q:Is it a mammal
#Q:does it have stripes
tiger
#Q:does it hop
kangaroo
elephant
gila monster
The code below will read an input file in this format and build a
tree (passed back via reference parameter root).
The Program
You should write a program that prompts for an input file (but see
extra credit
for an option to display all input files). The program
should build a "guessing" tree and use this to allow the user to play a
game. As shown above, if the program doesn't guess correctly, the user
should be able to add a new animal (or new person, or new food, or new
whatever) and a new question that will then be added to the tree.
Extra Credit Input
( this is worth 5 points)
#C:Animals -- mammals, birds, reptiles, etc.
#C:Duke Courses --- hard courses, easy courses, etc.
Coding Requirements
You should write a class GuessGame, part of which is provided
to you (see the files guess.h) and guess.cc.
You'll need to write several
member functions, both private and public. You may decide it's
worthwhile to design and implement other classes. If you need help with
a Makefile for this, just ask. You'll need to extend the relatively
simple playgame.cc that's provided for you.
Grading Standards
This assignment is worth 24 points. Points will be awarded as follows:
| Behavior | Points |
|---|---|
| Plays Game | 4 |
| Writes File/Reads File | 4 |
| Adds new information to tree | 4 |
| User-interface (good prompts, robust, easy to read/play) | 4 |
| Coding Style (class, comments, etc.) | 4 |
| README | 2 |
| Sample Data Files | 2 |
To submit your assignment, type:
To submit the extra credit assignment, type: