Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. void lookUpBook(int bookCount, bookType bookData[]){
  2. string bookLookUp;
  3. char lookUpBookChoice;
  4. int i;
  5. bool exit = true;
  6. bool foundUpper = false;
  7. bool capitalize = true;
  8. bool lowercase = true;
  9. if (bookCount == 0)
  10. {
  11. cout << "There are no items in the database.\n"; system("pause");
  12. }
  13. else
  14. {
  15. do
  16. {
  17. cout << "\t\t>>>BOOK LOOK UP <<<\n";
  18. cout << "SEARCH: "; cin.ignore(); getline(cin,bookLookUp);
  19. //This capitalizes the first letter of every word that was inputted into the string.
  20. for(int j = 0; j < bookLookUp.length(); j++)
  21. {
  22. if (isalpha(bookLookUp[j]) && capitalize == true)
  23. {
  24. bookLookUp[j] = toupper(bookLookUp[j]);
  25. capitalize = false;
  26. }
  27. else if (isspace(bookLookUp[j]))
  28. {
  29. capitalize = true;
  30. }
  31. }
  32. //This checks the user input with the database for the book.
  33. for (i = 0; i < bookCount && exit == true; i++)
  34. {
  35. if (bookData[i].getTitle().find(bookLookUp,0) != std::string::npos)
  36. {
  37. cout << "RESULT: " << bookData[i].getTitle() << endl; cout << "View this book record? <Y/N>: "; cin >> lookUpBookChoice;
  38. while ((lookUpBookChoice != 'Y') && (lookUpBookChoice != 'y') && (lookUpBookChoice != 'N') && (lookUpBookChoice != 'n'))
  39. {
  40. cin.clear(); cin.ignore(100,'\n');
  41. cout << "\t\t" << lookUpBookChoice << " is not a valid choice. Please enter a valid choice (Y/N): "; cin >> lookUpBookChoice;
  42. }
  43. if (lookUpBookChoice == 'Y' || lookUpBookChoice == 'y')
  44. {
  45. bookinfo(i , bookData);
  46. exit = false;
  47. foundUpper = true;
  48. break;
  49. }
  50. else if (lookUpBookChoice == 'N' || lookUpBookChoice == 'n')
  51. foundUpper = true;
  52. }
  53. }
  54. if (foundUpper == false)
  55. {
  56. //This lower cases the first letter of every word that was inputted into the string.
  57. for(int j = 0; j < bookLookUp.length(); j++)
  58. {
  59. if (isalpha(bookLookUp[j]) && lowercase == true)
  60. {
  61. bookLookUp[j] = tolower(bookLookUp[j]);
  62. lowercase = false;
  63. }
  64. else if (isspace(bookLookUp[j]))
  65. {
  66. lowercase = true;
  67. }
  68. }
  69. //This checks the user input with the database for the book.
  70. for (i = 0; i < bookCount && exit == true; i++)
  71. {
  72. if (bookData[i].getTitle().find(bookLookUp,0) != std::string::npos)
  73. {
  74. cout << "RESULT: " << bookData[i].getTitle() << endl; cout << "View this book record? <Y/N>: "; cin >> lookUpBookChoice;
  75. while ((lookUpBookChoice != 'Y') && (lookUpBookChoice != 'y') && (lookUpBookChoice != 'N') && (lookUpBookChoice != 'n'))
  76. {
  77. cin.clear(); cin.ignore(100,'\n');
  78. cout << "\t\t" << lookUpBookChoice << " is not a valid choice. Please enter a valid choice (Y/N): "; cin >> lookUpBookChoice;
  79. }
  80. if (lookUpBookChoice == 'Y' || lookUpBookChoice == 'y')
  81. {
  82. bookinfo(i, bookData);
  83. exit = false;
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. if (i == bookCount)
  90. {
  91. exit = false;
  92. cout << "The book is not in the database.\n";
  93. system("pause");
  94. }
  95. } while (exit == true);
  96. }
  97. return;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement