Question: You will be writing a Library simulator involving multiple classes. To make things a little simpler for you, I am supplying you with LibraryItem.hpp, Patron.hpp
You will be writing a Library simulator involving multiple classes. To make things a little simpler for you, I am supplying you with LibraryItem.hpp, Patron.hpp and Library.hpp. You will write the implementation files for the LibraryItem, Patron and Library classes, and the header and implementation files for three classes that inherit from LibraryItem (Book, Album and Movie). You must also write a makefile for this assignment - follow the model of the example makefile I provided).
A couple of notes:
The vector::erase() function lets you delete an element of a vector, shifting over all the elements after it.
You'll see in LibraryItem.hpp a line that says "class Patron;". That is a forward declaration. It doesn't say anything about the definition of the Patron class, but it promises the compiler that there will be a type named Patron. The reason we don't just say "#include Patron.hpp" is that both LibraryItem and Patron need to know about each other, but they can't both #include the other because that would create a cyclic dependency.
Here are the .hpp files - do not alter them: LibraryItem.hpp
, Patron.hpp
and Library.hpp

LibraryItem:
#ifndef LIBRARY_ITEM_HPP
#define LIBRARY_ITEM_HPP
#include
class Patron;
// These three locations are mutually exclusive, but note that
// a LibraryItem can be on request for a Patron while being checked
// out to another Patron. In that case the LibraryItem's location is
// CHECKED_OUT, and when it is returned, it's location will
// become ON_HOLD_SHELF.
enum Locale {ON_SHELF, ON_HOLD_SHELF, CHECKED_OUT};
class LibraryItem
{
private:
std::string idCode;
std::string title;
Locale location;
Patron* checkedOutBy;
Patron* requestedBy;
int dateCheckedOut;
public:
LibraryItem(std::string idc, std::string t);
virtual int getCheckOutLength() = 0;
std::string getIdCode();
std::string getTitle();
Locale getLocation();
void setLocation(Locale);
Patron* getCheckedOutBy();
void setCheckedOutBy(Patron*);
Patron* getRequestedBy();
void setRequestedBy(Patron*);
int getDateCheckedOut();
void setDateCheckedOut(int);
};
#endif
Patron:
#ifndef PATRON_HPP
#define PATRON_HPP
#include
#include
#include "LibraryItem.hpp"
class Patron
{
private:
std::string idNum;
std::string name;
std::vector
double fineAmount;
public:
Patron(std::string idn, std::string n);
std::string getIdNum();
std::string getName();
std::vector
void addLibraryItem(LibraryItem* b);
void removeLibraryItem(LibraryItem* b);
double getFineAmount();
void amendFine(double amount);
};
#endif
Library:
#ifndef LIBRARY_HPP
#define LIBRARY_HPP
#include
#include
#include "Book.hpp"
#include "Album.hpp"
#include "Movie.hpp"
#include "Patron.hpp"
class Library
{
private:
std::vector
std::vector
int currentDate;
public:
Library();
void addLibraryItem(LibraryItem*);
void addPatron(Patron*);
std::string checkOutLibraryItem(std::string patronID, std::string
ItemID);
std::string returnLibraryItem(std::string ItemID);
std::string requestLibraryItem(std::string patronID, std::string
ItemID);
std::string payFine(std::string patronID, double payment);
void incrementCurrentDate();
Patron* getPatron(std::string patronID);
LibraryItem* getLibraryItem(std::string ItemID);
};
#endif
Here are descriptions of the three classes:
LibraryItem:
idCode - a unique identifier for a LibraryItem - you can assume uniqueness, you don't have to enforce it
title - cannot be assumed to be unique
location - a LibraryItem can be either on the shelf, on the hold shelf, or checked out
checkedOutBy - pointer to the Patron who has it checked out (if any)
requestedBy - pointer to the Patron who has requested it (if any); a LibraryItem can only be requested by one Patron at a time
dateCheckedOut - when a LibraryItem is checked out, this will be set to the currentDate of the Library
constructor - takes an idCode, and title; checkedOutBy and requestedBy should be initialized to NULL; a new LibraryItem should be on the shelf
some get and set methods
Book/Album/Movie:
These three classes all inherit from LibraryItem.
All three will need a public static const int CHECK_OUT_LENGTH. For a Book it's 21 days, for an Album it's 14 days, and for a Movie it's 7 days.
All three will have an additional field. For Book, it's a string field called author. For Album, it's a string field called artist. For Movie, it's a string field called director. There will also need to be get methods to return the values of these fields.
Patron:
idNum - a unique identifier for a Patron - you can assume uniqueness, you don't have to enforce it
name - cannot be assumed to be unique
checkedOutItems - a vector of pointers to LibraryItems that a Patron currently has checked out
fineAmount - how much the Patron owes the Library in late fines (measured in dollars); this is allowed to go negative
constructor - takes an idNum and name
some get and set methods
addLibraryItem - adds the specified LibraryItem to checkedOutItems
removeLibraryItem - removes the specified LibraryItem from checkedOutItems
amendFine - a positive argument increases the fineAmount, a negative one decreases it; this is allowed to go negative
Library:
holdings - a vector of pointers to LibraryItems in the Library
members - a vector of pointers to Patrons in the Library
currentDate - stores the current date represented as an integer number of "days" since the Library object was created
a constructor that initializes the currentDate to zero
addLibraryItem - adds the parameter to holdings
addPatron - adds the parameter to members
getLibraryItem - returns a pointer to the LibraryItem corresponding to the ID parameter, or NULL if no such LibraryItem is in the holdings
getPatron - returns a pointer to the Patron corresponding to the ID parameter, or NULL if no such Patron is a member
In checkOutLibraryItem, returnLibraryItem and requestLibraryItem, check the listed conditions in the order given - for example, if checkOutLibraryItem is called with an invalid LibraryItem ID and an invalid Patron ID, it should just return "item not found"
checkOutLibraryItem
if the specified LibraryItem is not in the Library, return "item not found"
if the specified Patron is not in the Library, return "patron not found"
if the specified LibraryItem is already checked out, return "item already checked out"
if the specified LibraryItem is on hold by another Patron, return "item on hold by other patron"
otherwise update the LibraryItem's checkedOutBy, dateCheckedOut and Location; if the LibraryItem was on hold for this Patron, update requestedBy; update the Patron's checkedOutItems; return "check out successful"
returnLibraryItem
if the specified LibraryItem is not in the Library, return "item not found"
if the LibraryItem is not checked out, return "item already in library"
update the Patron's checkedOutItems; update the LibraryItem's location depending on whether another Patron has requested it; update the LibraryItem's checkedOutBy; return "return successful"
requestLibraryItem
if the specified LibraryItem is not in the Library, return "item not found"
if the specified Patron is not in the Library, return "patron not found"
if the specified LibraryItem is already requested, return "item already on hold"
update the LibraryItem's requestedBy; if the LibraryItem is on the shelf, update its location to on hold; return "request successful"
payFine
if the specified Patron is not in the Library, return "patron not found"
use amendFine to update the Patron's fine; return "payment successful"
incrementCurrentDate
increment current date; increase each Patron's fines by 10 cents for each overdue LibraryItem they have checked out (using amendFine)
be careful - a LibraryItem can be on request without its location being the hold shelf (if another Patron has it checked out);
One limited example of how your classes might be used is:
Book b1("123", "War and Peace", "Tolstoy"); Book b2("234", "Moby Dick", "Melville"); Book b3("345", "Phantom Tollbooth", "Juster"); Patron p1("abc", "Felicity"); Patron p2("bcd", "Waldo"); Library lib; lib.addLibraryItem(&b1); lib.addLibraryItem(&b2); lib.addLibraryItem(&b3); lib.addPatron(&p1); lib.addPatron(&p2); lib.checkOutLibraryItem("bcd", "234"); for (int i=0; i This example obviously doesn't include all of the functions described above. You are responsible for testing all of the required functions to make sure they operate as specified.
LibraryItem.cpp, Book.hpp, Book.cpp, Album.hpp, Album.cpp, Movie.hpp, Movie.cpp, Patron.cpp,Library.cpp, and makefile. Don't submit the .hpp files that I provided you, since you're not changing those.
In the main method you use for testing, you should only need to #include Library.hpp. Remember that your compile command needs to list all of the .cpp files.
Just to think about: There are six possible changes in the location of a Book. Can all six occur?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
