Esempio n. 1
0
//adding a book in alphabetical order
void BookTracker::add(string bookName, int haveValue, int wantValue) {
    BookNode *bookNode = new BookNode(bookName, haveValue, wantValue);
    if (head == nullptr) {
        head = bookNode;
    } else {
        //if book is found print out info
        try {
            bookNode = findBook(bookName);
            cout << "Book was already added" << endl;
            cout << bookNode->toString() << endl;
            //if exception is caught proceed to add book
        } catch (exception e) {
            BookNode *current = head;
            BookNode *previous = head;
            while (current != nullptr && bookNode->getBookName().compare(current->getBookName()) > 0) {
                previous = current;
                current = current->getNext();
            }

            //if the book being added belongs at the head
            if (current == head) {
                bookNode->setNext(head);
                head = bookNode;
            } else {
                bookNode->setNext(current);
                previous->setNext(bookNode);
            }
        }
    }
}
Esempio n. 2
0
void Library::addBook()
{
	/*
	 * addBook - prompts the user for book info and uses it to create
	 *					 a Book, which is added to holdings  
	 */
	if (DBG_FUN) std::cout << "Library::addBook" << std::endl;
	 
	std::string tmpTitle;  // temporary storage for user input
	std::string tmpAuthor;
	std::string tmpID;

	std::cout << "Title: ";
	getline(std::cin, tmpTitle); // No validation is done on input
	std::cout << "Author: ";
	getline(std::cin, tmpAuthor);
	std::cout << "Book ID (ISBN####): ";
	getline(std::cin, tmpID);

	int checkID = findBook(tmpID); // Look for that tmpID in holdings
	if ( checkID >=0 )
	{
		std::cout << "Sorry, that Book ID is already in use." << std::endl;
		return;
	}

	Book book(tmpID,tmpTitle,tmpAuthor);
	holdings.push_back(book);
	std::cout << "Added book " << tmpTitle << " with ID " << tmpID <<std::endl;
}
Esempio n. 3
0
/********************************************************************
 *  void Library::returnBook(std::string bookID)
 *
 *  Purpose: This function returns the Book object with the specified ID
 *           to the library.
 *
 *  Preconditions: none
 *
 *  Postconditions: The return operation succeeds if the following
 *                  conditions hold:
 *                  - the library has a Book object with an ID of bookID
 *                  - the Book object is checked out
 *                  If the Book object is not requested by another Patron,
 *                  the location is set to ON_SHELF.
 *                  If the Book object is requested by another Patron,
 *                  the location is set to ON_HOLD.
 *******************************************************************/
void Library::returnBook(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;
    }
    
    // validate current location
    if (holdings[bIndex].getLocation() != CHECKED_OUT)
    {
        std::cout << "\nThat book is not checked out right now.\n";
        return;
    }
    
    // remove book from current patron checkedOutBooks
    holdings[bIndex].getCheckedOutBy()->removeBook(&(holdings[bIndex]));
    
    // set book checkedOutBy to NULL
    holdings[bIndex].setCheckedOutBy(NULL);
    
    // check if requested by another patron
    if (holdings[bIndex].getRequestedBy() != NULL)
        holdings[bIndex].setLocation(ON_HOLD);
    else
        holdings[bIndex].setLocation(ON_SHELF);
    
    // print confirmation message
    std::cout << "\n\"" << holdings[bIndex].getTitle() << "\""
              << " has been returned to the library.\n";
}
Esempio n. 4
0
/********************************************************************
 *  void Library::addBook()
 *
 *  Purpose: This function prompts the user for book information and
 *           adds a Book object set with that information to the library.
 *
 *  Preconditions: none
 *
 *  Postconditions: If a unique idCode was entered, the library contains 
 *                  a Book object with the specified values.
 *******************************************************************/
void Library::addBook()
{
    std::string idCode, title, author;  // user input
    
    // prompt user for book ID
    std::cout << "\nEnter the book ID: ";
    std::getline(std::cin, idCode);
    
    // check if ID is already in use
    if (findBook(idCode) >= 0)
    {
        std::cout << "\nThat ID is already in use.\n";
        return;
    }
    
    // prompt user for book title
    std::cout << "Enter the book title: ";
    std::getline(std::cin, title);
    
    // prompt user for book author
    std::cout << "Enter the book author: ";
    std::getline(std::cin, author);
    
    // add book object to holdings
    std::cout << "\nAdding \"" << title << "\" to records.\n";
    holdings.push_back(Book (idCode, title, author));
}
Esempio n. 5
0
void Library::viewBookInfo(std::string bookID)
{
	/*
	 * • viewBookInfo
	 *	◦ if the specified Book is not in the Library, print out that
	 *		message and return to the menu
	 *	◦ print the Book's ID, title, author and location; if it's on
	 *		request, print who it's requested by; if it's checked	out,
	 *		print who it's checked out by, and it's due date (date checked
	 *		out + check out length)
	 *	• be careful - a Book can be on request without its location being
	 *		the hold shelf (if another Patron has it checked out);
	 */
  if (DBG_FUN) std::cout << "Library::viewBookInfo" << std::endl;
	bool bookFound = false;
	std::string tab = "            ";
  
	int book = findBook(bookID);

	if (book < 0)
	{
		std::cout << "Couldn't find that book in our collection." << std::endl;
		return;
	}


  // Print the ID, Title and Author of the book
	std::cout << holdings[book].getIdCode() << "    " 
		<< holdings[book].getTitle() << ",  "
		<< holdings[book].getAuthor() << std::endl;

	Locale location = holdings[book].getLocation();
	Patron * requestedBy = holdings[book].getRequestedBy();


	// To avoid screen noise, don't show location if it's on the shelf
  // If the book is NOT on the shelf, print it's location and show
	// which member has it checked out and/or on hold

	if (location == CHECKED_OUT)
	{
		std::cout << tab << "Current location: " << LocaleString[location] 
			<< " to " << (*(holdings[book].getCheckedOutBy())).getName()
			<< ", due date is " 
			<< (holdings[book].getDateCheckedOut() + Book::CHECK_OUT_LENGTH )
			<< std::endl;
	}
	else if (location == ON_HOLD || requestedBy != NULL ) {
		// If the location is ON HOLD, or if the book is on the shelf but
		// requested by someone, print the location
		std::cout << tab << "Current location: " << LocaleString[location] << std::endl;
	}
	if ( requestedBy != NULL )
	{
		// Print if someone has the book on hold
		std::cout << tab << "Hold requested by: " << (*requestedBy).getName() << std::endl;
		return;
	}
}
Esempio n. 6
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";
    }
}
Esempio n. 7
0
//method for changing the want value of a
//specific book.
void BookTracker::changeWantValue(string bookName, int newValue) {
    try {
        BookNode *node = findBook(bookName);
        node->setWantValue(newValue);
    } catch(exception e) {
        //rethrow error
        throw e;
    }
}
Esempio n. 8
0
//get's book information for specific book
string BookTracker::getBookInfo(string bookName) {
    try {
        BookNode *node = findBook(bookName);
        return node->toString();
    } catch (exception e) {
        //rethrow exception
        throw e;
    }
}
Esempio n. 9
0
void Library::requestBook(std::string patronID, std::string bookID)
{
	/*
	 * requestBook
	 *	◦ if the specified Book or Patron are not in the Library, print out
	 *		that message and return to the menu
	 *	◦ if the Book is already requested by another Patron, print out that
	 *		message and return to the menu
	 *	◦ update the Book's requestedBy; if the Book is on the shelf, update
	 *		its location to on hold; print that Book title is on request for
	 *		Patron name
	 */
  if (DBG_FUN) std::cout << "Library::requestBook" << std::endl;
	int book;
	int member;
	Locale location;

	book = findBook(bookID);
	if (book < 0 ) {
		std::cout << "ERROR: Couldn't find that book in our collection." 
			<< std::endl;
		return;
	}
	member = findMember(patronID);
	if (member < 0 ){
		std::cout << "ERROR: Couldn't find that person in our membership" 
			<< std::endl;
		return;
	}

	if ( holdings[book].getRequestedBy() != NULL) 
	{
		std::cout << "That book is already on hold; " 
			<< "only one hold allowed at a time." << std::endl;
		return;
	}

  if ( holdings[book].getCheckedOutBy() != NULL ) {
  	if ( patronID.compare((*(holdings[book].getCheckedOutBy())).getIdNum()) == 0 )
		{
			std::cout << "ERROR: Can't put a hold on a book you've checked out" << std::endl;
			return;
		}
	}


  // Update the Book  with the request
  holdings[book].setRequestedBy(& members[member]);
	location = holdings[book].getLocation();
	if (location == ON_SHELF){
		holdings[book].setLocation(ON_HOLD);
	}

	std::cout << "\"" << holdings[book].getTitle() << " is on hold for " <<
		members[member].getName() << std::endl;
}
Esempio n. 10
0
//adds new costumer to waiting list
void BookTracker::addToWaitlist(string bookNameIn, string costumerNameIn) {
    try {
        BookNode *node = findBook(bookNameIn);
        WaitList *list = node->getList();
        list->enqueue(costumerNameIn);
    } catch (logic_error e) {
        //rethrow error
        throw e;
    }
}
Esempio n. 11
0
/********************************************************************
 *  void Library::checkOutBook(std::string patronID, std::string bookID)
 *
 *  Purpose: This function has the Patron object with the specified ID
 *           check out the Book object with the specified ID.
 *
 *  Preconditions: none
 *
 *  Postconditions: The check out operation succeeds if the following
 *                  conditions hold:
 *                  - the library has a Patron object with an ID of patronID
 *                  - the library has a Book object with an ID of bookID
 *                  - the Book object is not already checked out
 *                  - the Book object is not on hold by another Patron object
 *******************************************************************/
void Library::checkOutBook(std::string patronID, std::string bookID)
{
    // declare and set to indices of book and patron
    int bIndex = findBook(bookID),
        mIndex = findMember(patronID);
    
    // validate patronID and bookID
    if (bIndex < 0)
    {
        std::cout << "\nThat book ID was not found in the library database.\n";
        return;
    }
    if (mIndex < 0)
    {
        std::cout << "\nThat member ID was not found in the library database."
                  << "\n";
        return;
    }
    
    // check current location
    switch (holdings[bIndex].getLocation())
    {
        case CHECKED_OUT:
            std::cout << "\nThat book is already checked out.\n";
            return;
        case ON_HOLD:
            // check if on hold by requester
            if (holdings[bIndex].getRequestedBy()->getIdNum() != patronID)
            {
                std::cout << "\nThat book is on hold by another member.\n";
                return;
            }
            // on hold by requester. reset requestedBy
            holdings[bIndex].setRequestedBy(NULL);
            // here we intentionally fall through
        case ON_SHELF:
            // update location to CHECKED_OUT
            holdings[bIndex].setLocation(CHECKED_OUT);
            // update checkedOutBy to requester
            holdings[bIndex].setCheckedOutBy(&(members[mIndex]));
            // update dateCheckedOut to currentDate
            holdings[bIndex].setDateCheckedOut(currentDate);
            // add pointer to patron checkedOutBooks
            members[mIndex].addBook(&(holdings[bIndex]));
            // print confirmation message
            std::cout << "\n\"" << holdings[bIndex].getTitle() << "\""
                      << " is now checked out to "
                      << members[mIndex].getName() << ".\n";
    }
}
Esempio n. 12
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
    connect(ui->actionLogin, SIGNAL(triggered()), this, SLOT(startLogin()));

    m_pForm = new Form(this);

    connect(ui->actionFind, SIGNAL(triggered()), m_pForm, SLOT(findBook()));

    setCentralWidget(m_pForm);


}
Esempio n. 13
0
void Library::returnBook(std::string bookID)
{
	/*
	 * returnBook
	 *	◦ if the specified Book is not in the Library, print out that message 
	 *		and return to the menu
	 *	◦ if the Book is not checked out, print out that message and return to 
	 *		the menu
	 *	◦ update the Patron's list; update the Book's location (and possibly 
	 *		requestedBy) depending on whether another Patron has requested it; 
	 *		print out that Book title has been returned
	 */
  if (DBG_FUN) std::cout << "Library::returnBook" << std::endl;
	int book;
	int member;
	Locale location;

	book = findBook(bookID);
	if (book < 0 )
	{
		std::cout << "ERROR: Couldn't find that book in our collection." << std::endl;
		return;
	}
	if ( holdings[book].getLocation() != CHECKED_OUT) 
	{
		std::cout << "Our records indicate that book is not checked out." << std::endl;
		return;
	}
	std::cout << "Returning book " << holdings[book].getTitle() << " to library" << std::endl;

	// Update the members list of checked out books
	member = findMember( (*(holdings[book].getCheckedOutBy())).getIdNum() );
	members[member].removeBook(& holdings[book]);

	// If there's a hold on the book, move it to ON_HOLD, otherwise
	// return it to the shelf
	if ( holdings[book].getRequestedBy() != NULL )
	{
		std::cout << "Putting book on hold for "
			<< (* (holdings[book].getRequestedBy())).getName() << std::endl;
		holdings[book].setLocation(ON_HOLD);
	}
	else
	{
		holdings[book].setLocation(ON_SHELF);
	}
}
Esempio n. 14
0
//removes next person from queue
void BookTracker::sellBook(string bookNameIn) {
    try {
        BookNode *node = findBook(bookNameIn);
        WaitList *list = node->getList();
        //if the list is not empty
        if (list->peek() != nullptr) {
            throw out_of_range("There are people waiting for this book. ");
        }
        node->addToHaveValue(-1);
    } catch (invalid_argument e) {
        //rethrow error
        throw e;
    } catch (out_of_range x) {
        //rethrow error
        throw x;
    }
}
Esempio n. 15
0
/********************************************************************
 *  void Library::requestBook(std::string patronID, std::string bookID)
 *
 *  Purpose: This function has the Patron object with the specified ID
 *           request the Book object with the specified ID.
 *
 *  Preconditions: none
 *
 *  Postconditions: The request operation succeeds if the following
 *                  conditions hold:
 *                  - the library has a Patron object with an ID of patronID
 *                  - the library has a Book object with an ID of bookID
 *                  - the Book object is not requested by another Patron object
 *                  - the Book object is not checked out by same Patron object
 *******************************************************************/
void Library::requestBook(std::string patronID, std::string bookID)
{
    // declare and set to indices of book and patron
    int bIndex = findBook(bookID),
        mIndex = findMember(patronID);
        
    // validate patronID and bookID
    if (bIndex < 0)
    {
        std::cout << "\nThat book ID was not found in the library database.\n";
        return;
    }
    if (mIndex < 0)
    {
        std::cout << "\nThat member ID was not found in the library database."
                  << "\n";
        return;
    }

    // check if already requested
    if (holdings[bIndex].getRequestedBy() != NULL)
    {
        std::cout << "\nThat book is already requested by another member.\n";
        return;
    }
    else if (holdings[bIndex].getCheckedOutBy() != NULL
             && holdings[bIndex].getCheckedOutBy()->getIdNum() == patronID)
    {
        // cannot request book that is checked out by requester
        std::cout << "\nA member cannot request a book that he or she "
                  << "already has checked out.\n";
        return;
    }
    
    // set requestedBy of book to requester
    holdings[bIndex].setRequestedBy(&(members[mIndex]));
    
    // update location only if ON_SHELF
    if (holdings[bIndex].getLocation() == ON_SHELF)
        holdings[bIndex].setLocation(ON_HOLD);
    
    // print confirmation message
    std::cout << "\n\"" << holdings[bIndex].getTitle() << "\""
              << " is now on request by "
              << members[mIndex].getName() << ".\n";
}
Esempio n. 16
0
// for ex17.4
// print the result using the given iostream
void reportResults(std::istream& in, std::ostream os,
                   const std::vector<std::vector<Sales_data>>& files)
{
    std::string s;
    while(in >> s)
    {
        auto trans = findBook(files, s);
        if(trans.empty()){
            std::cout << s << "not found in any stores" << std::endl;
            continue;
        }

        for(const auto& store :trans)
            os << "store " << std::get<0>(store) << " sales: "
               << std::accumulate(std::get<1>(store), std::get<2>(store),
                                  Sales_data(s))
                  << std::endl;
    }
}
Esempio n. 17
0
		/*
		  This function deletes a book from the array by setting setting the 
		  m_empty member to true.

		  Checked it.  Looks good.
		*/
		void BookCollection::deleteBook()
		{
			std::string input;		// To hold user string input.
			char choice;			// To hold the user's choice
			std::list<BookData>::iterator pos;	// iterator

			// Ask the user for the title or ISBN of the book
			std::cout << "Please enter the title or ISBN of the "
				<< "book." << std::endl;
			std::getline(std::cin, input);

			// pass the user input to the findBook function
			pos = findBook(input);

			// If the book wasn't found
			if (pos == bookList.end())
			{
				std::cout << "The book was not found" << std::endl;
			} // end if
			// Otherwise
			else
			{
				// display the book's info
				pos->bookInfo();

				// Confirm
				std::cout << "Are you sure you want to delete this book?  "
					<< " Press y to confirm or any other key to quit."
					<< std::endl;
				std::getline(std::cin, input);
				choice = input.at(0);

				if (choice == 'y')
				{
					pos = bookList.erase(pos);
				} // end if
				
			} // end else

		} // end function deleteBook
Esempio n. 18
0
//dequeue people
string BookTracker::emptyWaitList(string bookName) {
    string result = "";
    try {
        BookNode *node = findBook(bookName);
        WaitList *list = node->getList();

        if (list->peek() != nullptr) {
            result = bookName;
            int maxHave = node->getHaveValue();
            for (int i = 0; i < maxHave && list->peek() != nullptr; i++) {
                result = result + "\n\t";
                result = result + node->removeCostumer();
            }
            result = result + "\nHave all been removed from " + bookName + "'s waiting list\n\n";
        }
        return result;
    } catch (logic_error e) {
        //rethrow
        throw e;
    }

    return result;
}
Esempio n. 19
0
//adds a book from formatted string with delimitor
//returns book with those off waitlist
string BookTracker::addBookFromDeliveryString(string lineIn) {
    string line = lineIn;
    string word = "";
    const int NUMOFPARAMS = 3;

    //get params in a array
    string bookParams[NUMOFPARAMS];
    stringstream splitter(line);
    for (int i = 0; i < NUMOFPARAMS; i++) {
        if (getline(splitter, word, '~')) {
            bookParams[i] = word;
        }
    }

    int have, want;
    string name = "";
    //store params for creation
    name = bookParams[0];
    have = stoi(bookParams[1]);
    want = stoi(bookParams[2]);

    try {
        string result = "";
        BookNode *node = findBook(name);
        node->addToHaveValue(have);
        node->setWantValue(want);
        result = emptyWaitList(name);
        return result;
    } catch (logic_error e) { //add book if not found
        add(name, have, want);
        return "The book " + name + " has been added to the Inventory.";
    }

    return "";

}
Esempio n. 20
0
int main (int argc, char **argv){
   int EXIT_STATUS = 0;
   
   FILE *info = fopen (argv[1], "r");  //open file for scanning
   if(info == NULL){  //check for valid filename, if not exit with status 1
      fflush(NULL);
      fprintf(stderr,"Invalid file name!\n");
      fflush(NULL);
      EXIT_STATUS = 1;
      exit(EXIT_STATUS);
   }

   long numcustomers;  //variable for # of customers
   long numpurchases;  //variable for # of purchases
   long hashsize;
   fscanf(info, "%ld", &numcustomers);  //scan in first number as # customers
   fscanf(info, "%ld", &numpurchases);  //scan in next number as # customers
   fscanf(info, "%ld", &hashsize);

   hashRef bookhash = newHash(hashsize);

   ListRef customers[numcustomers+1];  //create array that holds list for each customer

   for(int i = 1; i<numcustomers+1; i++){  //create a list for each customer
      customers[i] = newList();
   }

   long bookid = 0;  //variables for custid and bookid
   long custid = 0;
   int printrecbool = 0;
   int check = 0;    //variable to check for EOF

   fscanf(info, "%ld %ld %d", &custid, &bookid, &printrecbool);  //initial scan of custID and bookID
   while(check != EOF){  //loop until we reach end of file
      insertAfterLast(customers[custid], bookid);  //add bookID to appropriate customer list
      insertBookList(bookhash, bookid);            //inserts book into the hash

      for(NodeRef current = customers[custid]->first; current != NULL; current = current->next){
         if(current->data != bookid){
            int index = hashKey(bookhash, bookid);
            bookNodeRef temp = findBook(bookhash->purchasedBooks[index], bookid);
            insertAfterLast(temp->copurchases, current->data);

            index = hashKey(bookhash, current->data);
            temp = findBook(bookhash->purchasedBooks[index], current->data);
            insertAfterLast(temp->copurchases, bookid);
         }
      }


      if(printrecbool){
         int index = hashKey(bookhash, bookid);
         bookNodeRef temp = findBook(bookhash->purchasedBooks[index], bookid);
         NodeRef mostfreq = highestCount(temp->copurchases, customers[custid]);
         printf("Customers buying book %ld also purchased book %ld\n", bookid, mostfreq->data);
      }
      check = fscanf(info, "%ld %ld %d", &custid, &bookid, &printrecbool);  //scan in next custID and bookID
   }



   fclose(info);

   return EXIT_STATUS;
}
Esempio n. 21
0
void Library::checkOutBook(std::string patronID, std::string bookID)
{
	/*
	 * checkOutBook
	 *	◦ if the specified Book or Patron are not in the Library (an ID doesn't
	 *		match an object in the Library), print out that message and return
	 *		to the 	menu
	 *	◦ if a Book is already checked out, print out that message and return
	 *		to the menu
	 *	◦ if a Book is on hold by another Patron, print out that message and
	 *		return to the menu
	 *	◦ if a Book is on hold by this Patron, unset that
	 *
	 *	◦ update the Book's checkedOutBy, dateCheckedOut and Location;
	 *		update the Patron's list; print out that Book title has been checked out to
	 *		Patron name
	 */
  if (DBG_FUN) std::cout << "Library::checkOutBook" << std::endl;

	int book;
	int member;
	Locale location;

	book = findBook(bookID);
	if (book < 0 ){
		std::cout << "ERROR: Couldn't find that book in our collection" << std::endl;
		return;
	}
	member = findMember(patronID);
	if (member < 0 ){
		std::cout << "ERROR: Couldn't find that person in our membership" << std::endl;
		return;
	}

	location = holdings[book].getLocation();
	switch (location){
		case CHECKED_OUT:
			std::cout << "Sorry, that book is currently checked out to "
				<< (*(holdings[book].getCheckedOutBy())).getName() << std::endl;
			return;
			break;
		case ON_HOLD:
			if( patronID.compare((*(holdings[book].getRequestedBy())).getIdNum()) !=0 )
			{
				std::cout << "Sorry, that book is currently on hold for " 
				<< (*(holdings[book].getRequestedBy())).getName() << std::endl;
				return;
			}
			else
			{
				// If the member trying to check out the book is the member
				// who has it on hold, that works.
				std::cout << "Releasing member's hold on book." << std::endl;
				
				// No break or return here!! Fall through to next case.
				
			}
		case ON_SHELF:
			std::cout << "Checking out book." << std::endl;
			// Update the book
			holdings[book].setCheckedOutBy(& members[member]);
			holdings[book].setDateCheckedOut(currentDate);
			holdings[book].setLocation(CHECKED_OUT);
			holdings[book].setRequestedBy(NULL);

   		// Update the member
			members[member].addBook(& holdings[book]);

			std::cout << "\"" << holdings[book].getTitle() << "\"  has been checked out by " 
				<< members[member].getName() <<std::endl;
			break;
	}
}
Esempio n. 22
0
		/*
		  This function edits a BookData object
		  Checked it.  Looks good.
		*/
		void BookCollection::editBook()
		{
			std::string input;		// To hold user string input.
			int iinput;		// To hold user int input
			double dinput;		// To hold user double input
			std::list<BookData>::iterator pos;	// To hold the postion of the book
			int choice = 0;			// Stores user's menu choice

			// Ask the user for the title or ISBN of the book
			std::cout << "Please enter the title or ISBN of the "
				<< "book." << std::endl;
			std::getline(std::cin, input);

			// pass the user input to the findBook function
			pos = findBook(input);

			// If the returned position is -1 then the book wasn't found
			if (pos == bookList.end())
			{
				std::cout << "The book was not found" << std::endl;
			} // end if
			// Otherwise
			else
			{
				// display the book's information
				pos->bookInfo();

				do
				{
					// Find out which field the user wants to edit.
					std::cout << "Select the field to edit or press exit menu."
						<< std::endl;
					std::cout << "   1. Book title\n";
					std::cout << "   2. ISBN number\n";
					std::cout << "   3. Author's name\n";
					std::cout << "   4. Publisher's name\n";
					std::cout << "   5. The date the book was added to inventory\n";
					std::cout << "   6. The quantity of this book\n";
					std::cout << "   7. The wholesale cost of the book\n";
					std::cout << "   8. The retail price of the book\n";
					std::cout << "   9. Exit\n\n";

					// Display prompt and get user's choice
					std::cout << "   Enter your choice: ";
					std::getline(std::cin, input);
					choice = atoi(input.c_str());
        
					// Validate user's entry
					while (choice < 1 || choice > 9)
					{
						std::cout << "\n   Please enter a number in the "
							<< "range 1 - 9. ";
						std::getline(std::cin, input);
						choice = atoi(input.c_str());
					} // end while
		
					switch (choice)
					{
						case 1: 
							// Get the title from the user
							std::cout << "Enter the name of the book: ";
							std::getline(std::cin, input);
							pos->setTitle(input);
							std::cout << std::endl;
							break;
						case 2:	
							// Get the isbn from the user
							std::cout << "Enter the isbn of the book: ";
							std::getline(std::cin, input);
							pos->setIsbn(input);
							std::cout << std::endl;
						break;
						case 3:	
							// Get the author of the books 
							std::cout << "Enter the author of the book: ";
							std::getline(std::cin, input);
							pos->setAuthor(input);
							std::cout << std::endl;
							break;
						case 4:
							// Get the publisher of the book
							std::cout << "Enter the publisher of the book: ";
							std::getline(std::cin, input);
							pos->setPublisher(input);
							std::cout << std::endl;
							break;
						case 5:
							// Get the date added of the book
							std::cout << "Enter the date added of the book: ";
							std::getline(std::cin, input);
							pos->setDateAdded(input);
							std::cout << std::endl;
							break;
						case 6:
							// Get the quantity of the book
							std::cout << "Enter the quantity of the book: ";
							std::getline(std::cin, input);
							iinput = atoi(input.c_str());
							pos->setQuantity(iinput);
							std::cout << std::endl;
							break;
						case 7:
							// Get the wholesale cost of the book
							std::cout << "Enter the wholesale cost of " 
								<< "the book: ";
							std::getline(std::cin, input);
							dinput = atof(input.c_str());
							pos->setWholesaleCost(dinput);
							std::cout << std::endl;
							break;
						case 8:
							// Get the retail price of the book
							std::cout << "Enter the retail price of the book: ";
							std::getline(std::cin, input);
							dinput = atof(input.c_str());
							pos->setRetailPrice(dinput);
							std::cout << std::endl;
							break;

					} // end switch
				} while (choice != 9); // end do while

			} // end else

		} // end function editBook