/******************************************************* **returnBook Description: ** 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" *******************************************************/ string Library::returnBook(std::string bID) { //find if Book exists// if (getBook(bID) == NULL) return "Book was not found."; //find if Book // if (getBook(bID)->getLocation() != CHECKED_OUT) return "Book is already in Library."; else { //initiate local pointers if Book exists and is not CHECKED_OUT// Book* bPtr = getBook(bID); Patron* pPtr = bPtr->getCheckedOutBy(); //remove Book from Patron's checkOutBooks// pPtr->removeBook(bPtr); //set Book's location based on request status// if (bPtr->getRequestedBy() == NULL) bPtr->setLocation(ON_SHELF); else bPtr->setLocation(ON_HOLD_SHELF); //set Book's checkedOutBy// bPtr->setCheckedOutBy(NULL); //return was successful// return "Return successful."; } }
//Goes through the public properties of a book and prints them out. //This will print out if a book is checked out AND who requested it, if that situation is true void Library::viewBookInfo(std::string bookID) { Book* book = GetBook(bookID); if(book == NULL) { std::cout << "No such holding exists." << std::endl; } else { std::cout << std::endl << "ID: " << book->getIdCode() << std::endl; std::cout << "Title: " << book->getTitle() << std::endl; std::cout << "Author: " << book->getAuthor() << std::endl; if(book->getLocation() == ON_SHELF) { std::cout << "Location: ON SHELF" << std::endl; } else if(book->getLocation() == ON_HOLD) { std::cout << "Location: ON HOLD" << std::endl; std::cout << "Requested By: " << book->getRequestedBy()->getName() << std::endl; std::cout << "Requested By ID: " << book->getRequestedBy()->getIdNum() << std::endl; } else { std::cout << "Location: CHECKED OUT" << std::endl; std::cout << "Checked out by: " << book->getCheckedOutBy()->getName() << std::endl; std::cout << "Checked out by ID: " << book->getCheckedOutBy()->getIdNum() << std::endl; std::cout << "Due date: " << book->getDateCheckedOut() + 21 << std::endl; if(book->getRequestedBy() != NULL) { std::cout << "This book is also requested by patron: " << book->getRequestedBy()->getIdNum() << std::endl; std::cout << "It should be put on the hold shelf when checked back in." << std::endl; } } } }
//Return a book, if it is not already on the shelf. void Library::returnBook(std::string bookID) { Book* book = GetBook(bookID); if(book == NULL) { std::cout << std::endl << "No such book in holdings." << std::endl << std::endl; return; } if(book->getLocation() == ON_SHELF) { std::cout << "This book is already on the shelf." << std::endl; } else if(book->getLocation() == ON_HOLD) { std::cout << "This book is on the hold shelf and cannot be returned." << std::endl; } else { Patron* patron = book->getCheckedOutBy(); if(book->getRequestedBy() == NULL) { book->setLocation(ON_SHELF); book->setCheckedOutBy(NULL); book->setDateCheckedOut(-1); patron->removeBook(book); } else { book->setLocation(ON_HOLD); book->setCheckedOutBy(NULL); book->setDateCheckedOut(-1); patron->removeBook(book); } } }