Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be writing a Library simulator. It will have three classes: Book, Patro

ID: 3675905 • 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 may add one-line "inline function" implementations to the .hpp files if you want, but implementation of the other functions should go in the corresponding .cpp files. Please put your function comments in the .cpp files (they would clutter up the .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.

#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
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; this is allowed to go negative
a constructor that takes an idNum and name
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
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)

be careful - a Book can be on request without its location being the hold shelf (if another Patron has it checked out);

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 four .cpp files.

Just to think about: There are six possible changes in the location of a Book. Can all six occur?

Explanation / Answer

/*****************************************************************************
* Description: Patron.hpp is the class specification file for the Patron
* class as part of The Library project.
* **************************************************************************/
#ifndef PATRON_HPP
#define PATRON_HPP

#include <string>
#include <vector>

class LibraryItem;

class Patron
{
private:
std::string idNum;
std::string name;
std::vector<LibraryItem*> checkedOutItems;
double fineAmount;
public:
Patron();
Patron(std::string idn, std::string n);
std::string getIdNum();
std::string getName();
void setIdNum(std::string); // Added Set Method
void setName(std::string); // Added Set Method
std::vector<LibraryItem*> getCheckedOutItems();
void addLibraryItem(LibraryItem* b);
void removeLibraryItem(LibraryItem* b);
double getFineAmount();
void amendFine(double amount);
};
#endif

/******************************************************************
* File name: Album.cpp
* Description: Album.cpp is the class function implementation file
* for the Album class.
* ***************************************************************/
#include "LibraryItem.hpp"
#include "Album.hpp"

std::string Album::getOrigin()
{
return getArtist();
}

void Album::setArtist(std::string art)
{
artist = art;
}

std::string Album::getArtist()
{
return artist;
}

int Album::getCheckOutLength()
{
return CHECK_OUT_LENGTH;
}

/***********************************************************************
* File name: Album.hpp
* Description: Album.hpp is the class specification file for the Album
* class as part of The Library project.
* ********************************************************************/
#ifndef ALBUM_HPP
#define ALBUM_HPP

#include <string>

class Album : public LibraryItem {
private:
std::string artist;
public:
Album(std::string idc, std::string t, std::string art) : LibraryItem(idc, t)
{
setArtist(art);
setItemType(ALBUM);
}

static const int CHECK_OUT_LENGTH = 14;
std::string getOrigin(); // Override helper function
void setArtist(std::string art);
std::string getArtist();
int getCheckOutLength(); // Override pure virtual function in parent class
};
#endif

/*******************************************************************
* File name: Book.cpp
* Description: Book.cpp is the class function implementation file
* for the Book class.
* ****************************************************************/
#include "LibraryItem.hpp"
#include "Book.hpp"

std::string Book::getOrigin()
{
return getAuthor();
}

void Book::setAuthor(std::string auth)
{
author = auth;
}

std::string Book::getAuthor()
{
return author;
}

int Book::getCheckOutLength()
{
return CHECK_OUT_LENGTH;
}

/*********************************************************************
* File name: Book.hpp
* Description: Book.hpp is the class specification file for the Book
* class as part of The Library project.
* ******************************************************************/
#ifndef BOOK_HPP
#define BOOK_HPP

#include <string>

class Book : public LibraryItem {
private:
std::string author;
public:
Book(std::string idc, std::string t, std::string auth) : LibraryItem(idc, t)
{
setAuthor(auth);
setItemType(BOOK);
}

static const int CHECK_OUT_LENGTH = 21;
std::string getOrigin(); // Helper function override
void setAuthor(std::string auth);
std::string getAuthor();
int getCheckOutLength(); // override function
};
#endif

/****************************************************************
* File name: Library.cpp
* Description: Library.cpp is the class function implementation
* file for the Library class.
* *************************************************************/
#include "LibraryItem.hpp"
#include "Patron.hpp"
#include "Library.hpp"
#include <cstdlib> // Included for use of NULL pointers.
#include <iostream>
#include <iomanip>
using namespace std;

Library::Library()
{
currentDate = 0;
}

Library::~Library()
{
for (int patron = 0; patron < (members.size()); patron++)
{
delete members[patron];
}

for (int item = 0; item < (holdings.size()); item++)
{
delete holdings[item];
}
}

LibraryItem* Library::findHolding(std::string ItemID)
{
int size = holdings.size();
for (int index = 0; index < size; index++)
{
if ((holdings[index]->getIdCode()) == ItemID)
{
return holdings[index];
}
}   

return NULL;
}

Patron* Library::findMember(std::string patronID)
{
int size = members.size();
for (int index = 0; index < size; index++)
{
if ((members[index]->getIdNum()) == patronID)
{
return members[index];
}
}

return NULL;
}

void Library::addLibraryItem(LibraryItem* item)
{
holdings.push_back(item);
}

void Library::addMember(Patron* member)
{
members.push_back(member);
}

void Library::checkOutLibraryItem(std::string patronID, std::string ItemID)
{
LibraryItem* holding = findHolding(ItemID);
Patron* member = findMember(patronID);

if (holding == NULL)
{
cout << "Item with ID# " << ItemID;
cout << " is not a holding in this library." << endl;
if (member == NULL)
{
cout << "A Patron with ID# " << patronID;
cout << " is not a member of this library." << endl;
}
return;
}
else if (member == NULL)
{
cout << "A Patron with ID# " << patronID;
cout << " is not a member of this library." << endl;
if (holding == NULL)
{
cout << "Item with ID# " << ItemID;
cout << " is not a holding in this library." << endl;
}
return;
}

if (holding->getLocation() == CHECKED_OUT)
{
Patron* checker = holding->getCheckedOutBy();
if ((checker->getIdNum()) == patronID)
{
cout << "Item with ID# " << ItemID;
cout << " is already checked out by " << member->getName();
cout << "." << endl;
return;
}

cout << holding->getTitle() << " with ID# " << ItemID;
cout << " is already checked out by another Patron." << endl;
return;
}

if ((holding->getRequestedBy()) != NULL)
{
Patron* holder = holding->getRequestedBy();
if ((holding->getLocation() == ON_HOLD_SHELF) && (holder->getIdNum() != patronID))
{
cout << holding->getTitle() << " with ID# " << ItemID;
cout << " is on hold by another Patron." << endl;
return;
}
}

//Update LibraryItem's checkedOutBy, dateCheckedOut, and Location.
holding->setCheckedOutBy(member);
holding->setDateCheckedOut(currentDate);
holding->setLocation(CHECKED_OUT);

//If patron requested this item, update requestedBy.
if ((holding->getRequestedBy()) != NULL)
{
Patron* holder = holding->getRequestedBy();
if (holder->getIdNum() == patronID)
{
holding->setRequestedBy(NULL);
}
}   

//Update Patron's list.
member->addLibraryItem(holding);

//Print checked out confirmation.
cout << holding->getTitle() << " with ID# " << ItemID;
cout << " has been checked out to " << member->getName() << "." << endl;
}

void Library::returnLibraryItem(std::string ItemID)
{
LibraryItem* holding = findHolding(ItemID);

if (holding == NULL)
{
cout << "Item with ID# " << ItemID;
cout << " is not a holding in this library." << endl;
return;
}

if (holding->getLocation() != CHECKED_OUT)
{
cout << "Item with ID# " << ItemID;
cout << " is not checked out." << endl;
return;
}

Patron* member = holding->getCheckedOutBy();

//Update Patron's list.
member->removeLibraryItem(holding);

//Update LibraryItem's location.
if ((holding->getRequestedBy()) != NULL)
{
holding->setLocation(ON_HOLD_SHELF);
}
else
{
holding->setLocation(ON_SHELF);
}

//Update checkedOutBy.
holding->setCheckedOutBy(NULL);

//Print return confirmation.
cout << holding->getTitle() << " has been returned." << endl;
}

void Library::requestLibraryItem(std::string patronID, std::string ItemID)
{
LibraryItem* holding = findHolding(ItemID);
Patron* member = findMember(patronID);

if (holding == NULL)
{
cout << "Item with ID# " << ItemID;
cout << " is not a holding in this library." << endl;
if (member == NULL)
{
cout << "A Patron with ID# " << patronID;
cout << " is not a member of this library." << endl;
}
return;
}
else if (member == NULL)
{
cout << "A Patron with ID# " << patronID;
cout << " is not a member of this library." << endl;
if (holding == NULL)
{
cout << "Item with ID# " << ItemID;
cout << " is not a holding in this library." << endl;
}
return;
}

if (holding->getRequestedBy() != NULL)
{
Patron* holder = holding->getRequestedBy();
if ((holder->getIdNum()) == patronID)
{
cout << "Item with ID# " << ItemID;
cout << " is already requested by " << member->getName();
cout << "." << endl;
return;
}

cout << "Item with ID# " << ItemID;
cout << " is already requested by another Patron." << endl;
return;
}

if (holding->getCheckedOutBy() == member)
{
cout << "Item with ID# " << ItemID;
cout << " is already checked out by Patron ID# " << patronID;
cout << "." << endl;
return;
}

//Update LibraryItem's requestedBy.
holding->setRequestedBy(member);

//Update LibraryItem's location.
if (holding->getLocation() == ON_SHELF)
{
holding->setLocation(ON_HOLD_SHELF);
}

//Print request confirmation.
cout << holding->getTitle() << " is now on request for " << member->getName();
cout << "." << endl;
}

void Library::incrementCurrentDate()
{
currentDate++;

for (int patron = 0; patron < (members.size()); patron++)
{
vector<LibraryItem*> payment = members[patron]->getCheckedOutItems();
for (int items = 0; items < (payment.size()); items++)
{
//Determine if overdue
LibraryItem* checked = payment[items];

int days_checked_out = currentDate - (checked->getDateCheckedOut());
int days_left = (checked->getCheckOutLength()) - days_checked_out;

if (days_checked_out > (checked->getCheckOutLength()))
{
members[patron]->amendFine(.10);
}
}
}
}

void Library::payFine(std::string patronID, double payment)

{
Patron* member = findMember(patronID);

if (member == NULL)
{
cout << "A Patron with ID# " << patronID;
cout << " is not a member of this library." << endl;
return;
}

//Update fine amount.
member->amendFine(payment);

//Print fine confimration.
cout << "The fines for " << member->getName();
cout << " are now $" << fixed << setprecision(2) << member->getFineAmount() << endl;
}

void Library::viewPatronInfo(std::string patronID)
{
Patron* member = findMember(patronID);

if (member == NULL)
{
cout << "A Patron with ID# " << patronID;
cout << " is not a member of this library." << endl;
return;
}

cout << "-----------------------------------------------" << endl;   
cout << " Patron ID#: " << member->getIdNum() << endl;
cout << " Name: " << member->getName() << endl;
cout << "-----------------------------------------------" << endl;
cout <<" Checked Out Items:";

vector<LibraryItem*> items = member->getCheckedOutItems();

if (items.empty())
{
cout << " None." << endl;
}
else
{
cout << endl << endl;
int size = items.size();
if (size == 1)
{
LibraryItem* checked = items[0];
string title = checked->getTitle();
string origin = checked->getOrigin();
string id = checked->getIdCode();

if ((checked->getItemType()) == 1)
{
cout << " Album: ";
}
if ((checked->getItemType()) == 2)
{
cout << " Book: ";
}
if ((checked->getItemType()) == 3)
{
cout << " Movie: ";
}
cout << title << " by " << origin << ", ID# " << id << endl << endl;
}
else if (size > 1)
{
LibraryItem* checked;
string title, origin, id;
for (int index = 0; index < size; index++)
{
checked = items[index];
title = checked->getTitle();
origin = checked->getOrigin();
id = checked->getIdCode();
  
if ((checked->getItemType()) == 1)
{
cout << " Album: ";
}
if ((checked->getItemType()) == 2)
{
cout << " Book: ";
}
if ((checked->getItemType()) == 3)
{
cout << " Movie: ";
}
cout << title << " by " << origin << ", ID# " << id << endl;
}
cout << endl;
}
}

cout << "-----------------------------------------------" << endl;
cout << " Current Library Fines: $" << fixed << setprecision(2) << member->getFineAmount() << endl;
cout << "-----------------------------------------------" << endl;
}

void Library::viewItemInfo(std::string ItemID)
{
LibraryItem* holding = findHolding(ItemID);

if (holding == NULL)
{
cout << "Item with ID# " << ItemID;
cout << " is not a holding in this library." << endl;
return;
}

//Print item info.
cout << "-----------------------------------------------" << endl;   
  
//ID number:
cout << " Item ID#: " << ItemID << endl;

//Origin (Author/Artist/Director):
if ((holding->getItemType()) == BOOK)
{
cout << " Item Description: Book" << endl;
cout << " Author: " << holding->getOrigin() << endl;
}
else if ((holding->getItemType()) == ALBUM)
{
cout << " Item Description: Album" << endl;
cout << " Artist: " << holding->getOrigin() << endl;
}
else if ((holding->getItemType()) == MOVIE)
{
cout << " Item Description: Movie" << endl;
cout << " Director: " << holding->getOrigin() << endl;
}

//Title:
cout << " Title: " << holding->getTitle() << endl;
cout << "-----------------------------------------------" << endl << endl;

//Location:
cout << " Current Location: ";
if ((holding->getLocation()) == 0)
{
cout << "On Shelf" << endl;
}
else if ((holding->getLocation()) == 1)
{
cout << "On Hold Shelf" << endl;
}
else if ((holding->getLocation()) == 2)
{
cout << "Checked Out" << endl;
}

//Requested by:
if ((holding->getRequestedBy()) != NULL)
{
Patron* requester = holding->getRequestedBy();

cout << " Requested By: " << requester->getName() << endl;
}
else
{
cout << " Requested By: None" << endl;
}

//Checked out by:
if ((holding->getCheckedOutBy()) != NULL)
{
Patron* checker = holding->getCheckedOutBy();
  
cout << " Checked Out By: " << checker->getName() << endl;
}
else
{
cout << " Checked Out By: None" << endl;
}

//Due status:
if ((holding->getLocation()) == 2)
{
int days_checked_out = currentDate - (holding->getDateCheckedOut());
int days_left = (holding->getCheckOutLength()) - days_checked_out;
if (days_checked_out > (holding->getCheckOutLength()))
{
cout << " Status: OVERDUE" << endl;
}
else if (days_checked_out < (holding->getCheckOutLength()))
{
cout << " Status: " << days_left << " DAYS LEFT TILL DUE" << endl;
}
else if (days_checked_out == (holding->getCheckOutLength()))
{   
cout << " Status: DUE TODAY" << endl;
}
}
else
{
cout << " Status: Not Checked Out" << endl;
}

cout << endl << "-----------------------------------------------" << endl;
}

/*****************************************************************************
* File name: Library.hpp
* Description: Library.hpp is the class specification file for the Library
* class as part of The Library project.
* **************************************************************************/
#ifndef LIBRARY_HPP
#define LIBRARY_HPP

#include <string>
#include <vector>

class Patron;
class LibraryItem;

class Library
{
private:
std::vector<LibraryItem*> holdings;
std::vector<Patron*> members;
int currentDate;
public:
//Added two helper functions, findHolding and findMember.
Library();
~Library(); //Added destructor
LibraryItem* findHolding(std::string ItemID);
Patron* findMember(std::string patronID);
void addLibraryItem(LibraryItem* item);
void addMember(Patron* member);
void checkOutLibraryItem(std::string patronID, std::string ItemID);
void returnLibraryItem(std::string ItemID);
void requestLibraryItem(std::string patronID, std::string ItemID);
void incrementCurrentDate();
void payFine(std::string patronID, double payment);
void viewPatronInfo(std::string patronID);
void viewItemInfo(std::string ItemID);
};
#endif

/*************************************************************************
* File name: LibraryItem.cpp
* Description: LibraryItem.cpp is the class function implementation file
* for the LibraryItem class.
* **********************************************************************/
#include "LibraryItem.hpp"

LibraryItem::LibraryItem()
{
setIdCode("");
setTitle("");
setCheckedOutBy(NULL);
setRequestedBy(NULL);
setLocation(ON_SHELF);
}

LibraryItem::LibraryItem(std::string idc, std::string t)
{
setIdCode(idc);
setTitle(t);
setCheckedOutBy(NULL);
setRequestedBy(NULL);
setLocation(ON_SHELF);
}

std::string LibraryItem::getIdCode()
{
return idCode;
}

void LibraryItem::setIdCode(std::string id)
{
idCode = id;
}

std::string LibraryItem::getTitle()
{
return title;
}

void LibraryItem::setTitle(std::string t)
{
title = t;
}

Locale LibraryItem::getLocation()
{
return location;
}

void LibraryItem::setLocation(Locale lo)
{
location = lo;
}

Patron* LibraryItem::getCheckedOutBy()
{
return checkedOutBy;
}

void LibraryItem::setCheckedOutBy(Patron *p)
{
checkedOutBy = p;
}

Patron* LibraryItem::getRequestedBy()
{
return requestedBy;
}

void LibraryItem::setRequestedBy(Patron* p)
{
requestedBy = p;
}

int LibraryItem::getDateCheckedOut()
{
return dateCheckedOut;
}

void LibraryItem::setDateCheckedOut(int d)
{
dateCheckedOut = d;
}

Item LibraryItem::getItemType()
{
return itemType;
}

void LibraryItem::setItemType(Item type)
{
itemType = type;
}

/*************************************************************************
* File name: LibraryItem.hpp
* Description: LibraryItem.hpp is the class specification file for the
* LibraryItem class as part of The Library project.
* **********************************************************************/
#ifndef LIBRARY_ITEM_HPP
#define LIBRARY_ITEM_HPP

#include <string>
class Patron;


enum Locale {ON_SHELF, ON_HOLD_SHELF, CHECKED_OUT};

//Added Item Type:
enum Item {ALBUM = 1, BOOK, MOVIE};

class LibraryItem
{
private:
std::string idCode;
std::string title;
Locale location;
Patron* checkedOutBy;
Patron* requestedBy;
int dateCheckedOut;
Item itemType; // Added type description
public:
LibraryItem();
LibraryItem(std::string idc, std::string t);
virtual int getCheckOutLength() = 0;
virtual std::string getOrigin() = 0; // Added get method
std::string getIdCode();
void setIdCode(std::string id); // Added set method
std::string getTitle();
void setTitle(std::string t); // Added set method
Locale getLocation();
void setLocation(Locale lo);
Patron* getCheckedOutBy();
void setCheckedOutBy(Patron* p);
Patron* getRequestedBy();
void setRequestedBy(Patron* p);
int getDateCheckedOut();
void setDateCheckedOut(int d);
Item getItemType(); // Added get
void setItemType(Item type); // Added set
};
#endif

/******************************************************************
* File name: Menu.cpp
* Description: This is the main for the Final Project in CS 165.
* ***************************************************************/
#include "LibraryItem.hpp"
#include "Book.hpp"
#include "Album.hpp"
#include "Movie.hpp"
#include "Patron.hpp"
#include "Library.hpp"

#include <iostream> // input and output
#include <limits> // Used with cin.ignore() in programMenu()
#include <cstdlib> // For system clear
using namespace std;

//Function Prototypes:
int programMenu();

//Main function:
int main () {

Library simulation;

int input = 0; // Variable for program menu choice
while (input !=12)
{
system("clear");
input = programMenu();

if (input == 1) // Add Book to Library Holdings
{
string title, author, id;

//User input:
cout << " ADD BOOK TO LIBRARY HOLDINGS" << endl;
cout << "------------------------------" << endl;
cout << " Enter Title: ";
getline(cin, title);
cout << " Enter Author: ";
getline(cin, author);
cout << " Assign Unique ID#: ";
getline(cin, id);
  
//Input validation:
LibraryItem* check = simulation.findHolding(id);
if (check != NULL)
{
cout << endl << "That ID is already in use." << endl;
}
else
{
Book *newItem; // Allocate memory for Library Item
newItem = new Book(id, title, author); // Create Library Item

simulation.addLibraryItem(newItem); // Add item to Library
cout << endl << "The book has been added to the library." << endl;   
}

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 2) // Add Movie to Library Holdings
{   
string title, director, id;

//User input:
cout << " ADD MOVIE TO LIBRARY HOLDINGS" << endl;
cout << "-------------------------------" << endl;
cout << " Enter Title: ";
getline(cin, title);
cout << " Enter Director: ";
getline(cin, director);
cout << " Assign Unique ID#: ";
getline(cin, id);

//Input validation:
LibraryItem* check = simulation.findHolding(id);
if (check != NULL)
{
cout << endl << "That ID is already in use." << endl;
}
else
{
Movie *newItem; // Allocate memory for Library Item
newItem = new Movie(id, title, director); // Create Library Item

simulation.addLibraryItem(newItem); // Add item to Library
cout << endl << "The movie has been added to the library." << endl;
}

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 3) // Add Album to Library Holdings
{
string title, artist, id;

//User input:
cout << " ADD ALBUM TO LIBRARY HOLDINGS" << endl;
cout << "-------------------------------" << endl;
cout << " Enter Title: ";
getline(cin, title);
cout << " Enter Artist: ";
getline(cin, artist);
cout << " Assign Unique ID#: ";
getline(cin, id);

//Input validation:
LibraryItem* check = simulation.findHolding(id);
if (check != NULL)
{
cout << endl << "That ID is already in use." << endl;
}
else
{
Album *newItem; // Allocate memory for Library Item
newItem = new Album(id, title, artist); // Create Library Item

simulation.addLibraryItem(newItem); // Add item to Library   
cout << endl << "The album has been added to the library." << endl;
}

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 4) // Add New Library Member
{
string name, id;   

// User input:
cout << " ADD NEW LIBRARY MEMBER" << endl;
cout << "------------------------" << endl;
cout << " Enter Name: ";
getline(cin, name);
cout << " Enter Unique ID#: ";
getline(cin, id);

//Input validation:
Patron* check = simulation.findMember(id);
if (check != NULL)
{
cout << endl << "That ID is already in use." << endl;
}
else
{
Patron *patron; // Allocate memory for Patron
patron = new Patron(id, name); // Create Patron

simulation.addMember(patron); //Add member to Library
cout << endl << "The patron has been added to the library." << endl;
}

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 5) // Pay Library Fine
{
string id;
double payment;

cout << " MAKE A PAYMENT ON A LIBRARY FINE " << endl;
cout << "----------------------------------" << endl;
cout << " Enter Patron ID#: ";
getline(cin, id);
cout << " Enter Payment Amount: $";
cin >> payment;
payment *= -1;

cout << endl;
simulation.payFine(id, payment);

cin.ignore();
cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 6) // View Library Member Account
{
string id;

cout << " VIEW LIBRARY MEMBER ACCOUNT" << endl;
cout << "-----------------------------" << endl;
cout << " Enter Patron ID#: ";
cin >> id;

cout << endl;
simulation.viewPatronInfo(id);
cin.ignore();

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 7) // View Library Item Information
{
string id;

cout << " VIEW LIBRARY ITEM INFORMATION" << endl;
cout << "-------------------------------" << endl;
cout << " Enter Item ID#: ";
getline(cin, id);
  
cout << endl;
simulation.viewItemInfo(id);

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 8) // Request Item from Library
{
string ID, ItemID;

cout << " REQUEST ITEM FROM LIBRARY" << endl;
cout << "---------------------------" << endl;
cout << " Enter Patron ID#: ";
getline(cin, ID);
cout << " Enter Item ID#: ";
getline(cin, ItemID);

cout << endl;
simulation.requestLibraryItem(ID, ItemID);

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 9) // Check Out Library Item
{
string ID, ItemID;

cout << " CHECK OUT LIBRARY ITEM" << endl;
cout << "------------------------" << endl;
cout << " Enter Patron ID#: ";
getline(cin, ID);
cout << " Enter Item ID#: ";
getline(cin, ItemID);

cout << endl;
simulation.checkOutLibraryItem(ID, ItemID);

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 10) // Return Library Item
{
string id;

cout << " RETURN LIBRARY ITEM" << endl;
cout << "---------------------" << endl;
cout << " Enter Item ID#: ";
getline(cin, id);

cout << endl;
simulation.returnLibraryItem(id);

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}

if (input == 11) // Increment Current Date
{
simulation.incrementCurrentDate();
cout << "The date has been incremented." << endl;   

cout << endl << "Press [Enter] to return to the main menu." << endl;
cin.ignore();   
}
}

return 0;
}

int programMenu()
{
int input; // Local variable
bool integerFail = false; // Ensure integer input

cout << endl << endl << endl;
cout << " ==========================================" << endl;
cout << " | The Library Menu |" << endl;
cout << " ==========================================" << endl;
cout << " | 1. Add Book to Library Holdings |" << endl;
cout << " | 2. Add Movie to Library Holdings |" << endl;
cout << " | 3. Add Album to Library Holdings |" << endl;
cout << " | 4. Add New Library Member |" << endl;
cout << " | 5. Pay Library Fine |" << endl;
cout << " | 6. View Library Member Account |" << endl;
cout << " | 7. View Library Item Information |" << endl;
cout << " | 8. Request Item from Library |" << endl;
cout << " | 9. Check Out Library Item |" << endl;
cout << " | 10. Return Library Item |" << endl;
cout << " | 11. Increment Current Date |" << endl;
cout << " | 12. Quit Program |" << endl;
cout << " ==========================================" << endl;
cout << " Enter: ";

do {
cin >> input; // User input here
integerFail = cin.fail();
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), ' ');
} while (integerFail == true);
cout << endl;

return input;
}

/*******************************************************************
* File name: Movie.cpp
* Description: Movie.cpp is the class function implementation file
* for the Movie class.
* ****************************************************************/
#include "LibraryItem.hpp"
#include "Movie.hpp"

std::string Movie::getOrigin()
{
return getDirector();
}

void Movie::setDirector(std::string direct)
{
director = direct;
}

std::string Movie::getDirector()
{
return director;
}

int Movie::getCheckOutLength()
{
return CHECK_OUT_LENGTH;
}

/***********************************************************************
* File name: Movie.hpp
* Description: Movie.hpp is the class specification file for the Movie
* class as part of The Library project.
* ********************************************************************/

#include <string>

#ifndef MOVIE_HPP
#define MOVIE_HPP
class Movie : public LibraryItem {
private:
std::string director;
public:
Movie(std::string idc, std::string t, std::string direct) : LibraryItem(idc, t)
{
setDirector(direct);
setItemType(MOVIE);
}

static const int CHECK_OUT_LENGTH = 7;
std::string getOrigin(); // Override helper function
void setDirector(std::string direct);
std::string getDirector();
int getCheckOutLength(); // Override function
};
#endif

/****************************************************************
* File name: Patron.cpp
* Description: Patron.cpp is the class function implemenation
* file for the Patron class.
* *************************************************************/
#include "LibraryItem.hpp"
#include "Patron.hpp"

Patron::Patron()
{
setIdNum("");
setName("");   
}

Patron::Patron(std::string idn, std::string n)
{
setIdNum(idn);
setName(n);
}

std::string Patron::getIdNum()
{
return idNum;
}

std::string Patron::getName()
{
return name;
}

void Patron::setIdNum(std::string id)
{
idNum = id;
}

void Patron::setName(std::string n)
{
name = n;
}

std::vector<LibraryItem*> Patron::getCheckedOutItems()
{
return checkedOutItems;
}

void Patron::addLibraryItem(LibraryItem* b)
{
checkedOutItems.push_back(b);   
}

void Patron::removeLibraryItem(LibraryItem* b)
{
std::string id;
id = b->getIdCode();

int size = checkedOutItems.size();
for (int index = 0; index < size; index++)
{
if ((checkedOutItems[index]->getIdCode()) == id)
{
checkedOutItems.erase(checkedOutItems.begin() + index);
size = index;
}
}
}

double Patron::getFineAmount()
{
return fineAmount;
}

void Patron::amendFine(double amount)
{
fineAmount += amount;
//If amount is positive, it increases the fine.
//If amount is negative, it decreases the fine.
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote