CS
3050, Spring 2006
Programming Assignment 6
Due Monday, May 30, 2006
Building a Data File with Primary and
Secondary Indexes
In this lab we will create and
manage a data file of books and its indexes with a program written in
C++. The format of the book records is:
- Size (two-byte binary integer),
- Have/Not Have ('1' or '0', 1-byte character signifying "true" or
"false"),
- ISBN (10 characters),
- Author(s) (up to 256 characters),
- Publisher (up to 256 characters),
- Title (up to 256 characters).
The fields will appear in the order given above. Author,
Publisher, and Title fields will be terminated with the character "|"
as a delimiter. The fixed-size fields Size, Have/Have Not, and
ISBN
will not be terminated with delimiters.
The program supports
the following operations:
- To build or append to a data file ............. bf
- To show a data file ......................................... sf
- To find a record by ISBN ........................... fp
- To find a record by publisher .................. fs
- To create index files ..................................... ci
- To stop the program ..................................... quit
The primary index will use ISBN for the key and the byte offset for
the reference number. The secondary index will use either
Publisher as the key and the primary key as the reference number. In
the secondary index, for each secondary key, you should maintain its
reference numbers in sorted order. You may use any of the
implementations that we have discussed in class for the secondary index
(e.g. arrays or linked lists).
The program will do the following:
1. Do a scan of the datafile and create a simple primary index and a
secondary index in main memory.
2. Be able to perform a sequence of operations of the following types:
- Search (both on primary
and secondary keys). Search the appropriate index and retieve the
record using the byte offset from the data file, then print it to the
screen in human-readable form.
- Insert: read from
the keyboard all of the fields for a record, append the record to the
data file and make the corresponding instertion to the indexes.
After each search, wait for the user to press a key on the keyboard
before processing the next operation to allow the user time to read the
results of the search.
The following files are provided:
Data: Lab6.dat
Files courtesy of Jordan Erro:
Main: Lab6.cpp
Classes:
Book.h
Buffer.h
PrimaryIndex.h
SecondaryIndex.h
You will first need to read, understand and document the .h files, then
write the .cpp files for the classes. Once you get things working you
are free to modify the programs to make them more robust, as long as
you maintain the required functionality.
(Please note that these files have been tested on the sol in the cs
domain, you should probably use "save as" rather than cut and paste.)