Question: Please help me fix/finish my code. This project is altered every semster so please look over THESE specific specs. Don't copy and paste from prior

Please help me fix/finish my code. This project is altered every semster so please look over THESE specific specs. Don't copy and paste from prior semesters.

************

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.hppPlease help me fix/finish my code. This project is altered every semsterso please look over THESE specific specs. Don't copy and paste from, Patron.hppprior semesters. ************ You will be writing a Library simulator involving multipleclasses. To make things a little simpler for you, I am supplying and Library.hppyou with LibraryItem.hpp, Patron.hpp and Library.hpp. You will write the implementation filesfor the LibraryItem, Patron and Library classes, and the header and implementation (I've included them below)

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

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 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.

You must submit on Mimir: LibraryItem.cpp, Book.hpp, Book.cpp, Album.hpp, Album.cpp, Movie.hpp, Movie.cpp, Patron.cpp,Library.cpp,

*************************

Here is the code that I have started. Please note that that LibraryItem.hpp, Patron.hpp, and Library.hpp were given and cannot be altered, the rest of the code is what I've come up with. Please post your output if submitting an answer. Don't worry about the makefile, I can do that on my own.

***********************************************************************

Album.hpp

********************************************************************/

#ifndef ALBUM_HPP

#define ALBUM_HPP

#include

using namespace std;

class Album : public LibraryItem

{

private:

std::string artist;

public:

Album(std::string idc, std::string t, std::string art) : LibraryItem(idc, t)

{

setArtist(art);

}

static const int CHECK_OUT_LENGTH = 14;

void setArtist(std::string artistAlbum);

std::string getArtist();

int getCheckOutLength(); // Override pure virtual function in parent class

};

#endif

***********************************************************************

Album.cpp

******************************************************************

#include "LibraryItem.hpp"

#include "Album.hpp"

void Album::setArtist(std::string art)

{

artist = art;

}

std::string Album::getArtist()

{

return artist;

}

int Album::getCheckOutLength()

{

return CHECK_OUT_LENGTH;

}

***********************************************************************

Book.hpp

******************************************************************

#ifndef BOOK_HPP

#define BOOK_HPP

#include

class Book : public LibraryItem

{

private:

std::string author;

public:

Book(std::string idc, std::string t, std::string auth) : LibraryItem(idc, t)

{

setAuthor(auth);

}

static const int CHECK_OUT_LENGTH = 21;

void setAuthor(std::string aut);

std::string getAuthor();

int getCheckOutLength(); // Override pure virtual function in parent class

};

#endif

***********************************************************************

Book.cpp

******************************************************************

#include "LibraryItem.hpp"

#include "Book.hpp"

void Book::setAuthor(std::string auth)

{

author = auth;

}

std::string Book::getAuthor()

{

return author;

}

int Book::getCheckOutLength()

{

return CHECK_OUT_LENGTH;

}

***********************************************************************

Movie.hpp

******************************************************************

#ifndef MOVIE_HPP

#define MOVIE_HPP

#include

class Movie : public LibraryItem

{

private:

std::string director;

public:

Movie(std::string idc, std::string t, std::string d) : LibraryItem(idc, t)

{

setDirector(d);

}

static const int CHECK_OUT_LENGTH = 7;

void setDirector(std::string d);

std::string getDirector();

int getCheckOutLength(); // Override pure virtual function in parent class

};

#endif

***********************************************************************

Movie.cpp

******************************************************************

#include "LibraryItem.hpp"

#include "Movie.hpp"

void Movie::setDirector(std::string d)

{

director = d;

}

std::string Movie::getDirector()

{

return director;

}

int Movie::getCheckOutLength()

{

return CHECK_OUT_LENGTH;

}

***********************************************************************

LibraryItem.hpp ***THIS WAS GIVEN *******DO NOT ALTER*****

******************************************************************

#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);

};

***********************************************************************

LibraryItem.cpp

******************************************************************

#include "LibraryItem.hpp"

using namespace std;

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 code)

{

idCode = code;

}

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 *pco)

{

checkedOutBy = pco

}

Patron* LibraryItem::getRequestedBy()

{

return requestedBy;

}

void LibraryItem::setRequestedBy(Patron* prb)

{

requestedBy = prb;

}

int LibraryItem::getDateCheckedOut()

{

return dateCheckedOut;

}

void LibraryItem::setDateCheckedOut(int date)

{

dateCheckedOut = date;

}

***********************************************************************

Patron.hpp ***THIS WAS GIVEN *******DO NOT ALTER*****

******************************************************************

#ifndef PATRON_HPP

#define PATRON_HPP

#include

#include

#include "LibraryItem.hpp"

class Patron

{

private:

std::string idNum;

std::string name;

std::vector checkedOutItems;

double fineAmount;

public:

Patron(std::string idn, std::string n);

std::string getIdNum();

std::string getName();

std::vector getCheckedOutItems();

void addLibraryItem(LibraryItem* b);

void removeLibraryItem(LibraryItem* b);

double getFineAmount();

void amendFine(double amount);

};

#endif

***********************************************************************

Patron.cpp

******************************************************************

#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;

}

void Patron::setIdNum(std::string idNumber)

{

idNum = idNumber;

}

std::string Patron::getName()

{

return name;

}

void Patron::setName(std::string namePatron)

{

name = namePatron;

}

std::vector Patron::getCheckedOutItems()

{

return checkedOutItems;

}

void Patron::addLibraryItem(LibraryItem* add)

{

checkedOutItems.push_back(add);

}

void Patron::removeLibraryItem(LibraryItem* remove)

{

std::string id;

id = remove->getIdCode();

int size = checkedOutItems.size();

for (int index = 0; 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;

}

***********************************************************************

Library.hpp ***THIS WAS GIVEN *******DO NOT ALTER*****

******************************************************************

#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 holdings;

std::vector members;

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

***********************************************************************

Library.cpp

******************************************************************

#include "LibraryItem.hpp"

#include "Patron.hpp"

#include "Library.hpp"

#include // Included for use of NULL pointers.

#include

#include

using namespace std;

Library::Library()

{

currentDate = 0;

}

Library::~Library()

{

for (int patron = 0; patron

{

delete members[patron];

}

for (int item = 0; item

{

delete holdings[item];

}

}

void Library::addLibraryItem(LibraryItem* item)

{

holdings.push_back(item);

}

void Library::addPatron(Patron* member)

{

members.push_back(member);

}

void Library::checkOutLibraryItem(std::string patronID, std::string ItemID)

{

if (holding == NULL)

{

cout

cout

if (member == NULL)

{

cout

cout

}

return;

}

else if (member == NULL)

{

cout

cout

if (holding == NULL)

{

cout

cout

}

return;

}

if (holding->getLocation() == CHECKED_OUT)

{

Patron* checker = holding->getCheckedOutBy();

if ((checker->getIdNum()) == patronID)

{

cout

cout getName();

cout

return;

}

cout getTitle()

cout

return;

}

if ((holding->getRequestedBy()) != NULL)

{

Patron* holder = holding->getRequestedBy();

if ((holding->getLocation() == ON_HOLD_SHELF) && (holder->getIdNum() != patronID))

{

cout getTitle()

cout

return;

}

}

holding->setCheckedOutBy(member);

holding->setDateCheckedOut(currentDate);

holding->setLocation(CHECKED_OUT);

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 getTitle()

cout getName()

}

void Library::returnLibraryItem(std::string ItemID)

{

LibraryItem* holding = findHolding(ItemID);

if (holding == NULL)

{

cout

cout

return;

}

if (holding->getLocation() != CHECKED_OUT)

{

cout

cout

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 getTitle()

}

void Library::requestLibraryItem(std::string patronID, std::string ItemID)

{

LibraryItem* holding = findHolding(ItemID);

Patron* member = findMember(patronID);

if (holding == NULL)

{

cout

cout

if (member == NULL)

{

cout

cout

}

return;

}

else if (member == NULL)

{

cout

cout

if (holding == NULL)

{

cout

cout

}

return;

}

if (holding->getRequestedBy() != NULL)

{

Patron* holder = holding->getRequestedBy();

if ((holder->getIdNum()) == patronID)

{

cout

cout getName();

cout

return;

}

cout

cout

return;

}

if (holding->getCheckedOutBy() == member)

{

cout

cout

cout

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 getTitle() getName();

cout

}

void Library::incrementCurrentDate()

{

currentDate++;

for (int patron = 0; patron

{

vector payment = members[patron]->getCheckedOutItems();

for (int items = 0; 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

cout

return;

}

//Update fine amount.

member->amendFine(payment);

//Print fine confimration.

cout getName();

cout getFineAmount()

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!