Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "serendipity.h"
- //--------------------------------------------------------//
- // File Name: inventoryDatabaseModule.cpp
- // Project name: Serendipity Ch 9-11
- //--------------------------------------------------------
- // Creators name and email: Kevin Nguyen, oggunderscore@gmail.com
- // Creation Date: 9/14/19
- // Date of Last Modification: 9/14/19
- //--------------------------------------------------------//
- // Purpose: This class displays the inventoryDatabaseModule.
- //--------------------------------------------------------//
- // Algorithm:
- // Prompt user for an input then execute module functions.
- //--------------------------------------------------------//
- // Data Dictionary
- // Constants
- //
- // Name Data Type Initial Value
- // ---------- -------------- ------------------//
- // N/A
- //
- // Variables
- //
- // Name Data Type Initial Value
- // ---------- -------------- ------------------//
- // selection int null
- // validInput boolean null
- // book array of structs null
- // tbook struct null
- //--------------------------------------------------------//
- /*
- string book.title[DBSIZE], book.isbn[DBSIZE], book.author[DBSIZE], book.publisher[DBSIZE], book.dateAdded[DBSIZE];
- int book.qtyOnHand[DBSIZE], bookCount;
- double book.wholesale[DBSIZE], book.retail[DBSIZE];
- string tBook.title, tBook.isbn, tBook.author, tBook.publisher, tBook.dateAdded;
- int tBook.qtyOnHand;
- double tBook.wholesale, tBook.retail;
- */
- int bookCount;
- bookType book[20];
- bookType tBook;
- //Setters
- void setTitle(bookType book[], string str, int x) {
- book[x].title = str;
- }
- void setISBN(bookType book[], string str, int x) {
- book[x].isbn = str;
- }
- void setAuthor(bookType book[], string str, int x) {
- book[x].author = str;
- }
- void setPub(bookType book[], string str, int x) {
- book[x].publisher = str;
- }
- void setDateAdded(bookType book[], string str, int x) {
- book[x].dateAdded = str;
- }
- void setQty(bookType book[], int amount, int x) {
- book[x].qtyOnHand = amount;
- }
- void setWholesale(bookType book[], double y, int x) {
- book[x].wholesale = y;
- }
- void setRetail(bookType book[], double y, int x) {
- book[x].retail = y;
- }
- int isEmpty(bookType book[], int x) {
- }
- void resetTemps() {
- tBook.title = "EMPTY";
- tBook.isbn = "EMPTY";
- tBook.author = "EMPTY";
- tBook.publisher = "EMPTY";
- tBook.dateAdded = getDate() + " (Auto)";
- tBook.qtyOnHand = 0;
- tBook.wholesale = 0.00;
- tBook.retail = 0.00;
- }
- void bookInfo(int bookID) {
- cout << "\n\t\t\t\t\tSerendipity Booksellers\n\t\t\t\t\tBook Information\n" << endl;
- cout << "Title: " << book[bookID].title << endl;
- cout << "ISBN: " << book[bookID].isbn << endl;
- cout << "Author: " << book[bookID].author << endl;
- cout << "Publisher: " << book[bookID].publisher << endl;
- cout << "Date Added: " << book[bookID].dateAdded << endl;
- cout << "Quantity-On-Hand: " << book[bookID].qtyOnHand << endl;
- cout << "Wholesale Cost: " << book[bookID].wholesale << endl;
- cout << "Retail Cost: " << book[bookID].retail << endl;
- pause();
- clear();
- inventoryDatabaseModule();
- }
- size_t findCaseInsensitive(string data, string toSearch, size_t pos) {
- // Convert complete given String to lower case
- transform(data.begin(), data.end(), data.begin(), ::tolower);
- // Convert complete given Sub String to lower case
- transform(toSearch.begin(), toSearch.end(), toSearch.begin(), ::tolower);
- // Find sub string in given string
- return data.find(toSearch, pos);
- }
- void lookUpBook() {
- clear();
- cout << "\t\tSerendipity Booksellers\n\t\tInventory Database\n\n\t\t1. Look up a Book\n\t\t2. Add a Book\n\t\t3. Edit a Book's Record\n\t\t4. Delete a Book\n\t\t5. Return to Main Menu\n\n\t\tPlease type in your input: 1\n";
- string search;
- cout << "\nSearch: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, search);
- bool validInput;
- char selection;
- for (int x = 0; x < DBSIZE; x++) {
- size_t found = findCaseInsensitive(book[x].title, search, 0);
- if (found != string::npos) {
- do {
- if (validInput != true) {
- cout << "\"" << book[x].title << "\" found by Title. Would you like to view it? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- bookInfo(x);
- case 'N':
- case 'n':
- validInput = true;
- inventoryDatabaseModule();
- //found = findCaseInsensitive(book[x].title, search, found+1);
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (found != string::npos);
- } else {
- do {
- if (validInput != true) {
- found = book[x].isbn.find(search);
- if (found != string::npos) {
- do {
- if (validInput != true) {
- cout << "\"" << book[x].isbn << "\" found by ISBN. Would you like to view it? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- bookInfo(x);
- case 'N':
- case 'n':
- validInput = true;
- inventoryDatabaseModule();
- //found = findCaseInsensitive(book[x].title, search, found+1);
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (found!= string::npos);
- } else {
- if (x == 19) {
- do {
- if (validInput != true) {
- cout << "Error: Could not find Title / ISBN. Try again? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- lookUpBook();
- case 'N':
- case 'n':
- validInput = true;
- inventoryDatabaseModule();
- //found = findCaseInsensitive(book[x].title, search, found+1);
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (found != string::npos);
- }
- }
- } else {
- break;
- }
- } while (found != string::npos);
- }
- }
- inventoryDatabaseModule();
- }
- void editor(int x);
- void addBook() {
- clear();
- if (bookCount >= DBSIZE) {
- cout << "Database is full! Please delete some books to proceed! (" << bookCount << "/" << DBSIZE << ")\n";
- pause();
- clear();
- inventoryDatabaseModule();
- } else {
- bool validInput;
- char selection;
- do {
- cout << fixed;
- cout.precision(2);
- cout << "*************************************************************\n\t\tSerendipity Booksellers\n\t\t\tAdd Book Menu\n\n\tCurrent Database Size: " << bookCount << "/" << DBSIZE << "\n" << endl;
- cout << "\t\t\t\t\t+ Pending Values +" << endl;
- cout << "(1) Enter Book Title\t\t\t > --" << tBook.title << endl;
- cout << "(2) Enter ISBN\t\t\t\t > --" << tBook.isbn << endl;
- cout << "(3) Enter Author\t\t\t > --" << tBook.author << endl;
- cout << "(4) Enter Publisher\t\t\t > --" << tBook.publisher << endl;
- cout << "(5) Enter Date Added\t\t\t > --" << tBook.dateAdded << endl;
- cout << "(6) Enter Quantity on Hand\t\t > --" << tBook.qtyOnHand << endl;
- cout << "(7) Enter Wholesale Cost\t\t > --$" << tBook.wholesale << endl;
- cout << "(8) Enter Retail Price\t\t\t > --$" << tBook.retail << endl;
- cout << "(9) Save Book to Database\t" << endl;
- cout << "(0) Return to Inventory Menu" << endl;
- cout << "\n*************************************************************\n\tChoice (0-9): ";
- cin >> selection;
- validInput = true;
- switch(selection) {
- case '1':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Book Title: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.title);
- addBook();
- break;
- case '2':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput ISBN: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.isbn);
- addBook();
- break;
- case '3':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Author: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.author);
- addBook();
- break;
- case '4':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Publisher: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.publisher);
- addBook();
- break;
- case '5':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Date: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.dateAdded);
- addBook();
- break;
- case '6':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Quantity on Hand: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- cin >> tBook.qtyOnHand;
- addBook();
- break;
- case '7':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Wholesale Cost: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- cin >> tBook.wholesale;
- addBook();
- break;
- case '8':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Retail Price: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- cin >> tBook.retail;
- addBook();
- break;
- case '9':
- validInput = true;
- clear();
- //SAVING CODE
- setTitle(book, tBook.title, bookCount);
- setISBN(book, tBook.isbn, bookCount);
- setAuthor(book, tBook.author, bookCount);
- setPub(book, tBook.publisher, bookCount);
- setDateAdded(book, tBook.dateAdded, bookCount);
- setQty(book, tBook.qtyOnHand, bookCount);
- setWholesale(book, tBook.wholesale, bookCount);
- setRetail(book, tBook.retail, bookCount);
- bookCount++;
- cout << "Save was successful. Database: (" << bookCount << "/" << DBSIZE << ")";
- cout << endl;
- resetTemps();
- clear();
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- addBook();
- break;
- case '0':
- validInput = true;
- clear();
- resetTemps();
- inventoryDatabaseModule();
- break;
- default:
- validInput = false;
- clear();
- cout << "\nPlease enter a valid selection!\n";
- break;
- }
- } while (validInput == false);
- }
- clear();
- }
- void editBook() {
- clear();
- cout << "\t\tSerendipity Booksellers\n\t\tInventory Database\n\n\t\t1. Look up a Book\n\t\t2. Add a Book\n\t\t3. Edit a Book's Record\n\t\t4. Delete a Book\n\t\t5. Return to Main Menu\n\n\t\tPlease type in your input: 3\n";
- string search;
- cout << "\nSearch: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, search);
- cout << "\n";
- bool validInput;
- char selection;
- for (int x = 0; x < DBSIZE; x++) {
- size_t found = book[x].title.find(search);
- if (found != string::npos) {
- do {
- if (validInput != true) {
- cout << "\"" << book[x].title << "\" found by Title. Would you like to edit it? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- tBook.title = book[x].title;
- tBook.isbn = book[x].isbn;
- tBook.author = book[x].author;
- tBook.publisher = book[x].publisher;
- tBook.dateAdded = book[x].dateAdded;
- tBook.qtyOnHand = book[x].qtyOnHand;
- tBook.wholesale = book[x].wholesale;
- tBook.retail = book[x].retail;
- editor(x);
- case 'N':
- case 'n':
- validInput = true;
- clear();
- inventoryDatabaseModule();
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (validInput != true);
- } else {
- do {
- if (validInput != true) {
- found = book[x].isbn.find(search);
- if (found != string::npos) {
- do {
- if (validInput != true) {
- cout << "\"" << book[x].isbn << "\" found by ISBN. Would you like to edit it? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- tBook.title = book[x].title;
- tBook.isbn = book[x].isbn;
- tBook.author = book[x].author;
- tBook.publisher = book[x].publisher;
- tBook.dateAdded = book[x].dateAdded;
- tBook.qtyOnHand = book[x].qtyOnHand;
- tBook.wholesale = book[x].wholesale;
- tBook.retail = book[x].retail;
- editor(x);
- case 'N':
- case 'n':
- validInput = true;
- clear();
- inventoryDatabaseModule();
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (validInput != true);
- } else {
- if (x == 19) {
- do {
- if (validInput != true) {
- cout << "Error: Could not find Title / ISBN. Try again? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- editBook();
- case 'N':
- case 'n':
- validInput = true;
- clear();
- inventoryDatabaseModule();
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (validInput != true);
- }
- }
- } else {
- break;
- }
- } while (validInput != true);
- }
- }
- //former clear
- }
- void removeBook(int x);
- void deleteBook() {
- clear();
- cout << "\t\tSerendipity Booksellers\n\t\tInventory Database\n\n\t\t1. Look up a Book\n\t\t2. Add a Book\n\t\t3. Edit a Book's Record\n\t\t4. Delete a Book\n\t\t5. Return to Main Menu\n\n\t\tPlease type in your input: 4\n";
- string search;
- cout << "\nSearch: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, search);
- cout << "\n";
- bool validInput;
- char selection;
- for (int x = 0; x < DBSIZE; x++) {
- size_t found = book[x].title.find(search);
- if (found != string::npos) {
- do {
- if (validInput != true) {
- cout << "\"" << book[x].title << "\" found by Title. Would you like to delete it? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- removeBook(x);
- case 'N':
- case 'n':
- validInput = true;
- clear();
- inventoryDatabaseModule();
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (validInput != true);
- } else {
- do {
- if (validInput != true) {
- found = book[x].isbn.find(search);
- if (found != string::npos) {
- do {
- if (validInput != true) {
- cout << "\"" << book[x].isbn << "\" found by ISBN. Would you like to delete it? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- removeBook(x);
- case 'N':
- case 'n':
- validInput = true;
- clear();
- inventoryDatabaseModule();
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (validInput != true);
- } else {
- if (x == 19) {
- do {
- if (validInput != true) {
- cout << "Error: Could not find Title / ISBN. Try again? (Y/N): ";
- cin >> selection;
- switch (selection) {
- case 'Y':
- case 'y':
- validInput = true;
- clear();
- deleteBook();
- case 'N':
- case 'n':
- validInput = true;
- clear();
- inventoryDatabaseModule();
- break;
- default:
- cout << "Please enter a valid response! ";
- validInput = false;
- break;
- }
- } else {
- break;
- }
- } while (validInput != true);
- }
- }
- } else {
- break;
- }
- } while (validInput != true);
- }
- }
- }
- void printDatabase() {
- clear();
- cout << "\t----------- Database Table -----------\n" << endl;
- cout << "ID\tTitle\t\t\tISBN\t\tAuthor\t\tPublisher\tDate\tQty\tWholesale\tRetail\n-----------------------------------------" << endl;
- for (int x = 0; x < bookCount; x++) {
- cout << x << "\t" << book[x].title << "\t\t\t" << book[x].isbn << "\t\t" << book[x].author << "\t\t" << book[x].publisher << "\t" << book[x].dateAdded << "\t" << book[x].qtyOnHand << "\t" << book[x].wholesale << "\t" << book[x].retail << endl;
- }
- cout << endl;
- pause();
- inventoryDatabaseModule();
- }
- void inventoryDatabaseModule() {
- char selection;
- bool validInput;
- resetTemps();
- clear();
- if (getExitCode() != true) {
- do {
- cout << "\t\tSerendipity Booksellers\n\t\tInventory Database\n\n\t\t1. Look up a Book\n\t\t2. Add a Book\n\t\t3. Edit a Book's Record\n\t\t4. Delete a Book\n\t\t5. Return to Main Menu\n\n\t\tPlease type in your input: ";
- cin >> selection;
- validInput = true;
- switch(selection) {
- case '1':
- validInput = true;
- lookUpBook();
- break;
- case '2':
- validInput = true;
- addBook();
- break;
- case '3':
- validInput = true;
- editBook();
- break;
- case '4':
- validInput = true;
- deleteBook();
- break;
- case '5':
- validInput = true;
- mainMenu();
- break;
- case '6':
- validInput = true;
- printDatabase();
- break;
- default:
- validInput = false;
- clear();
- cout << "\nPlease enter a valid selection!\n";
- break;
- }
- } while (validInput == false);
- }
- }
- void removeBook(int x) {
- clear();
- int finalBook = x;
- cout << "Book \"" << book[x].title << "\" has been deleted." << endl;
- for (int y = x; y < DBSIZE-1; y++){
- book[y].title = book[y+1].title;
- book[y].isbn = book[y+1].isbn;
- book[y].author = book[y+1].author;
- book[y].publisher = book[y+1].publisher;
- book[y].dateAdded = book[y+1].dateAdded;
- book[y].qtyOnHand = book[y+1].qtyOnHand;
- book[y].wholesale = book[y+1].wholesale;
- book[y].retail = book[y+1].retail;
- finalBook++;
- }
- finalBook++;
- book[finalBook].title = "";
- book[finalBook].isbn = "";
- bookCount--;
- cout << "Database: (" << bookCount << "/" << DBSIZE << ")" << endl;
- cout << endl;
- pause();
- inventoryDatabaseModule();
- }
- void editor(int x) {
- clear();
- bool validInput;
- char selection;
- do {
- cout << fixed;
- cout.precision(2);
- cout << "*************************************************************\n\t\tSerendipity Booksellers\n\t\t\tBook Editor Menu\n\n\tCurrent Database Size: " << bookCount << "/" << DBSIZE << "\n" << endl;
- cout << "\t\t\t\t\t+ Pending Values +" << endl;
- cout << "(1) Enter Book Title\t\t\t > --" << tBook.title << endl;
- cout << "(2) Enter ISBN\t\t\t\t > --" << tBook.isbn << endl;
- cout << "(3) Enter Author\t\t\t > --" << tBook.author << endl;
- cout << "(4) Enter Publisher\t\t\t > --" << tBook.publisher << endl;
- cout << "(5) Enter Date Added\t\t\t > --" << tBook.dateAdded << endl;
- cout << "(6) Enter Quantity on Hand\t\t > --" << tBook.qtyOnHand << endl;
- cout << "(7) Enter Wholesale Cost\t\t > --$" << tBook.wholesale << endl;
- cout << "(8) Enter Retail Price\t\t\t > --$" << tBook.retail << endl;
- cout << "(9) Save Book to Database\t" << endl;
- cout << "(0) Return to Inventory Menu" << endl;
- cout << "\n*************************************************************\n\tChoice (0-9): ";
- cin >> selection;
- validInput = true;
- switch(selection) {
- case '1':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Book Title: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.title);
- editor(x);
- break;
- case '2':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput ISBN: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.isbn);
- editor(x);
- break;
- case '3':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Author: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.author);
- editor(x);
- break;
- case '4':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Publisher: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.publisher);
- editor(x);
- break;
- case '5':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Date: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- getline(cin, tBook.dateAdded);
- editor(x);
- break;
- case '6':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Quantity on Hand: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- cin >> tBook.qtyOnHand;
- editor(x);
- break;
- case '7':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Wholesale Cost: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- cin >> tBook.wholesale;
- editor(x);
- break;
- case '8':
- validInput = true;
- clear();
- cout << "*************************************************************\n\tInput Retail Price: ";
- cin.ignore(numeric_limits<streamsize>::max(),'\n'); //Clear input buffer from previous text.
- cin >> tBook.retail;
- editor(x);
- break;
- case '9':
- validInput = true;
- clear();
- //SAVING CODE
- setTitle(book, tBook.title, bookCount);
- setISBN(book, tBook.isbn, bookCount);
- setAuthor(book, tBook.author, bookCount);
- setPub(book, tBook.publisher, bookCount);
- setDateAdded(book, tBook.dateAdded, bookCount);
- setQty(book, tBook.qtyOnHand, bookCount);
- setWholesale(book, tBook.wholesale, bookCount);
- setRetail(book, tBook.retail, bookCount);
- cout << "Edit was successful. Database: (" << bookCount << "/" << DBSIZE << ")";
- cout << endl;
- resetTemps();
- pause();
- clear();
- editor(x);
- break;
- case '0':
- validInput = true;
- clear();
- resetTemps();
- inventoryDatabaseModule();
- break;
- default:
- validInput = false;
- clear();
- cout << "\nPlease enter a valid selection!\n";
- break;
- }
- } while (validInput == false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement