(Latest Revision: 10/18/2000)
10/18/00: Corrected "typo" in sample script

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, and C++ classes. You need to understand some sorting and searching algorithms too. It is useful, but not necessary to know how to program with binary search trees. You also need to be familiar with the directions and examples here: http://shalim.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 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 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 character information. This collection is a data structure that can be implemented as a list, ordered list, or binary search tree.

Note: When character.dat is an empty file, the program should detect this and begin its execution with an empty collection of 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 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.

Here is a list of the interactive commands to which the program must be able to respond:

ADD

This command adds a character to the collection. The program prompts the user for the 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 a copy of the collection of characters in response to this command, or it may traverse the original 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 a copy of the collection, or you may do it by marking records in the original collection as "eliminated."

CHECK

The program prompts the user for a 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 suspects were added during the current execution of the program, the program must first rewrite the character.dat file, so that it now contains the most recent version of the character collection.


SAMPLE INTERACTION:

For this example, the character.dat file is empty and all the potential suspects are added by command. The characters entered by the user are shown in boldface.


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 characters in the collection or number of attributes a given suspect may have. You cannot use static allocation for lists of suspects or lists of their 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 do search operations. It has to search for characters and attributes of characters

A "List" may be implemented as an unordered list, as an ordered list, as a binary search tree, some other way.

Note that there is a notion of a list of (criminal suspect) characters and a notion of a list of attributes of a 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.

If you use a binary search tree for your list of characters, then also be careful of the traversal order you use to write the list 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. It's wise to use a post-order traversal. Do you see why?


TEST FILES:

You are responsible for deciding what sort of tests need to be done on your program to check it for correctness. I expect you to design your own test inputs. The sample inputs illustrated in this document are not adequate for thorough testing. Your test scripts must demonstrate adequate code coverage and data coverage. 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 in your class and in other classes. 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, you will lose points. Everything should work fine if your program uses the correct name for character.dat and if it gets all other input from standard input.

If you have any additional questions about this issue, feel free to ask, preferably in class 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: Here is the list of things you have to turn in:
  1. 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.

  2. 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.