CSE 143, Summer 2000

Homework 2

Library Database Recovery


introduction | objectives | overview | specifications | written work
resources | hints and tips | submission | files | footnotes | announcements

introduction

Your local public library uses a C++ program to keep track of its book collection. The system maintains records of which books are checked out, to whom, when they are due, and how much overdue fines are (based on the number of days a book is overdue). Last week, a serious accident involving an unabridged dictionary caused a hard drive crash and destroyed the latest version of the book records. Your friendly neighborhood librarians, with insufficient municipal funds to hire full-time programmers, have asked you to donate your time as a programmer to restore the data.

Luckily, the librarians had some important data backed up, so you have something to start from: a full catalogue of the books, and a "transaction log." The transaction log consists of a record of each check-in (borrow return) and check-out (return borrow), ordered by date, so you can reconstruct the current book data1 by processing these transactions in order. In addition to losing data, however, they lost some code, so your task will include writing a class from scratch to fit in an existing code framework.

objectives

The following concepts and technical knowledge are the focus of this homework:

overview

Under files below, you are provided with the following:

The two data file formats (book catalogue and transaction log) are described under resources below. All provided code is commented, and those comments supplement the information given in the instructions on this page.

Your programming tasks are as follows:

  1. read and understand given code in main.cpp, library.h, and library.cpp
  2. read and understand given code for class Date in date.h and date.cpp
  3. design the LibraryBook class, and create file lbook.h to contain the LibraryBook class declaration and initializations of any related constants
  4. create file lbook.cpp to contain the LibraryBook class implementation
  5. complete and test the program, using book catalogue and transaction log data files we supply, as well as at least one additional file of each type created by you (You will be asked to turn in your test data files. Your files may consist of our data with additional books and transactions added by you.)

Your primary task in this homework is to write the LibraryBook class from scratch. Each instance of this class corresponds to a book in the library's collection. As with all classes, you should separate your class declaration and definition in two files: lbook.h and lbook.cpp.

Read the provided code carefully. In addition to studying the specifications given below, identifying LibraryBook instances in the provided code and seeing how they are used (e.g. how member functions are called) will give you important clues about how the class should be written.

specifications

class LibraryBook

When you are finished, header file lbook.h should contain the class declaration for LibraryBook, as well as any constants the class might use. Remember that a class declaration consists of member variable and member function declarations---no definitions. Source file lbook.cpp should contain the member function definitions.

We provide a partial specification for the class in this section. Names and types of member variables are given here, but for member functions, we only provide you with the name of each function and what each is supposed to do. This means that you will have to study main.cpp, library.h, and library.cpp to deduce the correct member function prototypes, i.e. number of arguments and their types. (You can do this by looking for places in the code where LibraryBook member functions are called and examining the types of their arguments.)

Class LibraryBook should have the following private member variables:

After studying main.cpp and library.cpp, you should see that LibraryBook has two constructors (Can you find where they are invoked?). Both of these must be in the class declaration:

For the second constructor, you can deduce the exact order and types of the arguments by seeing how LibraryBook instances are declared and initialized in library.cpp.

So far, we've specified the member variables (what's stored for each book) and the constructors (how new instances of LibraryBook are declared and initialized). By studying library.cpp, you can conclude that LibraryBook has some additional public member functions (listed below). It might be helpful to print a copy of library.cpp and circle the places where these methods are invoked.

data files for testing

Data files books.txt and trans.txt are provided for testing, but you are also required to create a pair of data files of your own for testing (one book catalogue file, one transaction log file) and turn them in with your code. The data file formats are described in detail under resources below. You may write your own files from scratch, or you may use the provided data files as a starting point, as long as you modify them substantially (i.e. by adding or replacing at least three or four entries in each file).

You should name your book catalogue data file mybooks.txt and your transaction log file mytrans.txt.

other requirements

Finally, keep the following technical requirements in mind:

written work

In addition to your turn-in receipt print-out, you are required to submit the following on paper. This may be handwritten if it is 100% legible. If your TA can't read it easily, he may require you to resubmit it word-processed. It must be on a separate sheet of paper, and not embedded in comments in the program. Please write your name and section on the sheet.

  1. It may be that your project does not meet the specifications given above. Write a short statement that either says you are in full compliance with the requirements, or lists the ways in which you are not (things that don't work, etc.).

  2. You may decide that the program you turn in is not ideal in some respects. If your boss or fellow programmers were looking at it, what do you think they would find to like or dislike? Write a short paragraph evaluating the project. You could focus on the way it's designed and programmed, or focus on what usefulness the program has.

  3. Write a statement of acknowledgements. If you took code from anywhere (except what the assignment gives you directly), say where you got it from and who the original author is. You must do this even if you modified the code considerably. If you received help on the assignment from anyone other than course staff (TA, instructors, consultants), please list the name of the person and the extent of their help.

resources

You are already provided with all the file I/O code you need in library.cpp, but the data file formats are provided here for reference. This information will be useful for creating test data of your own.

book catalogue data file format

Each book has a three-line entry:

  44921
  The C++ Programming Language 
  Stroustrup, Bjarne 

The first line has the book's ID number, an integer. The second line has the book's title, and the third, the book's author. The book entries are not in any particular order.

transaction log data file format

Each check-in/check-out transaction has a one-line entry:

  01 27 2000 52 i 44921

The first three fields represent the date of the transaction as three integers: month, day, year. (This example transaction took place on January 27, 2000.) The next field (52, in this example) is the user ID number (an integer) of the person checking in/out a book in this transaction. The next field is a single character, either an 'i' or an 'o' (a lowercase letter O, not zero), where 'i' signifies that this transaction is a check-in, and 'o' signifies a check-out. Finally, the last field holds the book ID number (an integer) of the book being checked in/out. These transaction records should be ordered by date, from oldest to most recent.

hints and tips

submission

As always, be sure to read the official homework submission policy, linked on the course web on the Homework page. You will have to submit your work (1) via the web using the page linked below and (2) on paper.

Your web turn-in should consist of the files listed below. The form will not accept any other files.

Your paper submission should consist of the following:

As stated on the official homework submission policy page, all parts and pages of your paper submission must be stapled together and sealed in a large envelope. (Don't expect the TA to have a stapler in section, either!) You can lose points for not following these instructions (crazy, but true!) For this homework, you will submit your paper submission in quiz section on the due date at the top of this page.

files


footnotes

1Protection and recovery from loss is an important issue for companies and organizations which rely on databases for their operation.  The technique used in this homework is very typical of what is commonly done in database management systems.  A full "save" of all the records is made occasionally (perhaps once a week or less), and a log of all "transactions" or changes to the database after the full save is maintained.  (You might ask yourself why a full save isn't done more often.)  In case of a disaster, the database is recovered by first restoring it to an old state from the most recent full save, and then using the log file to roll forward the updates.


announcements

If any clarifications or changes need to be made for this homework, they will be posted to the cse143-announce e-mail list and linked here.


Return to main Homework page...
Last modified: Sun Jul 9 21:23:26 PDT 2000

Save paper. Read documents on the web and, if you must print, print two-sided. Recycle this when you're done.