You will be writing a Library simulator. It will have three classes: Book, Patro
ID: 666776 • Letter: Y
Question
You will be writing a Library simulator. It will have three classes: Book, Patron and Library. To make things a little simpler for you, I am supplying you with the three .hpp files. You will write the three implementation files. You should not alter the provided .hpp files.
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 Book.hpp a line that says "class Patron;". That is a forward declaration. It doesn't say anything about the definition of the Paton 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 Book 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: (they can not be changed)
//Book.hpp
#ifndef BOOK_HPP
#define BOOK_HPP
#include <string>
class Patron;
// These three locations are mutually exclusive, but note that
// a Book can be on request for a Patron while being checked
// out to another Patron. In that case the Book'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 Book
{
private:
std::string idCode;
std::string title;
std::string author;
Locale location;
Patron* checkedOutBy;
Patron* requestedBy;
int dateCheckedOut;
public:
static const int CHECK_OUT_LENGTH = 21;
Book(std::string idc, std::string t, std::string a);
int getCheckOutLength();
std::string getIdCode();
std::string getTitle();
std::string getAuthor();
Locale getLocation();
void setLocation(Locale);
Patron* getCheckedOutBy();
void setCheckedOutBy(Patron*);
Patron* getRequestedBy();
void setRequestedBy(Patron*);
int getDateCheckedOut();
void setDateCheckedOut(int);
};
#endif
//Patron.hpp
#ifndef PATRON_HPP
#define PATRON_HPP
#include <string>
#include <vector>
#include "Book.hpp"
//class LibraryItem;
class Patron
{
private:
std::string idNum;
std::string name;
std::vector<Book*> checkedOutBooks;
double fineAmount;
public:
Patron(std::string idn, std::string n);
std::string getIdNum();
std::string getName();
std::vector<Book*> getCheckedOutBooks();
void addBook(Book* b);
void removeBook(Book* b);
double getFineAmount();
void amendFine(double amount);
};
#endif
//Library.hpp
#ifndef LIBRARY_HPP
#define LIBRARY_HPP
#include <string>
#include <vector>
#include "Patron.hpp"
class Library
{
private:
std::vector<Book*> holdings;
std::vector<Patron*> members;
int currentDate;
public:
Library();
void addBook(Book*);
void addPatron(Patron*);
std::string checkOutBook(std::string pID, std::string bID);
std::string returnBook(std::string bID);
std::string requestBook(std::string pID, std::string bID);
std::string payFine(std::string pID, double payment);
void incrementCurrentDate();
Patron* getPatron(std::string pID);
Book* getBook(std::string bID);
};
#endif
Here are descriptions of the three classes:
Book:
idCode - a unique identifier for a Book (think library bar code, not ISBN)
title - cannot be assumed to be unique
author - the title and author don't need set methods, since they will never change after the object has been created, therefore these fields can be initialized directly within the constructor
location - a Book 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 Book can only be requested by one Patron at a time
dateCheckedOut - when a book is checked out, this will be set to the currentDate of the Library
CHECK_OUT_LENGTH - constant that gives how long a Book can be checked out for
constructor - takes an idCode, title and author; checkedOutBy and requestedBy should be initialized to NULL; a new Book should be on the shelf
some get and set methods
Patron:
idNum - a unique identifier for a Patron
name - cannot be assumed to be unique
checkedOutBooks - a vector of Books that Patron currently has checkedOut
fineAmount - how much the Patron owes the Library in late fines (measured in dollars); this is allowed to go negative
a constructor that takes an idNum and name and initializes fineAmount to zero
some get and set methods
addBook - adds the specified Book to checkedOutBooks
removeBook - removes the specified Book from checkedOutBooks
amendFine - a positive argument increases the fineAmount, a negative one decreases it
Library:
holdings - a vector of pointers to Books 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
addBook - adds the parameter to holdings
addPatron - adds the parameter to members
getBook - returns a pointer to the Book corresponding to the ID parameter, or NULL if no such Book 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
checkOutBook
if the specified Book is not in the Library, return "book not found"
if the specified Patron is not in the Library, return "patron not found"
if the specified Book is already checked out, return "book already checked out"
if the specified Book is on hold by another Patron, return "book on hold by other patron"
otherwise update the Book's checkedOutBy, dateCheckedOut and Location; if the Book was on hold for this Patron, update requestedBy; update the Patron's checkedOutBooks; return "check out successful"
returnBook
if the specified Book is not in the Library, return "book not found"
if the Book is not checked out, return "book already in library"
update the Patron's checkedOutBooks; update the Book's location depending on whether another Patron has requested it; update the Book's checkedOutBy; return "return successful"
requestBook
if the specified Book is not in the Library, return "book not found"
if the specified Patron is not in the Library, return "patron not found"
if the specified Book is already requested by another Patron, return "book on hold by other patron"
update the Book's requestedBy; if the Book is on the shelf, update its location to on hold; return "request successful"
payFine
takes as a parameter the amount that is being paid (not the negative of that amount)
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 Book they have checked out (using amendFine)
If a book is checked out on day 0, then on day 1, the patron has had it for 1 day. On day 21, the patron has had it for 21 days, so it is still not overdue. On day 22, the book is overdue and fines will be charged.
be careful - a Book 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:
Explanation / Answer
Please refer Book.hpp, Patron.hpp, Library.hpp from question
Menu.cpp
Patron.cpp
Library.cpp
Book.cpp
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.