Introduction

This section gives a brief introduction to the problem to solve and provides you with the marking scheme that will be applied. The classes to implement are presented in section 2.

The problem to solve

You may renew items on loan to you via Primo OneSearch as long as they are not reserved for another reader and you have not reached the maximum number of renewals.

The objective of this coursework is to produce classes to model the books found in the following types of library collections:

  • Electronic book repository: E-books can be downloaded by users at any time. Technically the library buys a download credit from a publisher for each e-book it wishes to provide. When the download credit of a book is exhausted the book cannot be downloaded any longer. As a consequence the library has implemented the rule that a user cannot download a given book more than once.
  • Short loan collection: Books can be borrowed for a short period of time and the borrower cannot extend the loan period. In addition, books cannot be reissued to their last borrower for a set amount of time. Fines are levied for late returns.
  • Standard loan collection: Books can be borrowed for a longer period than those from the Short loan collection. A book can be reserved — by at most one user — which means that the book is held for the reserver for a certain amount of time after the return date. A borrower can renew a non-overdue loan a number of times as long as the corresponding book has not been reserved by another user. A book can be borrowed again by the user who returns it if no one has reserved it. Fines are levied for late returns.

Section 2 describes the classes to implement.

Classes to implement

In all cases you should provide methods to print book’s data using overloading of the out- put operator << so as to reproduce the output provided when testing with the main.cpp provided.

Book

This is an abstract class that contains data members common to all books. In our simple model there is only one data member:

  • int bookid, a unique identifier associated with a book. In a real system this would be the book’s ISBN.

Other data members representing title, author, classification, etc. could be added later.

The methods to declare and possibly implement are

  • Accessor methods, void setid(int id) and int getid(), for bookid.
  • A constructor method — which can only be used by the constructors of derived classes as Book is an abstract class.
  • A pure virtual method, virtual std::string gettype() const = 0, that should be used by a method that overloads the output operator to display the type of book and the book identifier.
  • A virtual destructor.

Ebook

This class is publicly derived from the Book class. An object of the class contains the following data members:

  • int maxdownload, the maximum number of downloads authorized for the book.
  • int downloadsofar, the number of times the book has been downloaded.
  • usercell * head, the head of a list that stores the users that have downloaded the book, where usercell is a type declared as struct usercell { int userid; usercell * next; }; You may declare this type as a private type inside your class declaration, but in this case it should be qualified when used in a friend method (i.e. you should use Ebook::usercell instead of usercell).

In addition to accessor methods and the overloading of the output operator <<, the following public methods should be implemented:

  • Ebook(int id=0, int maxdownload=0), to construct a book with identifier, id, and download credit, maxdownload.
  • bool download(int userid), to download the book. If the user, userid, has not yet downloaded the book and downloadsofar is less than maxdownload the method returns true, otherwise it returns false. This possibly involves checking and updating the list of usercell records.

You may create some additional private methods to deal with the list of usercell records. Also do not forget to write a destructor to return to the system the memory allocated to this list.

Shortloan

This class is publicly derived from the Book class. Some parameters of a book on short loan are associated with the type of book rather than the particular book; in other word they are associated with the class rather than the object and are therefore declared as static members of the class. These are:

  • static int loanduration, the number of days a book can be kept by a borrower. We assume that a day (date) is simply an integer. So 100,101,102 correspond to three consecutive days. If a user borrows a book on day, d, he should return it not later than day, d+loanduration.
  • static float dailyfee, the daily fee applied to late returns. If a book is returned on day, d, beyond the due day, day, then the fee levied is (d-day)*dailyfee.
  • static int borrowgap. If a book is returned on day, day, the last borrower of the book cannot borrow it before day, day+borrowgap.

An object of the class contains the following data members:

  • bool onshelf, a boolean that is false if the book is out (i.e. with a borrower) and is true if the book is in (i.e. in the libary).
  • int borrowerid, the current borrower identifier if the book is out and the last- borrower identifier if the book is in. We will assume that a user identifier is a positive integer and that a zero identifier means that the book has never been borrowed.
  • int day, the due date if the book is out and the date the book was last returned if the book is in.

Besides constructor, accessor methods, and the overloading of the output operator <<, the following public methods should be implemented:

  • bool borrow(int borrowerid, int day), to enable user, borrowerid, to borrow the book on day, day. A user cannot borrow a book already on loan or if he is the last borrower of the book and returned it recently (see borrowgap above). The method returns true if the operation was successful and false otherwise.
  • float takeback(int day), to return the book to the library on day, day. The method returns the fee to be paid (0 if returned on time).
  • bool overdue(int day), to return true if the book is overdue and false otherwise.

You should create protected virtual helper methods to make the above methods appli- cable to inheriting classes.

Standardloan

This class publicly inherits from Shortloan. Parameters associated with this class are:

  • static int loanduration, the number of days a book can be kept by a borrower.
  • static int renewalduration. If a borrower renews a loan on day, d, her new due date becomes d+renewalduration (see renew method below). In practice renewalduration should be less than or equal to loanduration.
  • static int reservedhold, the number of days a reserved book is kept on hold for the reserver from the date the reservation is made if the book is on shelf or from the return date if it is not.
  • static int maxrenewal, the maximum number of times a loan can be renewed.

An object contains the following data members:

  • int reserverid, the identifier of the reserver of a book, or zero if the book is not reserved.
  • int hold, the deadline for the reserver to borrow the book. Note that this variable cannot be set at time of reservation if the book is on loan.
  • int renewed, the number of times the current borrower has renewed her loan.

Besides constructor, accessor methods, and the overloading of the output operator <<, you should implement the following public methods:

  • bool reserve(int userid, int day), to enable user, userid, to reserve the book on day, day. A user can reserve a book if it is on shelf and is not held for another user, or if it is out and not reserved. In this latter case the reserver cannot be the current borrower! The method returns true if the reservation was successful and false otherwise.
  • bool renew(int day), to renew the loan of a book currently on loan. This opera- tion is unsuccessful and returns false in the following cases: the book is overdue; the maximum number of renewals has been reached; the borrower’s current due date would not be increased by the operation; the book is reserved.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.