Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program for a police department that has collected a database of informa

ID: 3534360 • Letter: W

Question

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.

Command

Processing

ADD

Add a suspect to the Suspects data structure. Prompt the user for the suspect's name and a list of attributes. ADD commands can be issued only before an inquiry begins.

INQUIRY

Prompt user for code name of this inquiry. Once the inquiry has begun, do not allow the user to issue the ADD command until this inquiry is complete.

TIP

Prompt user for the tip information (a particular attribute). Process the tip, reducing the set of current suspects by deleting suspects who do not match the attribute mentioned in the tip. If there is only one suspect left in the set of active suspects, print out a message indicating that the crime is solved. Be sure to include the suspect's name and inquiry code name. This terminates the current inquiry.

CHECK

Prompt the user for a suspect'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.mf" file. Be careful about 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.

        (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

PRINT

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.

Command

Processing

ADD

Add a suspect to the Suspects data structure. Prompt the user for the suspect's name and a list of attributes. ADD commands can be issued only before an inquiry begins.

INQUIRY

Prompt user for code name of this inquiry. Once the inquiry has begun, do not allow the user to issue the ADD command until this inquiry is complete.

TIP

Prompt user for the tip information (a particular attribute). Process the tip, reducing the set of current suspects by deleting suspects who do not match the attribute mentioned in the tip. If there is only one suspect left in the set of active suspects, print out a message indicating that the crime is solved. Be sure to include the suspect's name and inquiry code name. This terminates the current inquiry.

CHECK

Prompt the user for a suspect'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.mf" file. Be careful about 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.

Explanation / Answer

Your assignment is to 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.



Input

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.

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.



Output


Responses to user commands are to be written to the screen, as described in the Command Processing instructions below.

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

If any new suspects were added (see ADD command), file "Criminal.mf" must be rewritten to contain the updated collection of criminal information.



Command Processing

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.

ADD Add a suspect to the Suspects data structure. Prompt the user for the suspect's name and a list of attributes. ADD commands can be issued only before an inquiry begins.

INQUIRY Prompt user for code name of this inquiry. Once the inquiry has begun, do not allow the user to issue the ADD command until this inquiry is complete.

TIP Prompt user for the tip information (a particular attribute). Process the tip, reducing the set of current suspects by deleting suspects who do not match the attribute mentioned in the tip. If there is only one suspect left in the set of active suspects, print out a message indicating that the crime is solved. Be sure to include the suspect's name and inquiry code name. This terminates the current inquiry.

CHECK Prompt the user for a suspect'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). You will actually just print to a file.

QUIT If any new suspects have been added during this execution of the program, rewrite the "Criminal.mf" file. Be careful about 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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote