本文整理汇总了C++中Patron::addBook方法的典型用法代码示例。如果您正苦于以下问题:C++ Patron::addBook方法的具体用法?C++ Patron::addBook怎么用?C++ Patron::addBook使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Patron
的用法示例。
在下文中一共展示了Patron::addBook方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkOutBook
//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);
}
}
示例2: checkOutBook
/*******************************************************
**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.";
}
}
}