( Latest Revision: 03/15/2005 )

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 its very first tasks. It is your responsibility to design the format you will use for character.dat.

The program must use character.dat to reconstruct its collection of shady-character information. You must implement this collection as a (in-memory) binary search tree keyed on names of shady characters.

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 must begin an interaction with the user. The user inputs commands from standard input in the format shown below in the examples.

Names and attributes in the input are strings of no more than 30 characters. The program must not be case sensitive. For example, all the strings in this set: {JOSEPH, JosEpH, Joseph} should be considered identical. To simplify the processing, assume that everyone in the world has a different name.


PROCESSING AND OUTPUT: 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 must prompt 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:

In this particular 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.

THINGS TO NOTICE ABOUT THE SAMPLE INTERACTION:
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 implementing your lists of attributes, you needn'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 are "risks". You need to take some extra precautions. If your program will traverse the tree while deleting some nodes then the deletion of a node could cause the traversal to go "off track" - do you see why? For a job such as this it's wise to use a post-order traversal.


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 (just as an example, suppose that file is named 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 turning in two hardcopy versions of your program and you will be sending me two e-mail messages.

With regard to the e-mail please follow these rules: Here is the list of things you have to turn in:
  1. At the start of class on first due date, turn in hardcopy of a level three version of the source code. Don't include code from the assignment directory (code I gave you) that you are incorporating into your program, but do include the rest of your source code.

  2. 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. In the e-mail 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

  3. At the start of class on the second due date, turn in a hardcopy of a final level version of the source code. Don't include code from the assignment directory (code I gave you) that you are incorporating into your program, but do include the rest of your source code.

  4. 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. In the e-mail 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.