本文整理汇总了C++中Book::getLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ Book::getLocation方法的具体用法?C++ Book::getLocation怎么用?C++ Book::getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::getLocation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: requestBook
//Puts a book on the hold shelf, unless it is already requested.
//If checked out, note that it should go to the hold shelf
void Library::requestBook(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->getRequestedBy() == NULL)
{
book->setRequestedBy(patron);
if(book->getLocation() == ON_SHELF)
{
book->setLocation(ON_HOLD);
}
}
else
{
std::cout << "This book is already requested!";
}
}
示例2: requestBook
/*******************************************************
**requestBook 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 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"
*******************************************************/
string Library::requestBook(std::string pID, std::string bID)
{
//find if Book exists//
if (getBook(bID) == NULL)
return "Book not found.";
//find if Patron exists//
if (getPatron(pID) == NULL)
return "Patron not found.";
//set Book's requestedBy and/or location//
//based on current location//
if (getBook(bID)->getLocation() == ON_HOLD_SHELF)
return "Book on hold by another Patron.";
else
{
//initiate local pointers if Book is not already on hold//
Patron* pPtr = getPatron(pID);
Book* bPtr = getBook(bID);
//set Book's requestedBy and location//
bPtr->setRequestedBy(pPtr);
if (bPtr->getLocation() == ON_SHELF)
{
bPtr->setLocation(ON_HOLD_SHELF);
}
//request was successful//
return "Request successful.";
}
}
示例3: 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);
}
}
示例4: viewBookInfo
//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;
}
}
}
}
示例5: 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.";
}
}
}
示例6: returnBook
//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);
}
}
}