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

I have an assignemt that is You will be writing a Library simulator. It will hav

ID: 666981 • Letter: I

Question

I have an assignemt that is

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:

Book.hpp

Patron.hpp

Library.hpp

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:

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.

I did some but the results are NOT correct

my cpp files are

Book.cpp

#include "Book.hpp"

#include

using namespace std;

/*Book::Book()

{

   idCode = "default";

   title = "defalut";

   author = "default";

   location = ON_SHELF;

}*/

Book::Book(std::string idc, std::string t, std::string a){

   idCode = idc;

   title = t;

   author = a;

   location = ON_SHELF;

}

string Book::getIdCode(){

   return idCode;

}

string Book::getTitle(){

   return title;

}

string Book::getAuthor(){

   return author;

}

Locale Book::getLocation(){

   return location;

}

void Book::setLocation(Locale lo){

   location = lo;

}

Patron* Book::getCheckedOutBy(){

   return checkedOutBy;

}

void Book::setCheckedOutBy(Patron* p){

   checkedOutBy = p;

}

Patron* Book::getRequestedBy(){

   return requestedBy;

}

void Book::setRequestedBy(Patron* p){

   requestedBy = p;

}

int Book::getDateCheckedOut(){

   return dateCheckedOut;

}

void Book::setDateCheckedOut(int d){

   dateCheckedOut = d;

}


Patron.cpp

#include "Patron.hpp"

#include

using namespace std;

/*Patron::Patron(){

   idNum = "0";

   name = "default";

}*/

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

   idNum = idn;

   name = n;

}

string Patron::getIdNum(){

   return idNum;

}

string Patron::getName(){

   return name;

}

vector Patron::getCheckedOutBooks(){

   return checkedOutBooks;

}

void Patron::addBook(Book* b){

   checkedOutBooks.push_back(b);

}

void Patron::removeBook(Book* b){

   for(int i = 0; i < checkedOutBooks.size(); ++i){

   if(checkedOutBooks[i] == b){

   checkedOutBooks.erase(checkedOutBooks.begin() + i);

   break;

   }

   }

}

double Patron::getFineAmount(){

  

   return fineAmount;

}

void Patron::amendFine(double amount){

   fineAmount += amount;

}


Library.cpp

#include "Library.hpp"

#include

using namespace std;

Library::Library()

{

currentDate=0;

}

void Library::addBook(Book* b)

{

holdings.push_back(b);

}

// Add Patron function

void Library::addPatron(Patron* p){

   members.push_back(p);

}

std::string Library::checkOutBook(std::string pID, std::string bID){

   Book* b = getBook(bID);

   if (b == NULL)

   return "book not found";

  

   Patron* p = getPatron(pID);

   if (p == NULL)

   return "patron not found";

  

   Patron* p1 = b->getCheckedOutBy();

   if (p1 != NULL){

   b->setDateCheckedOut(currentDate);

   b->setLocation(CHECKED_OUT);

   b->setCheckedOutBy(p);

   p->addBook(b);

   return "book already checked out";}

  

   Patron* p2 = b->getRequestedBy();

   if (p2 != NULL)

   return "book on hold by other patron";

  

   b->setDateCheckedOut(currentDate);

   b->setLocation(CHECKED_OUT);

   b->setCheckedOutBy(p);

   p->addBook(b);

   return "check out successful";

}

std::string Library::returnBook(std::string bID){

   Book* b = getBook(bID);

   if (b == NULL)

   return "book not found";

  

   Patron* p = b->getCheckedOutBy();

   if (p == NULL)

   return "book already in library";

   p->removeBook(b);

  

   Patron* p1 = b->getRequestedBy();

   if (p1 == NULL)

   b->setLocation(ON_SHELF);

   else{

   b->setDateCheckedOut(currentDate);

   b->setLocation(CHECKED_OUT);

   b->setCheckedOutBy(p1);

   p1->addBook(b);

   }

   return "return successful";

}

std::string Library::requestBook(std::string pID, std::string bID){

   Book* b = getBook(bID);

   if (b == NULL)

   return "book not found";

  

   Patron* p = getPatron(pID);

   if (p == NULL)

   return "patron not found";

  

   Patron* p1 = b->getRequestedBy();

   if (p1 != NULL)

   return "book on hold by other patron";

  

   b->setRequestedBy(p1);

   b->setLocation(ON_HOLD_SHELF);

   return "request successful";

}

std::string Library::payFine(std::string pID, double payment){

   Patron* p = getPatron(pID);

   if (p == NULL)

   return "patron not found";

  

   if (payment < 0)

   return "Fine should be positive";

  

   p->amendFine(payment);

   return "payment successful";

}

void Library::incrementCurrentDate(){

   currentDate++;

}

Patron* Library::getPatron(std::string pID){

   for (int i = 0; i < members.size(); i++){

   Patron* p = members[i];

   if (p->getIdNum() == pID) return p;

   }

   return NULL;

}

Book* Library::getBook(std::string bID){

   for (int i = 0; i < holdings.size(); i++){

   Book* b = holdings[i];

   if (b->getIdCode() == bID) return b;

   }

   return NULL;

}

testing.cpp

#include "Book.hpp"

#include "Patron.hpp"

#include "Library.hpp"

#include

#include

using namespace std;

int main()

{

Book b1("123", "War and Peace", "Tolstoy");

Book b2("234", "Moby Dick", "Melville");

Book b3("345", "Phantom Tollbooth", "Juster");

Book b4("456", "ahmed", "ali");

Patron p1("abc", "Felicity");

Patron p2("bcd", "Waldo");

Patron p3("hhh", "ahm");

Library lib;

lib.addBook(&b1);

lib.addBook(&b2);

lib.addBook(&b3);

lib.addPatron(&p1);

lib.addPatron(&p2);

//lib.requestBook("bcd", "234");

cout<< lib.checkOutBook("abc", "345")<

cout << lib.checkOutBook("hhh", "234") << endl;

cout<< lib.requestBook("bcd", "123")<

cout << lib.returnBook("345") << endl;

for (int i=0; i<7; i++)

   lib.incrementCurrentDate();

   cout << lib.checkOutBook("abc", "123") << endl;

   cout << lib.checkOutBook("abc", "345") << endl;

for(int i=0; i<24; i++)

   lib.incrementCurrentDate();

lib.payFine("abc", 1.4);

double p1Fine = p1.getFineAmount();

   cout<<"Patron p1 fine Amount:"<

double p2Fine = p2.getFineAmount();

   cout<<"Patron p2 fine Amount:"<

return 0;

}

the results

book already checked out

patron not found

book on hold by other patron

return successful

book already checked out

book already checked out

Patron p1 fine Amount:1.4

Patron p2 fine Amount:1.07124e-312

is that correct? amount fine has to be 0.10 cent each day after deadline

Explanation / Answer

Ans:

Please refer Book.hpp, Patron.hpp, Library.hpp from question

Menu.cpp

Patron.cpp

Library.cpp

Book.cpp

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