Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. /*****************************************************************************
  2. * AUTHOR : Matthew Fernandes
  3. * Assignment 11 : Breakfast Billing System
  4. * CLASS : CS02
  5. * SECTION : MW: 7a - 8:30p, F: 7a - 11p
  6. * Due Date : 12/5/16
  7. *****************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <fstream>
  11. #include <string>
  12. #include <vector>
  13. #include <iomanip>
  14. #include <ctype.h>
  15.  
  16.  
  17. using namespace std;
  18.  
  19. /*****************************************************************************
  20. *
  21. * Assignement 11 - Breakfast Billing System
  22. *____________________________________________________________________________
  23. * Intro
  24. *
  25. *____________________________________________________________________________
  26. * INPUT:
  27. *
  28. * OUTPUT:
  29. *
  30. *****************************************************************************/
  31.  
  32. void Header();
  33. void getData();
  34. void showMenu();
  35. void printCheck(vector <string>, vector <int>);
  36.  
  37. struct menuItemType
  38. {
  39. string menuItem;
  40. double menuPrice;
  41. };
  42.  
  43. /*****************************************************************************
  44. * Header
  45. * This function will output the class header when called in main.
  46. * - returns nothing
  47. *****************************************************************************/
  48. void Header()
  49. {
  50. //OUTPUT - class heading on the screen
  51. string Header(80, '*');
  52. cout << Header << endl;
  53. cout << " Programmed by : Matthew Fernandes\n";
  54. cout << " Student ID : 10019167\n";
  55. cout << " CS02 : MW: 7a - 8:30p, F: 7a - 11p\n";
  56. cout << " Assignment 11 : Breakfast Billing System\n";
  57. cout << Header << endl;
  58. }
  59. menuItemType data[8];
  60.  
  61. void getData()
  62. {
  63. ifstream myFile;
  64.  
  65. myFile.open("menu.txt");
  66.  
  67.  
  68. //For looped used to put the contents of the file into the array.
  69. for(int i = 0; i < 8; i++)
  70. {
  71. getline(myFile, data[i].menuItem);
  72. }
  73.  
  74. myFile.close();
  75. }
  76.  
  77. void showMenu()
  78. {
  79. getData();
  80. for(int i = 0; i < 8; i++)
  81. {
  82. cout << data[i].menuItem << endl;
  83. }
  84. }
  85.  
  86. void printCheck(vector <string> items, vector <int> numbers)
  87. {
  88. double a = 0.0,b = 0.0,c = 0.0,d = 0.0,e = 0.0,f = 0.0,
  89. g = 0.0,h = 0.0,total = 0.0, tax = 0.0, finished = 0.0;
  90. int num[8] = {0,0,0,0,0,0,0,0};
  91.  
  92. double price[8] = {0,0,0,0,0,0,0,0};
  93.  
  94. for(int i = 0; i <numbers.size(); i++)
  95. {
  96. num[i] = numbers.at(i);
  97. }
  98.  
  99. for(int i = 0; i < items.size(); i ++)
  100. {
  101. if("Plain Egg" == items.at(i) || "plain egg" == items.at(i))
  102. {
  103. price[i] = (price[i] + 1.45)*num[i];
  104. a = price[i];
  105. }
  106. if("Muffin" == items.at(i) || "muffin" == items.at(i))
  107. {
  108. price[i] = (price[i] + .99)*num[i];
  109. b = price[i];
  110. }
  111. if("Fruit Basket" == items.at(i) || "fruit basket" == items.at(i))
  112. {
  113. price[i] = (price[i] + 2.49)*num[i];
  114. c = price[i];
  115. }
  116. if("Coffee" == items.at(i) || "coffee" == items.at(i))
  117. {
  118. price[i] = (price[i] + .5)*num[i];
  119. d = price[i];
  120. }
  121. if("Bacon and Egg" == items.at(i) || "bacon and egg" == items.at(i))
  122. {
  123. price[i] = (price[i] + 2.45)*num[i];
  124. e = price[i];
  125. }
  126. if("French Toast" == items.at(i) || "french toast" == items.at(i))
  127. {
  128. price[i] = (price[i] + 1.99)*num[i];
  129. f = price[i];
  130. }
  131. if("Cereal" == items.at(i) || "cereal" == items.at(i))
  132. {
  133. price[i] = (price[i] + .69)*num[i];
  134. g = price[i];
  135. }
  136. if("Tea" == items.at(i) || "tea" == items.at(i))
  137. {
  138. price[i] = (price[i] + .75)*num[i];
  139. h = price[i];
  140. }
  141. }
  142. total = a + b + c + d + e + f + g + h;
  143. tax = total*.05;
  144. finished = tax+total;
  145. //int spaces;
  146. cout << "Welcome to Johnny's Restaurant" << endl;
  147. cout << endl;
  148. for(int i = 0; i < numbers.size(); i++)
  149. {
  150. //spaces = 35 - sizeof(items)/sizeof(items[i]);
  151. cout << fixed << setprecision(2)<< numbers.at(i) << " "
  152. << left << setw(34) << items.at(i)<< "$" << price[i] << endl;
  153. }
  154. cout << "Tax $" << tax << endl;
  155. cout << "-----------------------------------------" << endl;
  156. cout << "Amount Due $" << finished << endl;
  157. }
  158.  
  159. int main()
  160. {
  161. Header();
  162.  
  163. cout << "Welcome to Johnny's Restaurant" << endl;
  164. cout << endl;
  165.  
  166. showMenu();
  167.  
  168. string rawInput;
  169. int num;
  170. vector <int> numbers;
  171. vector<string> items;
  172. cout << endl;
  173. cout << "Choose your items from the menu followed by [ENTER]." << endl;
  174. cout << "Enter 'done' to finish your order: " << endl;
  175. while(rawInput != "done")
  176. {
  177. getline(cin,rawInput);
  178. if(rawInput == "Plain Egg" || rawInput == "Bacon and Egg"
  179. || rawInput == "Muffin" || rawInput == "French Toast"
  180. || rawInput == "Fruit Basket" || rawInput == "Cereal"
  181. || rawInput == "Coffee" || rawInput == "Tea"
  182. || rawInput == "plain egg" || rawInput == "bacon and egg"
  183. || rawInput == "muffin" || rawInput == "french toast"
  184. || rawInput == "fruit basket" || rawInput == "cereal"
  185. || rawInput == "coffee" || rawInput == "tea" || rawInput == "done")
  186. {
  187. if(rawInput == "done")
  188. break;
  189. else
  190. items.push_back(rawInput);
  191. }
  192. else
  193. {
  194. cout << "Sorry that's not a valid input, please enter a valid choice: ";
  195. cout << endl;
  196. }
  197. }
  198. cout << endl;
  199.  
  200. for(int i = 0; i < items.size(); i++)
  201. {
  202. cout << "How many " << items.at(i) << "s would you like? ";
  203. cin >> num;
  204. numbers.push_back(num);
  205. }
  206. cout << endl;
  207.  
  208.  
  209. printCheck(items, numbers);
  210.  
  211. return 0;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement