CISC 181 Project 3
The Library's Assistant
Due: May 19, in Class


The board of the local library has decided that computers are indeed not "just a fad", and have agreed to computerize their operations. The goal is to have all books and library cards online, and to keep track of what books are out, etc. You've been hired to design software to manage the library, its books, and its users. This project is designed to give you experience with making and using classes.

1. Program Design Requirements

To design the software, you need to think about several objects, their attributes, and what actions they can do. There are four classes (objects) in this program. book, library card, library, and user. Partial specifications for each of these classes are given below. Suggestions: There are to be no friends in this program (Exception: you may implement operator<< for classes Book and Card). Think carefully before you write a lot of code! Think about the objects, their attributes and actions, and their public interface.

2. Main function Listing

Here is a listing of the main program - proper design generally leads to tiny mains. Studying this code will likely give you hints about how the Library object generally works.
// File: proj3.cc
//       main function for library app
#include 
#include 
#include "library.h"
#include "utility.h"
#include "user.h"

int main() {
   ifstream inFile("library.data");
   Library theLibrary( inFile );
   User theUser;
   char Command;

   while( (Command = theUser.GetCommand()) != 'X' )
      theLibrary.DoCommand( Command );

   return EXIT_SUCCESS;
}

3. Source Files

Here are some source files. Study these to get a feel for how the program is to work.
///file: user.h
//      header file for class user - an interesting
//      class with no data!

#ifndef User_H_
#define User_H_

class User {
   public:
        User();         // initialize the user object
                        // by showing the menu
        char GetCommand();      // return a legal char from KB

   private:
        void ShowMenu();        // show the available choices
        Bool IsLegal(char cmd); // return true if cmd is legal
};

#endif

//file: user.cc
//      implementation file for class user.

#include 
#include 
#include 
#include "utility.h"
#include "user.h"

User :: User() {
        ShowMenu();
}

Bool User :: IsLegal(char cmd) {
   // New commands can easily be added.
   if(  (cmd == 'C') || (cmd == 'B') || (cmd == 'O') ||
        (cmd == 'I') || (cmd == 'X') || (cmd == 'M') )
        return True;
   else
        return False;
}

void User :: ShowMenu() {
   // A good technique for setting up a menu,
   // so that it is extensible.
   // ...ignore warnings from compiler....
   static char *menu[] = {"\n\tC:\tshow all library Cards",
                          "\tB:\tshow all library Books",
                          "\tO:\tcheck Out a book",
                          "\tI:\tcheck In a book",
                          "\tM:\tdisplay this Menu",
                          "\tX:\teXit and close the library",
                          NULL
                         };

   int k = 0;
   cout << "   Available Commands: " << endl;
   while( menu[k] )
      cout << menu[k++] << endl;

}

char User :: GetCommand() {
   char cmd;

   while( True ) {
        cout << "\n> ";
        cin >> cmd;
        cmd = toupper(cmd);

        if( IsLegal(cmd) ) {
           if( cmd == 'M' )
                ShowMenu();
           else
                return cmd;
        }
        else {
           cout << "\n*** Unrecognized command+++." << endl;
           cout << "Type M to see menu." << endl;
        }
   }

Additional things you must do:

  1. Enhance the library so that new cards and books can be created. You'll have to add a couple of librarian functions, and expand the user menu.
  2. You need some kind of offline storage. Have your program save all books and cards into a file at the end of the program, and read this file in to initialize everything at the start of the program. How you do this is all up to you.

Grading:


What to hand in:


Other Important Information: