Write a program for a police department that has collected a database of information on various suspects for a given crime. (Luckily for you, the department is only investigating one crime at a time.) Each suspect has a set of attributes, such as shifty eyes, a limp, or a parrot on his shoulder. The maximum number of such attributes for any suspect is not known. Your program accepts commands to manipulate the database in order to narrow down the list of suspects, in the hope of pinpointing the villain.
1.The retained criminal information, generated by the previous execution of this program, is input from file "Criminal.mf" at the beginning of each execution of the program.
2.The user inputs commands from the keyboard, in the format shown below. Names and attributes are strings of no more than 20 characters. The program should 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.
1.Responses to user commands are to be written to the screen, as described in the Command Processing instructions below.
2.Echo print each command and show the results of any PRINT commands in a file called "Criminal.trn". You may determine the format of the information in this file; it should be labeled and formatted clearly. A hard copy of this file is turned in with your program for grading.
3.If any new suspects were added (see ADD command), file "Criminal.mf" must be rewritten to contain the updated collection of criminal information.
New suspects can be added to the collection of criminal information using the ADD command. An inquiry consists of a set of commands with respect to a single crime, at the end of which the crime is assumed to be solved. An inquiry must be completed within the execution of the program; it cannot be "saved" to finish on a subsequent execution. After an inquiry is complete, a new inquiry (the investigation of another crime) can begin. Each new inquiry starts over with the entire collection of suspects.
(Some of the labels shown in the sample input are not typed in by the user, but are only printed for clarity. For this example, the "Criminal.mf" file is empty and all the potential suspects are added by command.)
ADD Name: Quickdraw McGraw
Attributes: has a Texas accent
has a body guard
is computer literate
ADD Name: Twingun Morgan
Attributes: has a New York accent
has red hair
smokes cigars
ADD Name: Jackda Ripper
Attributes: has a body guard
bites his fingernails
carries a knife
is computer literate
ADD Name: Annie Getcher Gunn
Attributes: has a New York accent
has red hair
eats Fritos
smokes cigars
ADD Name: Slowdrawl Raul
Attributes: has a Texas accent
carries a knife
is computer literate
eats Fritos
ADD Name: Sloan de Uptake
Attributes: has a body guard
has red hair
bites his fingernails
is computer literate
INQUIRY Code Name: Bang Bang
TIP Tip Info: has a New York accent
CHECK Quickdraw McGraw
TIP Tip Info: has red hair
CHECK Annie Getcher Gunn
TIP Tip Info: eats Fritos
INQUIRY Code Name: Holdup
TIP Tip Info: has a Texas accent
CHECK Slowdrawl Raul
CHECK Sloan de Uptake
TIP Tip Info: is computer literate
INQUIRY Code Name: Tough Stuff
TIP Tip Info: bites his fingernails
CHECK Twingun Morgan
TIP Tip Info: has a body guard
CHECK Slowdrawl Raul
TIP Tip Info: is computer literate
QUIT
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. Suspects must be actually 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.
3.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, but it complicates things.