Guest User

Untitled

a guest
Apr 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. /* Program: Project 2 (Serendipity Booksellers)
  2. Author: David Nelson
  3. Class: CSCI140
  4. Date: 10/10/2011
  5. Description: Main Menu Module
  6.  
  7. I certify that the code below is my own work.
  8.  
  9. Exception(s): N/A
  10.  
  11. */
  12. #include <iomanip>
  13. #include <iostream>
  14. #include "bookdata.h"
  15. //#include "cashier.h"
  16. #include "invmenu.h"
  17. #include "reports.h"
  18. #include "mainmenu.h"
  19. #include "BookCollection.h"
  20.  
  21. using namespace std;
  22.  
  23. void cashier();
  24.  
  25.  
  26. BookData book[20];
  27.  
  28. int main()
  29. {
  30.  
  31. int menuChoice;
  32. do
  33. {
  34. cout << "\t\t\tSerendipity Booksellers" << endl;
  35. cout << "\t\t\t\tMain Menu" << endl;
  36. cout << endl;
  37. cout << "\t1. Cashier Module" << endl;
  38. cout << "\t2. Inventory Database Module" << endl;
  39. cout << "\t3. Report Module" << endl;
  40. cout << "\t4. Exit" << endl;
  41. cout << endl;
  42. cout << "\tEnter your choice: ";
  43. cin >> menuChoice;
  44. if (menuChoice < 1 || menuChoice > 4)
  45. cout << "\aInvalid entry!." << endl;
  46. if (menuChoice == 1)
  47. cashier();
  48. if (menuChoice == 2)
  49. invMenu(book);
  50. if (menuChoice == 3)
  51. reports(book);
  52. }
  53. while (menuChoice !=4);
  54. return 0;
  55. }
  56. void Menu::cashier()
  57. {
  58. string date, isbn, title;
  59. int qty,locationInt, bQty;
  60. double subTotal, salesTax, totalPrice = 0, unitPrice;
  61. char runAgain;
  62. cout << "\nSerendipity Booksellers" << endl;
  63. cout << "Cashier Module" << endl;
  64. cout << endl;
  65. cout << "Date: ";
  66. cin >> date;
  67. do
  68. {
  69. cout << "Quantity of Books: ";
  70. cin >> qty;
  71. cout << "ISBN: ";
  72. cin >> isbn;
  73.  
  74. locationInt = findBook(book, isbn);
  75.  
  76. if(locationInt == -1)
  77. {
  78. cout << "Cannot locate ISBN" << endl;
  79. cout << "Would you like to enter a new ISBN? [Y/N]: ";
  80. cin >> runAgain;
  81. }
  82. else
  83. {
  84. title = book[locationInt].getTitle();
  85. unitPrice = book[locationInt].getRetail();
  86.  
  87. if(qty > book[locationInt].getQty())
  88. {
  89. cout << "Not enough books\n";
  90. break;
  91. }
  92. else
  93. {
  94.  
  95. bQty=book[locationInt].getQty();
  96. book[locationInt].setQty(bQty-qty);
  97. cout << "\nSerendipity Booksellers\n" << endl;
  98. cout << "Date: " << date << endl;
  99. cout << "QTY\tISBN\t\tTITLE\t\t\t\tPRICE\t\tTOTAL" << endl;
  100. cout << "-----------------------------------------------------------------------------" << endl;
  101. cout << qty << "\t" << setw(13) << isbn << " " << setw(30) << left << title << "$" << setw(6) << right << showpoint << setprecision (2) << fixed << unitPrice << "\t $" << setw(6) << right << showpoint << setprecision (2) << fixed << (qty * unitPrice);
  102. cout << endl << endl;
  103.  
  104. subTotal = qty * unitPrice;
  105. salesTax = subTotal * .06;
  106. totalPrice = subTotal + salesTax;
  107. cout << "Do you want to add another book?: ";
  108. cin >> runAgain;
  109. }
  110. }
  111.  
  112. while (runAgain !='N' && runAgain !='n')
  113. {
  114. if (runAgain !='Y' && runAgain !='y' && runAgain !='N' && runAgain !='n')
  115. cout << "\aInvalid entry!" << endl;
  116. else if(runAgain == 'Y' || runAgain == 'y')
  117. {
  118. cout << endl;
  119. cout << "Quantity of Books: ";
  120. cin >> qty;
  121. cout << "ISBN: ";
  122. cin >> isbn;
  123. locationInt = findBook(book, isbn);
  124.  
  125. if(locationInt == -1)
  126. {
  127. cout << "Cannot locate ISBN\n";
  128. cout << "Do you want to add another book?: ";
  129. cin >> runAgain;
  130. }
  131. else
  132. {
  133. title = book[locationInt].getTitle();
  134. unitPrice = book[locationInt].getRetail();
  135.  
  136. if(qty > book[locationInt].getQty())
  137. {
  138. cout << "Not enough books\n";
  139. break;
  140. }
  141. else
  142. {
  143.  
  144. bQty=book[locationInt].getQty();
  145. book[locationInt].setQty(bQty-qty);
  146. cout << "QTY\tISBN\t\tTITLE\t\t\t\tPRICE\t\tTOTAL" << endl;
  147. cout << "-----------------------------------------------------------------------------" << endl;
  148. cout << qty << "\t" << setw(13) << isbn << " " << setw(30) << left << title << "$" << setw(6) << right << showpoint << setprecision (2) << fixed << unitPrice << "\t $" << setw(6) << right << showpoint << setprecision (2) << fixed << (qty * unitPrice);
  149. cout << endl << endl;
  150.  
  151. subTotal = subTotal + (qty * unitPrice);
  152. salesTax = salesTax + (subTotal * .06);
  153. totalPrice = totalPrice + (qty * unitPrice) + (subTotal * .06);
  154. cout << "Do you want to add another book?: ";
  155. cin >> runAgain;
  156. }
  157. }
  158. }
  159. }
  160. if(locationInt != -1)
  161. {
  162. cout << "\nSerendipity Booksellers\n" << endl;
  163. cout << "Date: " << date << endl;
  164. /* cout << "QTY\tISBN\t\tTITLE\t\t\t\tPRICE\t\tTOTAL" << endl;
  165. cout << "-----------------------------------------------------------------------------" << endl;
  166. cout << qty << "\t" << setw(13) << isbn << " " << setw(30) << left << title << "$" << setw(6) << right << showpoint << setprecision (2) << fixed << unitPrice << "\t $" << setw(6) << right << showpoint << setprecision (2) << fixed << subTotal;
  167. */ cout << endl;
  168. cout << endl;
  169. cout << "\t\t\tSUBTOTAL:\t\t\t\t $" << right << setw(6) << fixed << showpoint << setprecision(2) << subTotal << endl;
  170. cout << "\t\t\tTAX: \t\t\t\t $" << right << setw(6) << fixed << showpoint << setprecision(2) << salesTax << endl;
  171. cout << "\t\t\tTOTAL: \t\t\t\t $" << right << setw(6) << fixed << showpoint << setprecision(2) << totalPrice << endl;
  172. cout << endl;
  173. }
  174.  
  175. do
  176. {
  177.  
  178. cout << "Do you want another transaction?: ";
  179. cin >> runAgain;
  180. if (runAgain != 'Y' && runAgain != 'y' && runAgain !='N' && runAgain != 'n')
  181. cout << "\aInvalid entry!" << endl;
  182. }
  183. while (runAgain != 'Y' && runAgain != 'y' && runAgain != 'N' && runAgain != 'n');
  184. if (runAgain == 'N' || runAgain == 'n')
  185. {
  186. cout << "Thank you for shopping Serendipity!\n" << endl;
  187. break;
  188. }
  189.  
  190. }
  191. while (runAgain != 'N' || runAgain != 'n');
  192. return;
  193. }
Add Comment
Please, Sign In to add comment