Project 4
Library Simulation II
Posted:
| Sunday 11/10/02
|
Design Document Due:
| before midnight, Sunday 11/17/02
|
Project Due:
| Before midnight, Sunday 11/24/02
|
Notes
|
- 16 Nov 2002
The description of the LibraryBook class states
"It must use a pointer to the LibraryPatron who has checked out the book."
Using an actual pointer variable will not work in this instance.
If a LibraryBook actually points to a LibraryPatron and the array of
LibraryPatrons is reallocated, then the pointers in the checked out
LibraryBooks are all "dangling". So when is a pointer not a pointer?
When it's an index. Instead of using an actual pointer, try storing the
patron's index into the LibraryPatron array. Since we're not deleting
patrons and you're not shuffling the patrons when a new one is added,
a patron's array index remains constant. Ask your TA or instructor
for a more thorough explanation if needed.
Alternatively, the LibraryPatron's unique Library card number
could also be kept.
- 15 Nov 2002
As noted on the discussion board, there were some inconsistencies
between the description of each class' print() method and the required
outputs. A print() method is still required, but the specification of
the print() methods have been removed. The output requirements have
been updated to reflect all required data.
- 12 Nov 2002
It is NOT necessary to dynamically allocate all
data members and local variables in project 4. The only
required dynamic allocation is for the arrays of LibraryBooks
and LibraryPatrons in the Library class.
A note on overdue fine calculations so that we all
do them the same....
If a book is checked out on day N for 7 days,
it is due on day N + 6 and is overdue on day N + 7
|
Objectives
To better understand the use of inheritance and polymorphism
in object oriented design and programming by
- Designing classes which are derived from other classes
- Implementing derived and base classes
- Using these classes in an application
Background
Inheritance and polymorphism are two fundamental features of OO
design and programming. They allow us to group related objects
that allow us to share common behaviors yet provide specialized
behavior when necessary. In this project you will be implementing
base classes and derived classes and using virtual functions.
Project Description
This project is a revised version of Project 3. Hopefully you can
reuse code from your project 3 solution. If you are not satisfied with
your project 3 solution, you may start with one of
partial solutions for project 3 provided by your instructors.
We will once again simulate a simple library. The library will consist of
a set of library books and set of library patrons
(people who borrow and return books). Commands will be read from a command file.
This simulation will expand on project 3 in several ways
- There will be more data for a book, incluing book type (sci-fi, biography, etc)
- There will more data for a patron, including the patron's age which is used to
classify a patron as an Adult or a Child
- Library patrons will be assigned library cards
- Overdue book fines will be calculated and paid
- Your program will simulate the passing of time
Your program will read commands from a file to perform the following functions.
- Change the date.
When the date changes, fines are calculated for each
overdue book.
- Add a book to the library
- Add a patron to the library
When a patron is added to the library, he is assigned a unique
library card number.
- Check out a book to a patron
- Allow a patron to return (check in) a book
When a libarary book is returned, the overdue book fee (if any) is paid.
- List all books in the library
- List all books in the library which are of a specified type
- List all patrons of the library
- List all adult patrons of the library
- List all child patrons of the library
- List all books currently checked out to a particular patron
Project Specification
Class Design Guidelines
Your program must include the C++ classes listed below. Some classes have
special restrictions.
The following restrictions apply to all classes.
- All data in all classes must be private.
- A default constructor, a copy constructor, an assignment operator
and a destructor must be written for all classes, even ff the compiler's default
behavior is sufficient.
- The methods for the base classes are specified below. You MAY NOT
add any additional public methods.
- All allowable member functions may be overloaded.
- As always, you are free to add whatever private methods and private data
you deem necessary for any class.
- All class designs must follow basic OO principles of encapsulation
and data hiding.
Reminder:It is poor design for library methods to be
reading data from the input file.
- No friends are permitted.
Required Classes
The Library Class
The Libarary class must contain the following data.
- A dynamically allocated array of LibraryBooks.
Initially, the array is allocated with enough space for one LibraryBook.
The capacity of the array is doubled whenever the array becomes full.
- A dynamically allocated array of LibraryPatrons.
Initially, the array is allocated with enough space for one LibraryPatron.
The capacity of the array is doubled whenever the array becomes full.
The library class provides public methods to support the operations listed above in the
project description.
In addition,
- The library assigns unique library card numbers to each new patron.
The first library card is number 1001.
- The library assess fines for overdue books at the beginning of each day
Adults are charged $0.25 per day per book
Children are charged $0.10 per day per book
- The library considers fines for a book as paid when the book is checked in
- Children (under 12) may check out books for only 7 days
- Adults (12 and over) may check out books for 14 days.
There is no need for an overloaded insertion operator for this class.
The Book Class
The book class is a BASE CLASS that contains the title, author, and type of the book.
A book is uniquely identified by its title.
The book class supports only constructors, accessors, mutators,
a virtual destructor, and a virtual print( ) method.
You may optionally write the operator<< function for the Book class.
LibraryBook class
The LibraryBook class publicly inherits from the Book class. Its design is
up to you, but with the following requirements.
- It must use the Date class to store the library book's due date.
- It must use a "pointer" to the LibraryPatron who has checked out the book.
- It must support a virtual print() function
The Person Class
The Person class is a BASE CLASS that contains the name and
age of the person. The Person class supports only constructors,
accessors, mutators, a virtual destructor, and a virtual print() method.
An overloaded insertion operator may be provided.
The LibraryPatron class
The LibraryPatron class publicly inherits from the Person class.
Its design is up to you, but at a minimum, it must support a print()
method.
A library card number uniquely identifies a LibraryPatron.
The Date class
Dates are an integral part of virtually every computer system.
At a minumum dates (and times) are used to record when certain important events happen.
Often date calculations are an important part of your applications.
- What day of the week is it?
- Is this a leap year? (By the way - do you know the "complete" definition of leap year?)
- How many days are there between two dates (subtraction)
- What day will it be in N days (addition)
- Many more
The obvious way to store a date (year, month, day) is not always the best (does
anyone remember Y2K?) because of the difficulty it imposes on date cacluations.
For example, suppose you wanted to know what day it is 500 days from now.
Your calculation would have to consider
issues such as crossing month and year boundaries and crossing leap years.
An often used alternative is to use an integer to
store a "day number". Some date in the past (such as Jan 1, 1970) is chosen
to be day #1. Every night at midnight, the integer is incremented. This approach
makes adding and subtracting dates less problematic. This is the design you
must implement. For our project, day 1 will be Tuesday, January 1, 2002,
which was not a leap year. You may assume that our simulation will not cross
into 2003. (Do you see a potential Y2K type problem with this design?)
The Date class must support the following operations.
Other operations may be provided, but must be justified in your design.
- constructor(s) of your choice
- a method to change the day to a new specified day
- a print( ) method that outputs the date in WWW DD MMM YYYY format
(eg. Tue 01 Jan 2002).
The insertion operator for the Date class is optional.
Other Requirements and Restrictions
In addition to the
course coding standards, your project must adhere to the following requirements
Assumptions
You may assume the following:
- If the command file can be opened, it will be in the
syntactically correct format described below.
- Dates will never go backwards and will not cross into 2003.
For output formatting purposes only (not for storing data), you may
assume
- Book titles are no more than 20 characters
- Patron and Author names are no more than 15 characters
- Book types are no more than 10 characters
The Command File
The command file contains command words and data for each command where
appropriate. To minimize the amount of work necessary for parsing the
command file, each command word and data item will be on a separate line.
Blank lines may occur anywhere within the file and should be ignored.
The command file contains the following command words and data items.
This file is the same basic format as for project 3. A sample file
is provided in Mr. Frey's public directory.
/afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p4/p4commands.dat
Students are encouraged to test their programs with short command files
that focus on one or two related commands. After all commands have
been tested as independently as possible, create command files with
many varied commands
All command words will be in UPPERCASE. The data for each command
is listed below under the command word, in order.
- ADDBOOK -- add a book to the library
book's title
book's author
book's type
- ADDPATRON -- add a patron to the library
patron's name
patron's age
- BOOKS -- print books in the library
all -- print all books in the library
OR
a book type - print all books of this type in the library.
- CHECKOUT -- check a book out of the library
book's title
patron's library card number
- CHECKIN -- return a book to the library
book's title
- DAY - change the current day
new day number
- PATRONSBOOKS -- list all books checked out to a patron
patron's library card number
- PATRONS -- list all patrons of the library
all - list all patrons
OR
adults - list only adults patrons
OR
children - list only child patrons
Sample Output
There are three required outputs from this program
- a list of books in the library
- a list of all books currently checked out to a particular patron
- a list of patrons of the library
No sample output is being provided. You may format your
output in any neat, easy to read format you feel is appropriate
as long as the required information listed below is present.
Your program must handle all situations in which there is nothing
to print (i.e. no books or no patrons).
1. List of books
This output must include the following information for each book.
- Title
- Author
- Type
- Status - checked in, checked out, or overdue
- If checked out or overdue list
the book's due date and the name of the patron who has borrowed the book
- If overdue list the amount of the fine due
2. List of Books for a Patron
This output must include the following information
- The patron's name, age and library card number
- The title and author of each book checked out by this patron
including those which are overdue and any fines owed by the patron
for the book.
3. List of Patrons
This output is a neatly organized list of patron names.
Project Make File
You are required to submit a make file with this project. The grader should
simply need to type "make Proj4" and your project should compile and link to an
executable called Proj4. The grader should also have the ability to do a
"make clean" and "make cleanest."
See the
CMSC 202 syllabus for links to more information on make files.
Grading
- 70% - Correctness
- The program behaves the same way that the sample does and the code meets ALL of the project specification.
- Projects that do not dynamically allocate memory or fail to deallocate
dynamic memory as specified in the
requirements above
will be subject to substantial deductions and may
recieve a score of zero.
- 10% - Design
- Your design was submitted on time.
- You have made a reasonable attempt at a first draft of the required class
definitions. (See the
specification for design4.txt.)
- 20% - CMSC 202 Coding Standards and Documentation
Project Submission
You must use separate compilation for this project. You should submit
the following files:
- Your make file
- Proj4.C that contains main ( )
- A header file and implemntation file for the Date class
- A header file and implemntation file for the Library class
- A header file and implemntation file for the Book class
- A header file and implemntation file for the Person class
- A header file and implemntation file for the LibraryBook class
- A header file and implemntation file for the LibraryPatron class
- Any auxiliary header and implementation files you deem necessary
Submit as follows:
submit cs202 Proj4
You can check to see what files you have submitted by typing
submitls cs202 Proj4
Don't forget about compiling/linking and testing your code with submitmake
and submitrun. See the new page on
submit tools for details.
More complete documentation for submit and related commands can be found
here.