Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void lookUpBook(int bookCount, bookType bookData[]){
- string bookLookUp;
- char lookUpBookChoice;
- int i;
- bool exit = true;
- bool foundUpper = false;
- bool capitalize = true;
- bool lowercase = true;
- if (bookCount == 0)
- {
- cout << "There are no items in the database.\n"; system("pause");
- }
- else
- {
- do
- {
- cout << "\t\t>>>BOOK LOOK UP <<<\n";
- cout << "SEARCH: "; cin.ignore(); getline(cin,bookLookUp);
- //This capitalizes the first letter of every word that was inputted into the string.
- for(int j = 0; j < bookLookUp.length(); j++)
- {
- if (isalpha(bookLookUp[j]) && capitalize == true)
- {
- bookLookUp[j] = toupper(bookLookUp[j]);
- capitalize = false;
- }
- else if (isspace(bookLookUp[j]))
- {
- capitalize = true;
- }
- }
- //This checks the user input with the database for the book.
- for (i = 0; i < bookCount && exit == true; i++)
- {
- if (bookData[i].getTitle().find(bookLookUp,0) != std::string::npos)
- {
- cout << "RESULT: " << bookData[i].getTitle() << endl; cout << "View this book record? <Y/N>: "; cin >> lookUpBookChoice;
- while ((lookUpBookChoice != 'Y') && (lookUpBookChoice != 'y') && (lookUpBookChoice != 'N') && (lookUpBookChoice != 'n'))
- {
- cin.clear(); cin.ignore(100,'\n');
- cout << "\t\t" << lookUpBookChoice << " is not a valid choice. Please enter a valid choice (Y/N): "; cin >> lookUpBookChoice;
- }
- if (lookUpBookChoice == 'Y' || lookUpBookChoice == 'y')
- {
- bookinfo(i , bookData);
- exit = false;
- foundUpper = true;
- break;
- }
- else if (lookUpBookChoice == 'N' || lookUpBookChoice == 'n')
- foundUpper = true;
- }
- }
- if (foundUpper == false)
- {
- //This lower cases the first letter of every word that was inputted into the string.
- for(int j = 0; j < bookLookUp.length(); j++)
- {
- if (isalpha(bookLookUp[j]) && lowercase == true)
- {
- bookLookUp[j] = tolower(bookLookUp[j]);
- lowercase = false;
- }
- else if (isspace(bookLookUp[j]))
- {
- lowercase = true;
- }
- }
- //This checks the user input with the database for the book.
- for (i = 0; i < bookCount && exit == true; i++)
- {
- if (bookData[i].getTitle().find(bookLookUp,0) != std::string::npos)
- {
- cout << "RESULT: " << bookData[i].getTitle() << endl; cout << "View this book record? <Y/N>: "; cin >> lookUpBookChoice;
- while ((lookUpBookChoice != 'Y') && (lookUpBookChoice != 'y') && (lookUpBookChoice != 'N') && (lookUpBookChoice != 'n'))
- {
- cin.clear(); cin.ignore(100,'\n');
- cout << "\t\t" << lookUpBookChoice << " is not a valid choice. Please enter a valid choice (Y/N): "; cin >> lookUpBookChoice;
- }
- if (lookUpBookChoice == 'Y' || lookUpBookChoice == 'y')
- {
- bookinfo(i, bookData);
- exit = false;
- break;
- }
- }
- }
- }
- if (i == bookCount)
- {
- exit = false;
- cout << "The book is not in the database.\n";
- system("pause");
- }
- } while (exit == true);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement