Professional Documents
Culture Documents
Given:
Electronic Copy Due:
Hard Copy Due:
Objectives
To learn how structures and arrays of structures can be used to consolidate mixed data types.
To work with standard one-dimensional array algorithms (searching and deleting).
To gain experience working with sorted data.
To work with C-strings and the string library.
To continue to develop your C++ coding, documenting and debugging skills.
To learn to read and modify an existing program.
To continue to build your problem solving and procedural abstraction skills.
The Problem
There is a partial solution for a book warehouse inventory database in the course directory (a6.cpp).
The database contains one record for each book that the warehouse sells. The book database will be
accessed online by a user who will enter requests from the keyboard and inspect the results on the
screen.
You are to complete the program according to the specifications below. No changes are allowed to
the existing code.
The book database is read from a file and stored in an array of records. Records are arranged in the file
in alphabetic order by author last name, within last name by author initial, and then by book title if
necessary. The record format is:
Field Name
Description
author initial
a char
inventory number
location
a C-string of 4 characters
(example: shelf h, bin 03 would be h-03)
title
comment
quantity on hand
Page 1 of 4
Processing
The program is menu-driven. Once the data has been loaded, the user is repeatedly provided with a list
of choices from which a book database command is selected. The operations provided are:
1. List All
Display all data for every book in the database. Use a format of
Field Descriptor
Value
with the fields written one per line and aligned in two columns, with the
width of the first column being longest Field Descriptor plus a couple of
trailing spaces.
2. List by Name
Display the data for all books that match an authors last name or partial
last name.
The user will enter the first part of the authors last name, which must be
at least one character and can extend up to the complete name. The
operation will search the book database for matching entries. A match
occurs when the author last name field begins with the partial name
entered. The comparison is case-sensitive, i.e. the uppercase and
lowercase versions of a letter are considered to be different. Use the
string function strncmp for the comparison (described in Section 8.1 of
the textbook).
Since the book database is in alphabetical order on author last name,
there is no need to search the entire array of records. Stop the search as
soon as a name that is alphabetically greater than the partial name
entered is reached.
Display the data for all matching entries in the same format used for the
List All operation. If there are no matching entries, then write a message
stating this.
Since this command only uses the last name it can be read using cin >>
When reading a c-string by this method the read will terminate when the
user enters any whitespace element, space tab or newline. Thus, it is
possible for the user to enter more input, ex Clark is a great
author. Only Clark will be read as the author name and the rest will be
left in the input buffer. Therefore, your code must remove any additional
user input on this line.
3. Remove
Page 2 of 4
Write the array of records to a data file, because it may have been
altered, and terminate execution of the program.
Program Design
The following parts of the program are complete and must not be altered:
the main program
loads the array from the file, prints the menu, and invokes
a function to process the user request
readfile
writefile
The following operations are stubbed out. You may not alter their calling interfaces:
list_all
list_by_name
remove
You must also define a function called write_entry that takes a single book record and outputs it as
specified in the description of the List All command. This function must be used whenever a book
record is displayed. You may define any additional helper functions that you feel are appropriate.
Documentation Required
The program has basic documentation for the main program and for all the functions. You must
complete the main program ID block. As well, each of the stubbed out functions that you must
complete, are mostly documented. However, the purpose statement is missing and you must complete
these. As well, any additional functions that you add must be completely documented.
Testing
Use the file books.dat as test data while developing the program. It is a text file, so you can display
it on the screen or print it.
An executable solution for this assignment is available in the class directory, in the file a6soln. It has
been made available so that you can see how the program should work.
Page 3 of 4
Submission Instructions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Page 4 of 4