(Latest Revision: 03/20/2003)
(3/20/2003 -- correction under "PRELIMINARIES" -- you need to program binary search trees)
Lists, Strings, Dictionaries: A Program that Helps
Search for America's Most Wanted Criminals
PRELIMINARIES:
Before working on this problem you need to know how to program with lists,
strings, binary search trees, and C++ classes. You need to understand some
sorting and searching algorithms too. You also need to be familiar with
the directions and examples here:
http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/
THE ASSIGNMENT:
Your assignment is to write a program for a (pretend) police department. The
program maintains a database of information on various "shady characters."
Each shady character has a set of attributes, such as shifty eyes, a limp, or
a parrot on his shoulder. A user of the program can run commands that help
narrow down the list of possible suspects in a crime investigation.
INPUT:
The program works with a file named character.dat.
Character.dat contains a series of zero or more records. Each record
consists of data about one particular shady character. When the program
begins execution, it must input the previously-saved character.dat
file as one of it's very first tasks. You must design the format you will use
for character.dat.
The program uses character.dat to reconstruct its collection of shady
character information. You must implement this collection as binary search
tree keyed on name of shady character.
Note: When character.dat is an empty file, the program should detect this and
begin its execution with an empty collection of shady character information.
After the program gets the data from character.dat it begins an
interaction with the user. The user inputs commands from standard input in
the format shown below in the examples. Names and attributes are strings of
no more than 30 characters. The program must not be case sensitive (e.g.
'JOSEPH' and 'Joseph' are the same name). To simplify the processing, you can
assume that names are unique -- that is, no two criminals use the same
"professional handle." The commands are discussed in detail below.
PROCESSING AND OUTPUT:
The user of the program can add a new shady character to the program's
collection using the ADD command. The INQUIRY command signals the start of an
inquiry. An inquiry consists of a set of TIP, CHECK, and PRINT commands
pertaining to the search for the perpetrator of a single crime. The end of an
inquiry is signalled when the program receives an ADD, QUIT, or a new INQUIRY
command. An inquiry cannot be "saved" to finish on a subsequent execution of
the program. TIP, CHECK, and PRINT commands may ONLY be issued during an
inquiry.
Below is a list of the interactive commands to which the program must be able
to respond. The QUIT command may write a new character.dat file. Otherwise
these commands do all reading from standard input and all
writing to standard output.
ADD
This command adds a shady character to the in-memory list of shady characters.
The program prompts the user for the shady character's name and a list of
attributes.
INQUIRY
The program must prompt the user for the code name of this inquiry. Other
actions will probably be necessary, but their nature depends on your choice of
implementation. For example the program may make an in-memory copy of the
collection of shady characters in response to this command, or it may traverse
the original in-memory collection, marking each record in some way.
TIP
The program must prompt the user for the tip information -- a particular
attribute. The program then processes the tip. It reduces the set of current
suspects by eliminating suspects who do not match the attribute. If, after
doing this reduction, there is only one matching suspect, or no matching
suspects left, the program prints out an appropriate message. When you
program this message, be sure to include the suspect's name and the inquiry's
code name. You may decide to implement this operation by doing deletions from
an in-memory copy of the collection, or you may do it by marking records in
the original in-memory collection as "eliminated."
CHECK
The program prompts the user for a shady character's name. It then checks to
see if that name matches any of the names of the active suspects. The program
prints out an appropriate response.
PRINT
The program prints the names of all the active suspects (those who have not
yet been eliminated).
QUIT
This command causes the program to terminate. However, if any new shady
characters were added during the current execution of the program, the program
must first write a new version of the character.dat file, so that it now
contains the most recent version of the collection of shady characters.
SAMPLE INTERACTION:
For this example, the character.dat file is empty at the time the program
begins its run. All the shady characters are inserted with ADD commands
performed by the user of the program. The inputs made by the user are shown
in boldface. The output of the program is shown in plain typeface (not
bold).
ADD
OK, we are now adding a character to the database.
Name of Character: Quickdraw McGraw
Attributes: has a Texas accent
has a body guard
is computer literate
ADD
OK, we are now adding a character to the database.
Name of Character: Twingun Morgan
Attributes: has a New York accent
has red hair
smokes cigars
ADD
OK, we are now adding a character to the database.
Name of Character: Jackda Ripper
Attributes: has a body guard
bites his fingernails
carries a knife
is computer literate
ADD
OK, we are now adding a character to the database.
Name of Character: Annie Getcher Gunn
Attributes: has a New York accent
has red hair
eats bullets
smokes cigars
ADD
OK, we are now adding a character to the database.
Name of Character: Slowdrawl Raul
Attributes: has a Texas accent
carries a knife
is computer literate
eats bullets
ADD
OK, we are now adding a character to the database.
Name of Character: Sloan de Uptake
Attributes: has a body guard
has red hair
bites his fingernails
is computer literate
INQUIRY
OK, we are now conducting an inquiry.
Enter a Code Name for this Inquiry: Bang Bang
TIP
Enter Tip Info: has a New York accent
CHECK
Enter Name of character: Quickdraw McGraw
Quickdraw McGraw is not a match.
TIP
Enter Tip Info: has red hair
CHECK
Enter Name of character: Annie Getcher Gunn
Annie Getcher Gunn matches.
TIP
Enter Tip Info: eats bullets
ALERT! That leaves only one
suspect in the Bang Bang inquiry: Annie Getcher Gunn
INQUIRY
OK, we are now conducting an inquiry.
Enter a Code Name for this Inquiry: Holdup
TIP
Enter Tip Info: has a Texas accent
CHECK
Enter Name of character: Slowdrawl Raul
Slowdrawl Raul matches.
CHECK
Enter Name of character: Sloan de Uptake
Sloan de Uptake is not a match.
TIP
Enter Tip Info: is computer literate
INQUIRY
OK, we are now conducting an inquiry.
Enter a Code Name for this Inquiry: Tough Stuff
TIP
Enter Tip Info: bites his fingernails
PRINT
The remaining matches are:
Ripper, Jackda
Uptake, Sloan de
CHECK
Enter Name of character: Twingun Morgan
Twingun Morgan is not a match.
TIP
Enter Tip Info: has a body guard
CHECK
Enter Name of character: Slowdrawl Raul
Slowdrawl Raul is not a match.
TIP
Enter Tip Info: carries a knife
ALERT! That leaves only one
suspect in the Tough Stuff inquiry: Jackda Ripper
QUIT
OK, saving database to file "character.dat" ... Done. Goodbye.
DATA STRUCTURES:
There is no upper bound to the number of shady characters in the collection or
number of attributes a given shady character may have. You cannot use static
allocation for lists of shady characters or lists of their attributes.
When it comes to implementng your lists of attributes, don't take the word
"list" too seriously. Choose a data structure that supports all the operations
you need, or augment an existing data structure to give it the additional
capabilities you require. Consider that the program has to search for
attributes of characters. You may implement a "list" of attributes as an
unordered list, as an ordered list, as a binary search tree, or some other
way.
Note that this program incorporates the notion of a list of shady characters
and the notion of a list of attributes of a shady character. That
makes two different kinds of lists. It may therefore be worthwhile to develop
a "list" class that uses a template for the list item. On the other hand you
may want to do something different to simplify your programming work. The
decision is yours.
Be careful of the traversal order you use to write the list of shady
characters to your character.dat file. Pre-order is the one to use. Do you
remember why from your previous study of binary search trees?
If you prune a copied tree in response to the TIP command, there is a danger
of corrupting the data in the tree. Do you understand this? You need to take
some extra precautions. If your program will traverse the tree and call for
the deletion of some nodes during the traversal. In that case it's wise to
use a post-order traversal. Do you see why?
TEST FILES:
You are responsible for deciding what sort of tests you need to do on your
program to check it for correctness. I expect you to do thorough "black box"
testing. I will base a significant portion of your grade on your testing
procedures. The sample inputs illustrated in this document are not
adequate for thorough testing. I expect you to design your own test inputs.
Also, you must interact directly with your program in order to create an
adequate test script. Your script will not contain enough information for me,
your reader, if you redirect standard input to a file of prepared inputs. I
won't be able to easily follow the interaction between you and the program.
However, You can probably save some time by preparing files of inputs and by
pasting sections of these files into your shell-window while running your
program. We can discuss this and other testing "tricks" in class.
As part of the testing for this assignment you also must ask at least one
other person to operate your program, get his or her opinion of the interface,
and make any improvements that are called for.
When I do my testing of your program, time will be of the essence because I
will be testing the programs of many students. I will prepare files
containing inputs to test your programs. I will start with an empty file
named character.dat. I will place commands for standard input in a
file, say called myinput, and I will run your program in a mode like
this:
myNameForYourProgram < myinput > myoutput
I will then examine the contents of myoutput to see if it differs
significantly from the output file I get when I run my own solution program.
If I have to change my input files or the names of my input files in order to
get your program to accept them, I will take away a significant number of
percentage points from your score. Everything should work fine if your
program uses the correct name for character.dat, if it implements the
user commands in accordance with the specifications I gave you, and if it does
not do any extra input or output that I didn't ask for.
If you have any questions about testing issues or anything else, feel free to
ask, preferably in class or on the CS3100@waganupa.csustan.edu mailing list
where the rest of the students can get the answer at the same time.
WHAT TO TURN IN:
You will be sending me two e-mail messages. Please follow these rules:
- Always send me e-mail as plain text in the main message body. Never send
me attachments.
- I will tell you what subject line to use with each message, and I need
you to use exactly the subject lines I give you. (I get hundreds
of e-mail messages at a time and your subject line allows me to sort
messages.)
Here is the list of things you have to turn in:
- Send the following items to me by e-mail before midnight on the
first due date:
A level three version of the source code and a script showing your test
runs. Include all the source files (*.h files and *.cpp files) that are
required to compile the program into an executable image -- everything I
need so that I can compile and test your program. Combine all the source
files and the script into one
shell archive file
and e-mail me the archive file with the subject line:
CS3100,prog3.3.
- Send the following items to me by e-mail before midnight on the
second due date:
A final version of the source code and a script showing your test runs.
Include all the source files (*.h files and *.cpp files) that are
required to compile the program into an executable image -- everything I
need so that I can compile and test your program. Combine all the source
files and the script into one
shell archive file
and e-mail me the archive file with the subject line:
CS3100,prog3.f.
Note that there are no spaces in the subject lines given. It is important
that you do not insert any spaces. My e-mail address is: john@ishi.csustan.edu.
DUE DATES:
For the due dates, see
the class schedule.