Assigned |
Monday, February 2, 2004 |
Due |
11:59pm Sunday, February 15, 2004 |
Update |
Several public functions are added in the
ADT of PatronRecord, Book and Periodical. |
Correction |
In PatronRecord class, the methods for
the library functions should be CheckOutBook, returnBook,
recallBook, renewBook. It was written as returnItem, recallItem,
renewItem by mistake. |
Update |
You are allowed to have any accessors in addition to accessors for Book
and Periodical classes (e.g., accessors for CheckedOutList class).
|
Abstract Data Types (ADTs) are a central idea of this course and of object-oriented programming in general. Recall that an ADT has two parts: (1) a description of the elements that make up the type, and (2) a description of the operations allowed on instances of the type. The ADT idea is implemented in C++ as a class. This project will give you some exercise in using ADTs.
Another important OOP idea, parametric polymorphism, is implemented in C++ by templates. This project will give you some practice with C++ templates.
You will be given a makefile, include headers from multiple directories, compile code from multiple directories, and use a set of class libraries. These are commonly used techniques in industry, so they're worth learning for future reference. You will be responsible for creating your own makefiles for all other projects.
Here are your tasks:
/afs/umbc.edu/users/y/p/ypeng/pub/CMSC341/Proj1/Proj1.C
Use Proj1.C without making any changes to it. Note: There is no
need to
copy Proj1.C to your own directory. Your makefile must access the file
from the
directory in which it is provided. Do not submit Proj1.C.
/afs/umbc.edu/users/y/p/ypeng/pub/CMSC341/Proj1/Makefile
to your own directory and modify it as needed. It can be used without modification if you follow the file names in the makefile.
/afs/umbc.edu/users/y/p/ypeng/pub/CMSC341/Proj1/341-Spring04-p1_questions.txt
to your own directory and edit it to provide your answers to the questions. Don't forget to submit the edited file; it's 10% of this project's grade.
A hypothetical library has two kinds of items that patrons can check out: books and periodicals. One can "check out", "return", "recall", and "renew" an item. Books and periodicals have different policies regarding to these four functions, as described below.
Overdue items will be charged a fine, which is set for $0.10 per book for each day past the due date, and $1.00 per day for a periodical.
A book item has a Title and a Call Number, both are strings. A book is uniquely identified with its Call Number. A periodical item has a Title and a Volume Number, they are also strings. A periodical is uniquely identified by the combination of its Title and Volume Number.
For simplicity, all dates are represented by integers. Form example, if today's date is 10010, a book checked out today will have the due date of 10038. And if a periodical with due date 10015 is recalled today, a new due date of 10013 is imposed.
You are asked to define and implement the following four classes.
The ADTs for these classes are described below.
A PatronRecord holds separate check out lists for books and periodicals for a library patron. For this project, only one patron, with name "John Doe", and library id "MD-12345", will be maintained. A PatronRecord has four required attributes: -- patron's name (a string), library id (a string), and two CheckedOutLists, typed for Book and Periodical, respectively.
The operations allowed on a PatronRecord are:
A CheckedOutList contains zero or more items of
the same
type (either books or periodicals) that are currently checked out by
the
patron. It therefore must be defined as template class. Your class must
use a vector
to store the current items of the given type. Every CheckedOutList can
hold
unlimited number of items. Its size, the actual number of items
it
currently holds at a given time, increases as items are checked out and
decreases as they are returned. A CheckedOutList has two required
attributes -- a list of items it currently holds (a vector
The operations allowed on a CheckedOutList are:
This operator outputs all items the CheckedOutList currently holds.
Note: Your implementation must use the print idiom described in
the
Weiss text on page 35 (in the Employee
class). This means you must write both the print
method of the CheckedOutList class and a non-class, non-friend function
A Book has five required attributes -- title (a string), call_num (a string), recallStatus (a boolean), renewCount(an integer), and due_date (an integer).
The required operations on Book are
This operator outputs the attributes of the Book.
Note: Your implementation must use the print idiom described in
the
Weiss text on page 35 (in the Employee
class). This means you must write both the print
method of the Book class and a non-class, non-friend function
A Periodical has five required attributes -- title (a string), volume_num (a string) recallStatus (a boolean), renewCount(an integer), and due_date (an integer).
The operations on Periodical are
This operator outputs the attributes of the Periodical.
Note: Your implementation must use the print idiom described in
the
Weiss text on page 35 (in the Employee
class). This means you must write both the print
method of the Periodical class and a non-class, non-friend function
Note 1: Your implementation of the above classes may include any
private
methods you deem necessary, but only the methods listed above may
be
public. Also, if needed, you may include additional private
attributes.
Note 2: The default constructor, copy constructor, assignment operator and destructor must be written by you even if there is no code. You may not use the compiler's default version of these methods even if the compiler's default version would be sufficient.
Project 1 will be invoked with a command line that consists of a single argument: the name of a file that contains a set of operations that must be performed on the patron's record. The format of this file is described in the command file section below.
Note that you must check command line arguments to ensure that they are valid, e.g. that the command file can be opened, and print an appropriate message if an error is found.
Commands in the file specify operations to be performed on the patron's record. Each line in the file represents one command. Blank lines may appear anywhere in the file and should be ignored. Otherwise, you can assume that any line containing a command is syntactically well-formed. We make this assumption so you don't have to spend lots of time making the command file parser bullet proof.
You can also assume that the commands in the command file are in correct order so that
The command file format follows:
For the first five commands, the itemType will be either "Book" (without the quotes) or "Periodical" (without the quotes), the attributes of the items appear in the following order:
The file containing the main function at the following location:
/afs/umbc.edu/users/y/p/ypeng/pub/CMSC341/Proj1/Proj1.C
Sample output is available for your study at
/afs/umbc.edu/users/y/p/ypeng/pub/CMSC341/Proj1/341-Spring04-p1-sample_output.txt
Note that this output was NOT created by executing any program, but
generated
artificially by hand. Note also that it is required that every command
that is
read from the command file is echoed as part of the output.
You should submit only the files you have written, a makefile, and the file containing your answers to the questions. The files to be submitted are:
Please do not submit any of the files provided to you such as Proj1.C.
Submit the files using the procedure given to you for your section
of the
course.
If your makefile is set up correctly, you should be able to excute the
command make
submit.
There are a number of tools available to you to
check on
your submittal. It is your responsibility to ensure that the submittal
is
correct and will result in a successful
compilation of your project. Do not wait till the last minute to submit
your
files. Give yourself enough time to check that your submittal is
correct.
If you don't submit a project correctly, you will not get credit
for it.
Why throw away all that hard work you did to write the project? Check
your
submittals. Make sure they work. Do this before the due date.
Documentation for the submit program is on the web at http://www.gl.umbc.edu/submit/.
One of
the tools provided by the submit program is
submitls.
It lists the names of the files you have submitted.
Additionally, there are two programs for use only by CMSC-341
students (not
part of the UCS submit program). They are in the directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/
and are named submitmake
and submitrun.
You can use these programs to make or run your submitted projects.
The syntax is similar to that for submit:
submitmake <class> <project>
Example: submitmake cs341 Proj1
This makes the project, and shows you the report from the make
utility. It
cleans up the directory after making the project (removes .o and
ii_files), but
leaves the
executable in place.
submitrun <class> <project> [command-line args]
Example: submitrun cs341Proj1 checkers checkfile.dat
This runs the project, assuming there is an executable (i.e. submitmake was run successfully).
Your project will be tested using a variety of
command
lines, some of which will be invalid.
Your project will also be tested using a variety of command files which
will
test various conditions which your code should handle.
Project grading is described in the Project Policy handout.
Your answers to 341-Spring04-proj1_questions.txt are worth 10% of your project grade.
Cheating in any form will not be tolerated. Please re-read the Project Policy handout for further details on honesty in doing projects for this course.
Remember, the due date is firm. Submittals made after midnight of
the due
date will not be accepted. Do not submit any files after that time.