Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. // Program Name: A2P2.cpp
  2. // Programmer Name: Alex Proulx
  3. // Overview: This is a menu for Vitto's Vending.
  4. // Date: 2/8/2016
  5.  
  6. #include <iostream>
  7. #include <string>
  8. #include <iomanip>
  9. #include <cstdlib>
  10. #include <windows.h>
  11. #include <conio.h>
  12. #include <process.h>
  13.  
  14. using namespace std;
  15.  
  16. void gotoxy(int x, int y)
  17. {
  18. COORD coord;
  19. coord.X = x; //column coordinate
  20. coord.Y = y; //row coordinate
  21. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  22. }
  23. void clrscr(int x, int y)
  24. {
  25. COORD coordScreen = { x, y };
  26. DWORD cCharsWritten;
  27. CONSOLE_SCREEN_BUFFER_INFO csbi;
  28. DWORD dwConSize;
  29. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  30. GetConsoleScreenBufferInfo(hConsole, &csbi);
  31. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  32. FillConsoleOutputCharacter(hConsole, TEXT(' '),
  33. dwConSize, coordScreen, &cCharsWritten);
  34. GetConsoleScreenBufferInfo(hConsole, &csbi);
  35. FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
  36. dwConSize, coordScreen, &cCharsWritten);
  37. SetConsoleCursorPosition(hConsole, coordScreen);
  38. }
  39. void greetings()
  40. {
  41. clrscr(0, 0);
  42. gotoxy(30, 10);
  43. cout << "Welcome to Vitto's!" << endl;
  44. gotoxy(30, 12);
  45. cout << "Mangiare, Mangiare!" << endl;
  46. gotoxy(30, 25);
  47. cout << "Press enter to continue...";
  48. _getch();
  49. clrscr(0, 0);
  50. }
  51.  
  52. void thanks_for_shopping(int total_purchases)
  53. {
  54. clrscr(0, 0);
  55. gotoxy(25, 10);
  56. cout << "You have purchased" << total_purchases << "number of items.";
  57. gotoxy(25, 12);
  58. cout << "Thank You for shopping at Vitto's!";
  59. }
  60.  
  61. void update_vending(string choice[8], string item_name[8],
  62. string price[7], int qty[7], string headers[4], int& header_position,
  63. int& choice_position, int& item_position, int& price_position, int& qty_position, int& total_purchases)
  64. {
  65. gotoxy(30, 1);
  66. cout << "VITTO'S VENDETTA VENDING" << endl;
  67.  
  68. for (int i = 0; i < 4; i++)
  69. {
  70. gotoxy(header_position, 3);
  71. cout << headers[i] << endl;
  72.  
  73. if (header_position == 8)
  74. {
  75. header_position = 18;
  76. }
  77.  
  78. else if (header_position == 18)
  79. {
  80. header_position = 31;
  81. }
  82.  
  83. else if (header_position == 18)
  84. {
  85. header_position = 40;
  86. }
  87. }
  88.  
  89. for (int i = 0; i < 8; i++)
  90. {
  91. gotoxy(8, choice_position);
  92. cout << choice[i] << endl;
  93. choice_position++;
  94. }
  95.  
  96. for (int i = 0; i < 8; i++)
  97. {
  98. gotoxy(18, item_position);
  99. cout << item_name[i] << endl;
  100. item_position++;
  101. }
  102.  
  103. for (int i = 0; i < 7; i++)
  104. {
  105. gotoxy(31, price_position);
  106. cout << price[i] << endl;
  107. price_position++;
  108. }
  109.  
  110. for (int i = 0; i < 8; i++)
  111. {
  112. gotoxy(40, qty_position);
  113. cout << qty[i] << endl;
  114. }
  115.  
  116. int finished_purchases = 1;
  117.  
  118. while (finished_purchases == 1)
  119. {
  120. char item_choice = _getch();
  121. item_choice = tolower(item_choice);
  122. int item_number = item_choice;
  123.  
  124. //Quantity
  125. switch (item_choice)
  126. {
  127. case '1':
  128. case '2':
  129. case '3':
  130. case '4':
  131. case '5':
  132. case '6':
  133. case '7':
  134.  
  135. if (qty[item_number - 49] > 0)
  136. {
  137. qty[item_number - 49]--;
  138. gotoxy(40, 5 + item_number - 49);
  139. cout << qty[item_number - 49];
  140. total_purchases++;
  141. }
  142.  
  143. if (qty[item_number - 49] == 0)
  144. {
  145. gotoxy(40, 5 + item_number - 49);
  146. cout << "OUT";
  147. }
  148. break;
  149.  
  150. case 'e':
  151. finished_purchases = 0;
  152. thanks_for_shopping(total_purchases);
  153. }
  154. }
  155. }
  156.  
  157. int main()
  158. {
  159. char repeat = 'y';
  160. while (repeat == 'y')
  161. {
  162. int header_position = 8;
  163. int choice_position = 5;
  164. int item_position = 5;
  165. int price_position = 5;
  166. int qty_position = 5;
  167. int qty[7] = { 5, 5, 5, 5, 5, 5, 5 };
  168. int total_purchases = 0;
  169. string choice[8] = { "1.", "2.", "3.", "4.", "5.", "6.", "7.", "E." };
  170. string item_name[8] = { "Soprano Soup", "Godfather Pasta", "Gotti Gum", "Capone Crisps", "Gambino Pie", "Luciano Lunch", "Mafia Muffin", "No More Purchases" };
  171. string price[7] = { "4.75", "5.85", "2.50", "3.00", "6.75", "8.50", "1.75" };
  172. string headers[4] = { "CHOICE", "ITEM NAME", "PRICE", "QTY" };
  173.  
  174. //Function Call
  175. greetings();
  176. update_vending(choice, item_name, price, qty, headers, header_position, choice_position, item_position, price_position, qty_position, total_purchases);
  177.  
  178. //Restart Application
  179. gotoxy(25, 10);
  180. cout << "Would you like to order more food? (y/n): ";
  181. cin >> repeat;
  182. }
  183. cin.get();
  184. return 0;
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement