//Takes a patron and book ID //Checks to make sure that the patron and book exist, returns if they dont //If book is on hold, only check out to that patron //If the book is on the shelf, it's fair game, set proper values. void Library::checkOutBook(std::string patronID, std::string bookID) { Book* book = GetBook(bookID); Patron* patron = GetPatron(patronID); if(book == NULL || patron == NULL) { if(book == NULL) { std::cout << std::endl << "No such book in holdings." << std::endl; } if(patron == NULL) { std::cout << std::endl << "No such patron in records." << std::endl; } return; } if(book->getLocation() == CHECKED_OUT) { std::cout << "This book is already checked out." << std::endl << std::endl; } else if(book->getLocation() == ON_HOLD) { if(book->getRequestedBy()->getIdNum() == patron->getIdNum()) { book->setLocation(CHECKED_OUT); book->setCheckedOutBy(GetPatron(patronID)); book->setDateCheckedOut(currentDate); book->setRequestedBy(NULL); patron->addBook(book); } else { std::cout << "This book is on hold and can only be checked out to requestee." << std::endl <<std::endl; } } else { book->setLocation(CHECKED_OUT); book->setCheckedOutBy(patron); book->setDateCheckedOut(currentDate); patron->addBook(book); } }
/******************************************************* **checkOutBook Description: ** 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" *******************************************************/ string Library::checkOutBook(string pID, string bID) { //find if Book and/or Patron exist// if (getBook(bID) == NULL) return "Book not found."; if (getPatron(pID) == NULL) return "Patron not found."; else { //initiate local pointers if Book and Patron exist// Book* bPtr = getBook(bID); Patron* pPtr = getPatron(pID); //find location of Book// if (bPtr->getLocation() == CHECKED_OUT) return "Book already checked out."; else if (bPtr->getLocation() == ON_HOLD_SHELF && bPtr->getRequestedBy() != pPtr) return "Book is on hold by another Patron."; //set Book's checkedOutBy, dateCheckedOut, location & requestedBy// else { bPtr->setCheckedOutBy(pPtr); bPtr->setDateCheckedOut(currentDate); bPtr->setLocation(CHECKED_OUT); bPtr->setRequestedBy(NULL); //add Book to Patron's checkedOutBooks// pPtr->addBook(bPtr); //check out was successful// return "Check out successful."; } } }