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.
- User- This class defines the user command interface. You have the complete source for this class. Notice that there is no data for the class User, and yet a constructor is still used! The purpose of the class User is to get legal commands from the keyboard and pass them back to Library.
- Book- This class defines what data makes up a book object (the book object's attributes), and what actions a book object can take. The data consists of:
- Title of book
- author of book
- a ISBN (book) number
- the status: -1 - at the bindary, 0 - on the shelf, 1 - checked out
- who has the book (card id of the holder - NOT their name)
All of this data is to be private. A Book object needs to be able to initalize itself, print itself, destroy itself (destructor), copy itself (copy constructor), be assigned to (operator=), identify itself by returning its book number, get the status, set the status, get and set who has the book. No other actions are needed.
- Card- This class defines data and actions associated with a library card object. The data (attributes of a Card) consist of
- the card holder's name
- the card holders phone number
- a card id number
- the number of the book checked out (or 0, if no book)
Again, all of this data needs to be private. A Card object needs to be able to initialize itself, destroy itself, copy itself, be assigned to, return the book number, and set the book number. No other actions are necessary.
- Library- This class defines the data and actions for the library, and will contain instances of the Book, and Card classes nested in it (composition). The data for Library consists of:
- current number of cards
- current number of books
- an array of books
- an array of cards
The Library object needs to be able to initialize itself, process transactions, find a book, find a card, etc. (You'll have to fill in some of the details.) All of the library data nd actions are to be private except for, the constructor, destructor, and the DoCommand function.
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:
- 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.
- 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:
- Correct Program Operation: 65%
- Test runs: 10%
- Following Good Coding Standards / Program structure: 25%
What to hand in:
- A listing of the program with appropriate comments and formatting.
- Several runs of the program, showing ALL of the programs features. This may take
several runs. That is fine.
Other Important Information:
- I hate to waste time even writing this, but all your work on the projects
MUST BE YOUR OWN. Specifically, you are NOT allowed to
work with another student, share or discuss solutions, or copy code from another student. Failure to adhere to this rule with be dealt with per University plagarism policies. Further, if you cheat on this project, the odds of you doing well on the test, and future CIS courses, are slim. Please do you own work.