当前位置: 首页>>代码示例>>C++>>正文


C++ Patron::addBook方法代码示例

本文整理汇总了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);
    }
}
开发者ID:nathansoz,项目名称:cs161-final,代码行数:50,代码来源:Library.cpp

示例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.";
		}
	}
}
开发者ID:brownnr,项目名称:C-and-Cpp,代码行数:54,代码来源:Library.cpp


注:本文中的Patron::addBook方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。