Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BookCollection.h"
- #include "bookdata.h"
- //#include "bookinfo.h"
- #include <iostream>
- #include <string>
- #include <cctype>
- int BookCollection::findBook(string isbntitle)
- {
- int index=0;
- string x, y;
- for (index=0; index < 20; index++)
- {
- x = book[index].getTitle();
- y = book[index].getIsbn();
- if (isbntitle == x || isbntitle == y)
- return index;
- else
- return -1;
- }
- }
- void BookCollection::addBook()
- {
- bool empt;
- for (int i=0; i < MAX_BOOKS; i++)
- {
- empt = book[i].isEmpty();
- if (empt)
- {
- book[i].isEmpty(false);
- cout << "Book Title: ";
- string title;
- cin.ignore();
- getline(cin, title);
- book[i].setTitle(title);
- cout << "ISBN: ";
- string isbn;
- cin >> isbn;
- book[i].setIsbn(isbn);
- cout << "Author's Name: ";
- string author;
- cin.ignore();
- getline(cin, author);
- book[i].setAuthor(author);
- cout << "Publisher's Name: ";
- string publisher;
- cin.ignore();
- getline(cin, publisher);
- book[i].setPub(publisher);
- cout << "Date book was added to inventory: ";
- string date;
- cin >> date;
- book[i].setDateAdded(date);
- cout << "Quantity being added: ";
- int qty;
- cin >> qty;
- book[i].setQty(qty);
- cout << "Wholesale price: ";
- double wholesale;
- cin >> wholesale;
- book[i].setWholesale(wholesale);
- cout << "Retail price: ";
- double retail;
- cin >> retail;
- book[i].setRetail(retail);
- break;
- }
- else
- {
- cout << "There are no empty places!\n";
- }
- }
- }
- void BookCollection::deleteBook()
- {
- char verify;
- int checker;
- string inputinfo;
- cout << "\nEnter book title or ISBN: ";
- cin.ignore();
- getline(cin, inputinfo);
- checker = findBook(inputinfo);
- if (checker == -1)
- {
- cout << "Book was not in the inventory" << endl;
- }
- else
- {
- book[checker].bookInfo();
- }
- cout << "Is this the book you want to delete? [Y/N]: ";
- cin >> verify;
- if (verify == 'N')
- {
- cout << "You have chosen not to delete" << endl;
- }
- else if (verify == 'Y')
- {
- book[checker].removeBook(true);
- }
- }
- void BookCollection::editBook()
- {
- string author, isbn, title, publisher, dateAdded, userInput;
- double wholesale, retail;
- int qty, location;
- cout << "\nEnter book title or ISBN: ";
- cin.ignore();
- getline(cin, userInput);
- location = findBook(userInput);
- isbn = book[location].getIsbn();
- title = book[location].getTitle();
- author = book[location].getAuthor();
- publisher = book[location].getPub();
- dateAdded = book[location].getDateAdded();
- qty = book[location].getQty();
- wholesale = book[location].getWholesale();
- retail = book[location].getRetail();
- if (location == -1)
- cout << "\nBook not in the system!" << endl;
- else
- {
- int choice;
- do
- {
- cout << "1) ISBN: " << isbn << endl;
- cout << "2) Title: " << title << endl;
- cout << "3) Author: " << author << endl;
- cout << "4) Publisher: " << publisher << endl;
- cout << "5) Date Added: " << dateAdded << endl;
- cout << "6) Quantity-on-Hand: " << qty << endl;
- cout << "7) Wholesale Cost: " << wholesale << endl;
- cout << "8) Retail Price: " << retail << endl;
- cout << "9) Go back." << endl;
- cout << "\tWhich field would you like to edit?: ";
- cin >> choice;
- if (choice == 1)
- {
- string newIsbn;
- cout << "\nEnter ISBN: ";
- cin.ignore();
- getline(cin, newIsbn);
- book[location].setIsbn(newIsbn);
- isbn = book[location].getIsbn();
- }
- if (choice == 2)
- {
- string newTitle;
- cout << "\nEnter Title: ";
- cin.ignore();
- getline(cin, newTitle);
- book[location].setTitle(newTitle);
- title = book[location].getTitle();
- }
- if (choice == 3)
- {
- string newAuthor;
- cout << "\nEnter Author: ";
- cin.ignore();
- getline(cin, newAuthor);
- book[location].setAuthor(newAuthor);
- author = book[location].getAuthor();
- }
- if (choice == 4)
- {
- string newPub;
- cout << "\nEnter Publisher: ";
- cin.ignore();
- getline(cin, newPub);
- book[location].setPub(newPub);
- publisher = book[location].getPub();
- }
- if (choice == 5)
- {
- string newDate;
- cout << "\nEnter date added: ";
- cin.ignore();
- getline(cin, newDate);
- book[location].setDateAdded(newDate);
- dateAdded = book[location].getDateAdded();
- }
- if (choice == 6)
- {
- int newQty;
- cout << "\nEnter quantity on-hand: ";
- cin >> newQty;
- book[location].setQty(newQty);
- qty = book[location].getQty();
- }
- if (choice == 7)
- {
- double newWholesale;
- cout << "\nEnter wholesale price: ";
- cin >> newWholesale;
- book[location].setWholesale(newWholesale);
- wholesale = book[location].getWholesale();
- }
- if (choice == 8)
- {
- double newRetail;
- cout << "\nEnter retail price: ";
- cin >> newRetail;
- book[location].setRetail(newRetail);
- retail = book[location].getRetail();
- }
- }
- while (choice != 9);
- }
- }
- void BookCollection::lookUpBook()
- {
- string userInput;
- int location;
- cout << "\nEnter book title or ISBN: ";
- cin.ignore();
- getline(cin, userInput);
- location = findBook(userInput);
- if (location == -1)
- cout << "\nBook not in the system!" << endl;
- else
- {
- book[location].bookInfo();
- }
- }
- int BookCollection::lookupIsbn(string isbn)
- {
- int location;
- location = findBook(isbn);
- if (location == -1)
- cout << "\nBook not in the system!" << endl;
- else
- {
- book[location].bookInfo();
- }
- }
- bool BookCollection::booksAvailable()
- {
- int i = 0, bAvail = 0;
- bool check;
- while(i < MAX_BOOKS)
- {
- check = book[i].isEmpty();
- if(check)
- {
- i++;
- }
- else
- {
- bAvail++;
- i++;
- }
- }
- if(bAvail == 0)
- {
- cout << "There are no books available" << endl;
- return false;
- }
- else
- {
- return true;
- }
- }
- void BookCollection::repListing()
- {
- char cont;
- cout << "\nInventory Listing" << endl;
- int count = 0;
- cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Author\t" << "Publisher\t" << "Date Added " << "Quantity "
- << " Wholesale " << " Retail " << endl;
- while(count < MAX_BOOKS)
- {
- cout << book[count].getTitle() << book[count].getIsbn() << book[count].getAuthor()
- << book[count].getPub() << book[count].getDateAdded() << book[count].getQty()
- << book[count].getWholesale() << book[count].getRetail() << endl;
- count++;
- }
- cout << "Press enter to continue" << endl;
- cin >> cont;
- return;
- }
- void BookCollection::repWholesale()
- {
- char cont;
- cout << "\nInventory Wholesale Value" << endl;
- int count = 0;
- double total = 0;
- cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Wholesale\t" << endl;
- while(count < MAX_BOOKS)
- {
- cout << book[count].getTitle() << book[count].getIsbn() << book[count].getQty()
- << book[count].getWholesale() << endl;
- total = total + (book[count].getQty() * book[count].getWholesale());
- count++;
- }
- cout << "The Total Wholesale Value of the Inventory is $" << total << endl;
- cout << "Press enter to continue" << endl;
- cin >> cont;
- return;
- }
- void BookCollection::repRetail()
- {
- char cont;
- cout << "\nInventory Retail Value" << endl;
- int count = 0;
- double total = 0;
- cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Retail\t" << endl;
- while(count < MAX_BOOKS)
- {
- cout << book[count].getTitle() << book[count].getIsbn() << book[count].getQty()
- << book[count].getRetail() << endl;
- total = total + (book[count].getQty() * book[count].getRetail());
- count++;
- }
- cout << "The Total Retail Value of the Inventory is $" << total << endl;
- cout << "Press enter to continue" << endl;
- cin >> cont;
- return;
- }
- void BookCollection::repQty()
- {
- int i, x, y;
- BookData temp;
- bool swap = true;
- char cont;
- cout << "\nListing by Quantity." << endl;
- while(swap)
- {
- swap = false;
- for(i = 0; i < MAX_BOOKS -1; i++)
- {
- x = book[i].getQty();
- y = book[i + 1].getQty();
- if(x < y)
- {
- temp = book[i];
- book[i] = book[i + 1];
- book[i + 1] = temp;
- swap = true;
- }
- }
- }
- i = 0;
- cout << "Title\t" << "ISBN\t" << "Quantity" << endl;
- while(i < MAX_BOOKS)
- {
- cout << book[i].getTitle() << "\t" << book[i].getIsbn() << "\t" << book[i].getQty() << endl;
- }
- cout << "Press enter to continue" << endl;
- cin >> cont;
- return;
- }
- void BookCollection::repCost()
- {
- cout << "\nListing by Cost." << endl;
- int i;
- double x, y;
- char cont;
- BookData temp;
- bool swap = true;
- while(swap)
- {
- swap = false;
- for(i = 0; i < MAX_BOOKS -1; i++)
- {
- x = book[i].getWholesale();
- y = book[i+1].getWholesale();
- if(x < y)
- {
- temp = book[i];
- book[i] = book[i + 1];
- book[i + 1] = temp;
- swap = true;
- }
- }
- }
- i = 0;
- cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Wholesale" << endl;
- while(i < MAX_BOOKS)
- {
- cout << book[i].getTitle() << "\t" << book[i].getIsbn() << "\t" << book[i].getQty() << "\t" << book[i].getWholesale() << endl;
- }
- cout << "Press enter to continue" << endl;
- cin >> cont;
- return;
- }
- void BookCollection::repAge()
- {
- cout << "\nListing by Age." << endl;
- int i;
- char cont;
- string x, y;
- BookData temp;
- bool swap = true;
- while(swap)
- {
- swap = false;
- for(i = 0; i < MAX_BOOKS -1; i++)
- {
- x = book[i].getDateAdded();
- y = book[i].getDateAdded();
- if(x < y)
- {
- temp = book[i];
- book[i] = book[i + 1];
- book[i + 1] = temp;
- swap = true;
- }
- }
- }
- i = 0;
- cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Date Added" << endl;
- while(i < MAX_BOOKS)
- {
- cout << book[i].getTitle() << "\t" << book[i].getIsbn() << "\t" << book[i].getQty() << "\t" << book[i].getDateAdded() << endl;
- }
- cout << "Press enter to continue" << endl;
- cin >> cont;
- return;
- }
- /*
- void match(string title, BookData b[])
- {
- for(int i=0; i < title.length(); i++)
- {
- title[i] = toupper(title[i]);
- }
- }
- */
Add Comment
Please, Sign In to add comment