You are on page 1of 4

COMP 1631 Assignment 6 (Book Warehouse Inventory Database)

Given:
Electronic Copy Due:
Hard Copy Due:

Tuesday, November 25, 2014


Tuesday, December 2, 2014 before 11:59 pm sharp
Wednesday, December 3, 2014 before 11:00 am sharp

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 last name

a C-string of maximum length 12 characters

author initial

a char

inventory number

an int, each book in the database is given a unique identifying


number

location

a C-string of 4 characters
(example: shelf h, bin 03 would be h-03)

title

a C-string of maximum length 20 characters

comment

a C-string of maximum length 24 characters

quantity on hand

an int, representing the number of that particular book on hand or


the number that have been backordered (for example, if a
bookstore orders 10 of a book when there are 0 on hand, a
backorder would be recorded as a quantity on hand of -10)

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

Delete an existing entry from the book database.


Book titles are not necessarily unique, so the inventory number is used to
identify the book record that is to be deleted. The user enters an
inventory number and the array is searched for a record with this

Page 2 of 4

number. Since the array is not ordered on inventory number, it may be


necessary to search the entire array.
If the record is not found, an appropriate message is written. If the record
is found, then all its data are displayed and the user is asked to confirm
the deletion. If the user confirms, then the record is deleted by shifting
all entries following it in the array up one position.
4. Quit

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

loads the book database array from a specified file

writefile

writes the book database array to a specified file

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.

Create a directory called a6.


Copy your .cpp source file into a6. This directory should not yet contain any other files,
including the executable program.
cd into a6.
Begin a LINUX script session.
Run the pwd command.
Use ls -al to display the contents of the directory (that is ell ess dash ay ell, not ell ess dash
ay one).
Run g++ to compile your, and use the -o option to give the executable program the name books.
Run the books program and tell it to loads the books.dat file that can be found in the course
directory. Execute the following actions in this exact order. Skip any actions that have not been
implemented in your program. Some of the information may not be required depending on how
you have implemented the operations. When quitting the program, tell it to save to a new file
named books2.dat.
LIST ALL
LIST BY NAME Xerxes the Greek
LIST BY NAME He
REMOVE
inventory number 1 (confirm: n)
REMOVE
inventory number 42 (confirm: y)
REMOVE
inventory number 100
LIST ALL
QUIT
give the file name books2.dat
Execute the command ls al books2.dat.
Use cat to display the source code in your .cpp file.
Terminate the script session by using the exit command.
cd up one level, out of a6.
Submit your assignment electronically using submit (the file to submit will be called a6 you are
submitting the entire directory and all its contents) to ppospisil.
Print a hard copy of your typescript file.
Place your hard copy in your instructors BLUE assignment box
Department.

4 outside the Computer Science

Page 4 of 4

You might also like