(last revision 11/05/97) (10/28/97 -- Moved back due date for Lev #2.) (11/05/97 -- Moved back due dates for Lev #3 and Final Level) ////////////////////////////////////////////////// CS 3100 PROGRAMMING ASSIGNMENT #03 -- America's Most Wanted ////////////////////////////////////////////////// Level #2 DUE October 31, 1997 Level #3 DUE November 06, 1997 Final Level DUE November 11, 1997 Please read the class documents entitled: programAssignmentRules, sampleProgramSubmission-level01, sampleProgramSubmission-level02, sampleProgramSubmission-level03, howToMakeTestScript-level01, sampleTestScript-level01, sampleTestScript-level02, and sampleTestScript-level03 before beginning to do this programming assignment. You will find the documents under "CourseDocuments" in the class directory. Also, be sure to ask questions in class! America's Most Wanted 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 1. The retained criminal information, generated by the previous execution of this program, must be input from a file named criminal.dat at the beginning of each execution of the program. You must determine the format you will use for this file. The file is used to reconstruct the criminal information data structure, a binary search tree. 2. The user inputs commands from the keyboard (standard input) in the format shown below. Names and attributes are strings of no more than 30 characters. The program must not be case sensitive (e.g. 'JOE' and 'Joe' 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 in the Command Processing instructions below. OUTPUT 1. Responses to user commands are to be written to the screen (standard output), as described in the Command Processing instructions below. 2. If any new suspects were added (see ADD command), file criminal.dat must be rewritten to contain the updated collection of criminal information. COMMAND PROCESSING New characters can be added to the 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 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. ADD Add a character to the data structure. Prompt 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. Each new inquiry starts over with the entire collection of suspects. 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 deleting 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. Be sure to include the suspect's name and inquiry code name. CHECK Prompt the user for a character's name. Check the set of active suspects to see if this name is there. Print out an appropriate response. PRINT Print the set of active suspects (those who have not yet been eliminated). QUIT If any new suspects have been added during this execution of the program, rewrite the criminal.dat file. Be careful how you go about saving the records. The traversal order affects the shape of the tree that is built on the next execution of the program. Terminate the program. SAMPLE INPUT (For this example, the criminal.dat file is empty and all the potential suspects are added by command.) 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 Fritos 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 Fritos 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 Fritos 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 "criminal.dat" ... Done. Goodbye. DATA STRUCTURES 1. There is no upper bound to the number of suspects or number of attributes for a given suspect. You cannot use an array-based list to store the suspects or the attributes for a given suspect. 2. The CHECK operation must be very efficient, because suspects are continually being pulled off the street for questioning and we must decide whether to let them go, or ruthlessly interrogate them. Using a simple linked list to store the suspects is not sufficient. You must use a binary search tree. 3. Suspects must actually be deleted from the structure when they are eliminated by TIP information. Because you destroy the list of suspects, as suspects are eliminated by TIP information, each inquiry should work on a copy of the original tree. HINT: When processing a TIP, what order of traversal of the tree do you need to do, and why? 4. TIP is executed much less often than CHECK and hence can be less efficient. It is acceptable if processing a TIP command requires searching the whole data structure of (active) suspects. Thus, a list of attributes can be stored with each suspect. You do not have to link all the suspects with the same attributes together. (This could potentially make for a much faster TIP operation.) You may do this if you want to, but it complicates things. This program uses strings, lists, and binary search trees. Implementations of these data structures are included in the Pascal-code and C-code subdirectories of this directory. There are Pascal and C versions of each data type. The C versions are "machine translations" of the Pascal versions. The translations were generated by the p2c program. None of the code is guaranteed to be error-free. The Pascal code is taken from a textbook (Dale & Lilly), and some bugs have been detected and corrected. The C code has simply been generated with p2c and placed here without being checked in any way. If you decide to use it, you should proof read it, and be prepared to get some compiler errors that you will have to fix. TESTING Test your program on appropriate inputs. Also, as part of this assignment you 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. I will be making files containing inputs to test your programs. I will run your programs in a mode like this: myNameForYourProgram < myinput > myoutput If I have to change my input files in order to get your program to accept them, you will lose points. The example input above should contain the information you need to make your program compatible. If you have any additional questions, feel free to ask, preferably in class where the rest of the students can get the answer at the same time.