Example #1
0
	bool operator <(const Book &book1, const Book &book2)
	{
        int compare = book1.getAuthor().compare(book2.getAuthor());

        if (compare < 0)
            return true;
        else
            return false;
	}
Example #2
0
void book_author_search()
{
	cout << "Enter the book's author:" << endl;
	string name;
	cin.clear();
	cin.ignore(numeric_limits<streamsize>::max(), '\n');
	getline(cin, name);
	Category *tmp1 = beginning;
	Book *tmp;
	vector <Book *> list;

	system("CLS");
	cout << "Searching..." << endl;

	int i = 0;

	while (tmp1 != NULL)
	{
		tmp = tmp1->getHead();

		while (tmp != NULL)
		{
			if (iequals(tmp->getAuthor(), name))
			{
				list.push_back(tmp);
				i++;
				cout << "Result no." << i << endl;
				tmp->print();
			}
			tmp = tmp->getNext();
		}
		tmp1 = tmp1->getNext();
	}

	if (i == 0)
	{
		system("CLS");
		cout << "No such ID was found." << endl;
		cout << "Please try again" << endl;
	}

	else
	{
		cout << "Which of the results do you want to manage? (enter a number)" << endl;

		stahp();
		int ch;
		cin >> ch;
		ch--;
		if (ch > 49 || list[ch] == NULL)
		{
			cout << "Invalid response. Please start again." << endl;
		}

		else
			book_menu(list[ch]);
	}
}
Example #3
0
void printFirstNode(List theList)
{
	Node* t = theList.getFirst();
	Book* bp = t->getBook();
	cout << bp->getTitle() << ' ';
	cout << bp->getAuthor() << ' ';
	cout << "$" << bp->getPrice() << endl;
	t = t->getNextNode();
}
Example #4
0
void Utils::displayBookInformation(Book book) {
	cout << "\tISBN            \t" << book.getIsbn() << endl;
	cout << "\tTitle           \t" << book.getTitle() << endl;
	cout << "\tAuthor          \t" << book.getAuthor() << endl;
	cout << "\tPublisher       \t" << book.getPublisher() << endl;
	cout << "\tDate Added      \t" << toString(book.getDateAdded()) << endl;
	cout << "\tQuantity-On-Hand\t" << book.getQuantityOnHand() << endl;
	cout << "\tWholesale Cost  \t" << setprecision(2) << book.getWholesaleCost() << endl;
	cout << "\tRetail Price    \t" << setprecision(2) << book.getRetailPrice() << endl << endl;
}
Book*    StoreSection::searchBookByAuthor(const QString& author){
    Book *book = 0;

    QHashIterator<QString, icXmlSerializable*> i(m_books);
    while (i.hasNext()) {
        i.next();
        book = (Book *)i.value();
        if (book->getAuthor() == author)
            return book;
    }

    return book;
}
Example #6
0
void Library::printAverageBookRatings() {
  //Create array to first hold the sums of ratings for each book, 
  // then calculate the average: avg = sum/divisor.
  int indBooks = bookList.size();
  int indUsers = userList.size();  
  double sum[indBooks], divisor[indBooks];  
  for (int i = 0; i < indBooks; i++) {
    sum[i] = 0.0;
    divisor[i] = 0.0;    
  }

  //Set average decimal precision. 
  cout << fixed << setprecision(2);
  cout << showpoint;

  //Loop thru the peoples' ratings, and accumulate score to sum[] array. 
  for (int i = 0; i < indUsers; i++) {
    User userSelection = userList.at(i);

    int indBook = 0;
    while (indBook < indBooks) {
      float ratingSelection = userSelection.getRatingAt(indBook);      
      //Accumulate ratings within sum array. 
      sum[indBook] = sum[indBook] + ratingSelection;
      if (ratingSelection != 0.0) {
        divisor[indBook]++; //Increment count of ratings if non-zero. 
      }
      indBook++;
    }
  }

  //Loop thru the books for the ratings. 
  float avg; 
  for (int i = 0; i < indBooks; i++) {
    if (divisor[i] == 0) {
      avg = 0;
    }
    else {
      avg = sum[i]/divisor[i];
    }
    Book bookSelection = bookList.at(i);
    string titleSelection = bookSelection.getTitle();      
    string authorSelection = bookSelection.getAuthor();      

    cout << avg << " " << titleSelection << " by " << authorSelection << endl;
  }
  cout << endl;
  
}
Example #7
0
void printList(const List& theList)
{
	if (theList.getFirst() == NULL) // if the list is empty
		cout << "\nempty list\n";

	Node* t = theList.getFirst();
	while (t != NULL)
	{
		Book* bp = t->getBook();
		cout << bp->getTitle() << ' ';
		cout << bp->getAuthor() << ' ';
		cout << "$" << bp->getPrice() << endl;
		t = t->getNextNode();
	}
}
void    Dialog::fillSection(StoreSection *section, QTreeWidgetItem *parentItem) {
    int index;
    Book *book;

    QList<Book*> list = section->getBooks();
    for (index=0; index < list.size(); index++) {
        book = list.at(index);

        QTreeWidgetItem *item = new QTreeWidgetItem(parentItem);
        item->setText(0, book->getTitle());
        item->setText(1, book->getAuthor());
        item->setText(2, QString::number(book->getPrice()));
        item->setText(3, QString::number(book->getStock()));
        parentItem->addChild(item);
    }
}
Example #9
0
/*
Converts a Book object to string representation

Example:
1
ISBN:               0399257748
Title:				The Martian
Author:				Andy Weir
Publisher:			Scribner
Date Added:			2015-1-16 23:56:11
Quantity:			1
*/
string Utils::toString(int itemNumber, int quantity, Book book) {
	string bookString = "";
	bookString += to_string(itemNumber) + "\n";
	bookString += "\t ISBN:              " + book.getIsbn() + "\n";
	bookString += "\t Title:             " + book.getTitle() + "\n";
	bookString += "\t Author:            " + book.getAuthor() + "\n";
	bookString += "\t Publisher:         " + book.getPublisher() + "\n";
	bookString += "\t Date Added:        " + toString(book.getDateAdded()) + "\n";
	bookString += "\t Quantity:          " + to_string(quantity) + "\n";

	ostringstream stream;
	stream << fixed << setprecision(2) << book.getRetailPrice();
	bookString += "\t Retail Price:      " + stream.str() + "\n";

	return bookString;
}
Example #10
0
//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;
            }
        }
    }
}
/*
	Display available options after a desired book's information is presented and corresponding transitions 
	when user choose one option.
*/
void InventoryModule::displayOptionsAfterLookUp(int thingToShow, Book bookObtained) {
	cout << "\t\t 1. Look Up Another Book" << endl;
	cout << "\t\t 2. Back To Look Up Menu" << endl;
	cout << "\t\t 3. Add This Book To Cart"<< endl << endl;

	switch (Utils::showChoices(1, 3)) {
	case 1:

		switch (thingToShow) {
		case SHOW_ISBN:
			showBooksByISBN();
			break;
		case SHOW_TITLE:
			showBooksByTitle();
			break;
		case SHOW_AUTHOR:
			showBooksByAuthor();
			break;
		case SHOW_PUBLISHER:
			showBooksByPublisher();
			break;
		case SHOW_DATE:
			showBooksByDate();
			break;
		case SHOW_QUANTITY:
			showBooksByQuantity();
			break;
		case SHOW_WHOLESALE:
			showBooksByWholesale();
			break;
		case SHOW_RETAIL_PRICE:
			showBooksByRetailPrice();
			break;
		}

		break;
	case 2:
		displayLookUpMenu();
		break;
	case 3:
		int howMany = 0;
		do {
			howMany = Utils::readInt("How Many Books Do You Want?\t");
			if (howMany < 0)
				cout << "Number Of Books Has To Be An Integer Greater Than 0. Please Enter Again" << endl << endl;
			if (howMany > bookObtained.getQuantityOnHand())
				cout << "We Only Have " << bookObtained.getQuantityOnHand() << " In Stock. Please Enter Again" << endl << endl;
		} while (howMany < 0 || howMany > bookObtained.getQuantityOnHand());

		int position = getBookPositionInCart(bookObtained);
		if (position == -1) {
			CashierModule::quantities[CashierModule::numberItems] += howMany;
			CashierModule::booksInCart[CashierModule::numberItems++] = bookObtained;

		}
		else CashierModule::quantities[position] += howMany;

		BookDAO::getInstance()->update(
								bookObtained.getIsbn(),
								bookObtained.getTitle(),
								bookObtained.getAuthor(),
								bookObtained.getPublisher(),
								bookObtained.getQuantityOnHand() - howMany,
								bookObtained.getWholesaleCost(),
								bookObtained.getRetailPrice());
	}
}
Example #12
0
bool Mediator::indexingListOnIndex(IndexWrapper::indexItem item)
{
	bool done = false;
	List<int>* flagsLs = this->dataBookManager->getListToFileFlag(item);
	if(!flagsLs->isEmpty())
	{
		cout << "Process Started: " << Utility::getDate() << endl;
		ListIterator<int> it = flagsLs->getIterator();
		int ID;
		while(it.hasNext())
		{
			ID = it.next();
			ByteString bs = this->dataBookManager->getBook(ID);
			Book book;
			book.Hidratate(bs);

			string clave;
			Record* record;
			ByteString bsIdBook;
			ByteString* bsId;
			bsIdBook.insertLast(&ID,sizeof(int));
			Key* key;
			switch(item){
			case IndexWrapper::AUTOR :
										clave = book.getAuthor();
										cout << "Book begin process: " << book.getTitle() << " - Author:" << clave << " - Start:" << Utility::getDate();

										key = new Key(clave);
										bsId = new ByteString(bsIdBook);
										record = new Record(key,bsId);
										done = this->indexWrapper->add(record,item);
										break;
			case IndexWrapper::EDITORIAL :
										clave = book.getEditorial();
										cout << "Book begin process: " << book.getTitle() << " - Editorial:" << clave << " - Start:" << Utility::getDate();

										key = new Key(clave);
										bsId = new ByteString(bsIdBook);
										record = new Record(key,bsId);
										done = this->indexWrapper->add(record,item);
										break;
			case IndexWrapper::TITULO :
										clave = book.getTitle();
										cout << "Book begin process: " << book.getTitle() << " - Start:" << Utility::getDate();

										key = new Key(clave);
										bsId = new ByteString(bsIdBook);
										record = new Record(key,bsId);
										done = this->indexWrapper->add(record,item);
										break;
			case IndexWrapper::PALABRAS :
										this->fileParser->setWords(book.getText());

										// ----------------------------------------------------------------------------------------------- //
										// Se incorpora la norma infinito del documento
										// ----------------------------------------------------------------------------------------------- //
										Key* keyIdBook = new Key(bsIdBook.toString());

										ByteString* bsInfinityNorm = new ByteString();
										unsigned int infinityNorm = this->fileParser->getInfinityNorm();
										bsInfinityNorm->insertLast(&infinityNorm, sizeof(unsigned int));

										Record* recInfinityNorm = new Record(keyIdBook, bsInfinityNorm);
										this->infinityNormIndex->add(recInfinityNorm);
										delete recInfinityNorm;
										// ----------------------------------------------------------------------------------------------- //

										map<string,Term*> terms = this->fileParser->getTerms();
										cout << "Book begin process: " << book.getTitle() << " - Words Count:" << Utility::intToString(terms.size()) << " - Start:" << Utility::getDate();
										int i = 0;
										for(map<string,Term*>::iterator it = terms.begin(); it != terms.end(); ++it)
										{
											i++;
											// ------------------------ //
											key = new Key(it->first);
											string word = it->first;
											list<int>* listDocuments = this->indexWrapper->searchAllIds(key, IndexWrapper::PALABRAS);
											int idTerm;

											// Si no tiene datos --> la palabra no existe en el hash
											if (listDocuments->size() == 0)
											{
												//delete poddo
												delete listDocuments;

												// Se agrega la palabra al vocabulario y se obtiene su id
												int possibleID = this->autoIncInteger + 1;

												// La clave es el id de termino y el dato la palabra
												ByteString bsIdTerm;
												bsIdTerm.insertLast(&possibleID, sizeof(int));
												Key* keyIdTerm = new Key(bsIdTerm.toString());

												ByteString* bsTerm = new ByteString();
												bsTerm->insertLast(word);

												Record* recVocabulary = new Record(keyIdTerm, bsTerm);
												this->vocabularyIndex->add(recVocabulary);
												delete recVocabulary;

												idTerm = possibleID;
												this->autoIncInteger++;
											}
											else
											{
												// Devuelve en la ultima posicion el id del termino y en las restantes los id de documentos
												Word* newWord = new Word(word, listDocuments);
												idTerm = newWord->getIdWord();
												delete newWord; // se elimina la lisdDocuments tambien
											}

											//Aca se agrega las ocurrencias del termino en el libro
											list<unsigned int> listOfPositions = it->second->getPositions();

											ByteString bs;
											bs.insertLast(&ID,sizeof(int));
											bs.insertLast(&idTerm,sizeof(int));
											Record* r = new Record();
											r->setKey(new Key(bs.toString()));

											this->ocurrenceTree->addList(r,listOfPositions);

											listOfPositions.clear();
											delete r;

											// ------------------------ //
											bsId = new ByteString(bsIdBook);
											bsId->insertLast(&idTerm, sizeof(int));
											record = new Record(key,bsId);

											done = this->indexWrapper->add(record,item);
											delete record;
										}

										break;
			}
			cout << "Book processed: " << book.getTitle() << " - Finish:" << Utility::getDate() << endl;
		}
		cout << "Process Ended: " << Utility::getDate();
	}

	//delete poddo
	if (flagsLs != NULL)
		delete flagsLs;

	return done;
}
Example #13
0
//See comment for function above. This function is essentially identical, simply takes a title instead of ISBN.
void Library::SellBookbyTitle(Book *tmp, string aTitle) {
    
    //If there are no Books
    if (root == NULL) {
        cout << "There are no books in the library." << endl;
    }
    
    //If there is only one Book
    else if (tmp->getLeft() == 0 && tmp->getRight() == 0) {
        cout << "Only one book in the library." << endl;
        cout << "$" << tmp->getPrice() << " " << tmp->getTitle() << " by " << tmp->getAuthor() << endl;
    }
    
    else {
        Book *stack[200];
        int L = 0;
        Book *current = tmp;
        bool done = false;
        
        while (done == false) {
            
            if (current != NULL) {
                stack[L] = current;
                L++;
                current = current->getLeft(current);
            }
            
            else {
                if (L != 0 && current == NULL) {
                    L--;
                    current = stack[L];
                    if (current->getTitle() == aTitle) {
                        if (current->getQuantity() == 1) {
                            Book* parent = stack[L-1];
                            cout << "Oh, looks like you are selling the last one. Removing from tree" << endl;
                            if (current->getLeft() == NULL && current->getRight() == NULL) {
                                if (current->getPrice() > parent->getPrice()) {
                                    parent->setRight(NULL);
                                }
                                else {
                                    parent->setLeft(NULL);
                                }
                            }
                            else if (current->getLeft() != NULL && current->getRight() == NULL) {
                                if (current->getPrice() > parent->getPrice()) {
                                    parent->setRight(current->getLeft());
                                }
                                else {
                                    parent->setLeft(current->getRight());
                                }
                            }
                            else if (current->getLeft() == NULL && current->getRight() != NULL) {
                                if (current->getPrice() > parent->getPrice()) {
                                    parent->setRight(current->getRight());
                                }
                                else {
                                    parent->setLeft(current->getLeft());
                                }
                            }
                            else if (current->getLeft() != NULL && current->getRight() != NULL) {
                                Book* prev = predecessor(current->getPrice(), current);
                                if (prev == NULL) {
                                    prev = successor(current->getPrice(), current);
                                }
                                if (prev->getPrice() > prev->getParent()->getPrice()) {
                                    prev->getParent()->setRight(prev->getRight());
                                }
                                else if (prev->getPrice() <= prev->getParent()->getPrice()) {
                                    prev->getParent()->setLeft(prev->getRight());
                                }
                                current->setPrice(prev->getPrice());
                                delete prev;
                            }
                        }
                        else {
                            int new_quant = current->getQuantity()-1;
                            current->setQuantity(new_quant);
                            cout << "$" << current->getPrice() << " " << current->getTitle() << " by " << current->getAuthor() << endl;
                            cout << "New quantity: " << current->getQuantity() << endl;
                        }
                    }
                    current = current->getRight(current);
                }
                else {
                    done = true;
                }
                
            }
        }
    }
    
    
}
Example #14
0
//This function is much the the one above.
//It is non-recursive to traverse the tree of books creating a stack.
//As it comes back, it removes books from the stack in order of the sorted parameter (price) and outputs to the user.
//This produces a sorted output by price but cuts off at the max price the user is willing to pay.
void Library::printBargainBooks(Book *tmp, double aPrice) {
    
    cout << "SORTED BY PRICE LOW TO HIGH" << endl;
    //If there are no Books
    if (root == NULL) {
        cout << "There are no books in the library." << endl;
    }
    
    //If there is only one Book
    else if (tmp->getLeft() == 0 && tmp->getRight() == 0) {
        cout << "$" << tmp->getPrice() << " " << tmp->getTitle() << " by " << tmp->getAuthor() << endl;
    }
    
    else {
        Book *stack[200];
        int L = 0;
        Book *current = tmp;
        bool done = false;
        
        while (done == false) {
            
            if (current != NULL) {
                stack[L] = current;
                L++;
                current = current->getLeft(current);
            }
            
            else {
                if (L != 0 && current == NULL) {
                    L--;
                    current = stack[L];
                    if (current->getPrice() <= aPrice) {
                    cout << "$" << current->getPrice() << " " << current->getTitle() << " by " << current->getAuthor() << endl;
                    }
                    current = current->getRight(current);
                }
                else {
                    done = true;
                }
                
            }
        }
    }
    
    
}
int Book::compareAuthor(Book _book) {
	return this->author.compareTo(_book.getAuthor());
}
Example #16
0
void Library::showBooks() const
{
	IdentNum i;
	if (books.size()==0)
		cout << "Nao existem livros registados.\n";
	else
	{
		cout << "#### Livros ####\n";
		cout << "---------------------------------------------------------------------------- \n";
		cout << "| ID   | Titulo                        | Autor                    | Disp.  |\n";
		cout << "---------------------------------------------------------------------------- \n";
		cout << setiosflags(ios::left);
		for (i=1;i<=books.size();i++)
		{
			Book bookTemp = getBookByID(i);
			cout << "| " << setw(MAXIDLENGTH) << bookTemp.getID() << "| " << setw(MAXTITLELENGTH) << bookTemp.getTitle() << "| " << setw(MAXAUTHORLENGTH) << bookTemp.getAuthor() << "| " << setw(MAXQUANTITYLENGTH) << bookTemp.getNumAvailable() << "|\n";
		}
		cout << resetiosflags(ios::left);
		cout << "---------------------------------------------------------------------------- \n";
	}
}