Assignment 3 -- Police Blotter
Due: Tuesday, April 23, 2002
- Practice using structs and binary search
As a public service, the local police department keeps a file of
city residents who have marked their belongings with a unique
4-digit ID code (an integer). When the police recover a missing
item, they would like to use a computer program to match the item
with its original owner via its ID code. Your assignment is to
write a program to do just that.
Your program will use two external data files for input,
and they can be downloaded from the Course Materials
section of BlackBoard.
You are not allowed to alter the input files in any way.
The files are described below.
- registered.txt is the file containing information
about the people who have registered their items with the
police. Each line of the file contains 1 record telling the
4-digit ID code of the item, the owner's first name, the owner's
last name, and the owner's phone number. For example, a line
1900 John Smith 555-4321
means that John Smith with phone number 555-4321 has registered
an item with the unique ID 1900. The last line of this file
will be the integer "0" (without the quotes) that you can use
as a sentinel to tell you when you've reached the end of the file.
Note that this file is sorted in order of increasing ID codes.
- recovered.txt contains information about the recovered
items. Each line of the file pertains to one item telling its
4-digit ID code and a one-word description of the item.
For example, a line such as
means that the police recovered a refrigerator whose unique ID
is 1408. This file also has 0 as its last line that you can use
as a sentinel.
Here's how your program will work.
When you have finished processing the recovered.txt file,
you should have an external output file containing a
well-formatted report that the police can use to
reunite the orphaned items with their long-lost owners.
The report should look something like this:
- First, use an array of structs to store the registration
information contained in the registered.txt file.
Each struct will contain information on a single item (its ID,
owner's first name, last name, and phone number). You may
assume that there will be no more than 100 items in the
- Process the recovered.txt file by doing the following
with each line of the file:
- Read in the ID of the recovered item and search the array of
structs for that ID. You are required to use a binary search
to do this. Remember, a binary search requires you to
know the number of items you're searching through.
That means you'll need to figure out the number of structs
in your array!
- If you find a match for the lost item, print the
code number, owner's name, owner's phone number, and item
description to an output file (not to cout). If there is no
match, print the ID code, "NO MATCH", and the item description
to the output file.
ID code Owner Phone Description
1900 John Smith 555-4321 television
1177 NO MATCH N/A car
1408 NO MATCH N/A refrigerator
1046 Sally Chan 484-9843 violin
Your report doesn't need to look exactly like this, but it
should be formatted neatly into columns with headings
for each column.
Remember to use functions to break up this problem into
smaller pieces. Some of the functions you might use here are:
You may use other functions as well.
- a function to create the array of structs from
- a function for performing a binary search
- a function to process the recovered.txt file
This assignment is worth 50 points, divided as follows:
- 20 pts for correct and complete output
- 10 pts for a correct implementation of a binary search
- 10 pts for good documentation including output formatting
- 5 pts for good C++ language usage including your use of structs
- 5 pts for good testing of your code (don't forget to paste your
case results into the source code!)
Remember to turn in both a paper and an electronic copy of your
project on BlackBoard. Name
your file with your FULL NAME along with the assignment number (e.g.
Having trouble? Don't wait until the last minute! Come see me and get
Administrative statementProgramming assignments are
individual projects. I encourage you to talk to others
general nature of the project and ideas about how to pursue it. However,
technical work, the writing, and the inspiration behind these must be
substantially your own. If any person besides you contributes in any way
project, you must credit their work on your homework. Similarly, if you
information that you have gleaned from other published sources, you must
them as references. Looking at, and/or copying, other people's programs
written work is inappropriate, and will be considered cheating.