Exemple #1
0
/********************************************************************
 *  void Library::viewBookInfo(std::string bookID)
 *
 *  Purpose: This function prints the information of the Book object
 *           that matches the specified bookID to the console.
 *
 *  Preconditions: none
 *
 *  Postconditions: The information of the Book object is printed to
 *                  the console window.
 *******************************************************************/
void Library::viewBookInfo(std::string bookID)
{
    // declare variable and set to book index
    int bIndex = findBook(bookID);
    
    // validate bookID
    if (bIndex < 0)
    {
        std::cout << "\nThat book ID was not found in the library database.\n";
        return;
    }
    
    // print book ID, title and author
    std::cout << "\nInformation on book ID " << holdings[bIndex].getIdCode()
              << "\n  Title:    " << holdings[bIndex].getTitle()
              << "\n  Author:   " << holdings[bIndex].getAuthor();
    
    // print book location
    std::cout << "\n  Location: ";
    switch (holdings[bIndex].getLocation())
    {
        case CHECKED_OUT:
            std::cout << "Checked out\n";
            break;
        case ON_HOLD:
            std::cout << "On hold\n";
            break;
        case ON_SHELF:
            std::cout << "On the shelf\n";
    }
    
    std::cout << std::endl;
    
    // print requestedBy if book has been requested
    Patron *pPatron = holdings[bIndex].getRequestedBy();
    if (pPatron != NULL)
        std::cout << "  This book has been requested by "
                  << pPatron->getName() << ".\n";
    
    // print checkedOutBy and due date if book is checked out
    pPatron = holdings[bIndex].getCheckedOutBy();
    if (pPatron != NULL)
    {
        std::cout << "  This book is checked out by "
                  << pPatron->getName() << ".\n";
        
        // get due date and print appropriate message
        int due = holdings[bIndex].getDateCheckedOut() + Book::CHECK_OUT_LENGTH;
        if (due == currentDate)
            std::cout << "  It is due on day " << due << ", which is today.\n";
        else if (due > currentDate)
            std::cout << "  It is due on day " << due << ", "
                      << "which is in " << due - currentDate << " days.\n";
        else
            std::cout << "  It is due on day " << due << ", "
                      << "which was " << currentDate - due << " days ago.\n";
    }
}
Exemple #2
0
//Same as above. Uses viewBookInfo to print books checked out to a patron.
void Library::viewPatronInfo(std::string patronID)
{
    Patron* patron = GetPatron(patronID);

    if(patron == NULL)
    {
        std::cout << std::endl << "That patron does not exist!" << std::endl;
    }
    else
    {
        std::cout << std::endl << "Patron ID: " << patron->getIdNum() << std::endl;
        std::cout << "Name: " << patron->getName() << std::endl;
        std::cout << "Fines: $" << std::setprecision(2) << std::fixed << patron->getFineAmount() << std::endl;

        if(patron->getCheckedOutBooks().size() == 0)
        {
            std::cout << "No checked out books." << std::endl << std::endl;
        }
        else
        {
            std::cout << "Checked out books:" << std::endl << std::endl;
            for(int i = 0; i < patron->getCheckedOutBooks().size(); i++)
            {
                viewBookInfo(patron->getCheckedOutBooks().at(i)->getIdCode());
            }
            std::cout << std::endl << std::endl;
        }
    }
}