Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. // Deven Pace - Course Project
  2. // Airline Seat Reservation Program
  3. //Start
  4. //develop constants and function prototypes
  5. //declare each col and row values
  6. //develope display menu functions
  7. //open seat price File
  8. //if opened unsuccessful, code error message
  9. //code switch statement for each seating options
  10. //seating option functions
  11. //end
  12.  
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <fstream>
  16. #include <string>
  17.  
  18. using namespace std;
  19.  
  20. //!!!Remember * is taken and # is available!!!//
  21.  
  22. //------------------------------------------------------------------------------
  23. //---Constants---//
  24. //------------------------------------------------------------------------------
  25.  
  26. //---First Class---//
  27. const int firstCOLS = 4;
  28. const int firstROWS = 5;
  29.  
  30. //---Coach---//
  31. const int coachCOLS = 6;
  32. const int coachROWS = 5;
  33.  
  34. //------------------------------------------------------------------------------
  35. //---Function Proto---//
  36. //------------------------------------------------------------------------------
  37.  
  38. void seatChart(double firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray [coachROWS][coachCOLS]);
  39. void displayMenu(double, double firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray [coachROWS][coachCOLS]);
  40.  
  41. //------------------------------------------------------------------------------
  42. //---Main Program---//
  43. //------------------------------------------------------------------------------
  44.  
  45. int main()
  46. {
  47.  
  48. //---Variables---//
  49. double choice = 0;
  50. const int firstClass = 1,
  51. firstCoach = 2,
  52. secondCoach = 3,
  53. displaySeat = 4,
  54. EXIT = 5;
  55. double firstArray[firstROWS][firstCOLS];
  56. double coachOneArray[coachROWS][coachCOLS];
  57. double coachTwoArray[coachROWS][coachCOLS];
  58.  
  59. //---Start of Menu---//
  60. cout << "Rigsby Programming Airline Reservation" << endl;
  61. cout << "--------------------------------------" << endl;
  62.  
  63. //---display menu options---//
  64.  
  65. displayMenu(choice, firstArray,coachOneArray, coachTwoArray);
  66.  
  67. return 0;
  68. }
  69.  
  70. //------------------------------------------------------------------------------
  71. //---Display Menu Function---//
  72. //------------------------------------------------------------------------------
  73.  
  74. void displayMenu(double, double, firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray[coachROWS][coachCOLS])
  75. {
  76. //---Variables---//
  77. int CHOICE;
  78. int firstClassRow, firstClassCol;
  79. int secondClassRow, secondClassCol;
  80.  
  81. double countFirst = 0, countFirstCoach = 0, countSecondCoach = 0;
  82.  
  83. const int FIRSTCLASS = 1,
  84. FIRSTCOACH = 2,
  85. SECONDCOACH = 3,
  86. DISPLAYSEAT = 4,
  87. EXIT = 5;
  88.  
  89. double firstPrice;
  90. double coachOnePrice;
  91. double coachTwoPrice;
  92.  
  93. //---Menu---//
  94. cout << "Please choose from the following option: (1-5)" << endl;
  95. cout << "----------------------------------------------\n" << endl;
  96. cout << "1: First Class" << endl;
  97. cout << "2: First Coach" << endl;
  98. cout << "3: Second Coach" << endl;
  99. cout << "4: Display Available Seating" << endl;
  100. cout << "5: Exit" << endl;
  101.  
  102. //---User Input---//
  103. cin >> CHOICE;
  104.  
  105. //------------------------------------------------------------------------------
  106. //---Open Input File/Check for failure---//
  107. //------------------------------------------------------------------------------
  108.  
  109. //---Open File---///
  110. ifstream inputfile;
  111. inputfile.open("SeatPrices.txt");
  112.  
  113. //---Validation Error---//
  114. if (inputfile.fail())
  115. {
  116. cout << "Sorry, that file does not exits or can not be found";
  117. exit(1);
  118. }
  119.  
  120. //---Colect Numbers From File---//
  121. inputfile >> firstPrice;
  122. inputfile >> coachOnePrice;
  123. inputfile >> coachTwoPrice;
  124.  
  125. //---Close File---//
  126. inputfile.close();
  127.  
  128. //------------------------------------------------------------------------------
  129. //---Switch Statements and Menu---//
  130. //------------------------------------------------------------------------------
  131.  
  132. switch (CHOICE)
  133. {
  134. //---First Class Case---//
  135. case FIRSTCLASS:
  136. cout << "You have selected to reserve first class" << endl;
  137. cout << "\nThe price for a first class seat is: $" << firstPrice << endl;
  138. cout << "\nIf you would like to continue, please choose a seat: (1-5) ";
  139. cin >> firstClassRow;
  140.  
  141. //---If statements---//
  142. if (firstClassRow > 5)
  143. {
  144. cout <<"\nYou have entered an incorrect row number, please choose 1-5 ";
  145. cin >> firstClassRow;
  146. }
  147.  
  148. cout << "\nPlease select an available seat: (1-4)";
  149. cin >> firstClassCol;
  150.  
  151. if (firstClassCol > 4)
  152. {
  153. cout << "You have entered an incorrect seat number, please chose 1-4 ";
  154. cin >> firstClassCol;
  155. }
  156.  
  157. if (firstArray[firstROWS - 1][firstCOLS - 1] != '*')
  158. {
  159. firstArray[firstROWS - 1][firstCOLS - 1] = '*';
  160. cout << endl << "Your seat has been reserved\n";
  161. countFirst++;
  162. }
  163. else {
  164. cout << "Sorry, that seat is occupied." << endl;
  165. }
  166. break;
  167.  
  168. //---First Coach Case---//
  169. case FIRSTCOACH:
  170. cout << "You have chosen to reserve first coach class" << endl;
  171. cout << "\nThe price for a first coach seat is: $" << coachOnePrice << endl;
  172. cout << "\nNow please pick which row you would like to sit in: ";
  173. cin >> firstClassCol;
  174. cout << "Please pick which seat you would like to sit in. Please enter between 6-10: ";
  175. cin >> firstClassCol;
  176.  
  177. if (firstClassCol > 10)
  178. {
  179. cout << "\nYou have entered an incorrect row number, please enter between 6-10 ";
  180. cin >> firstClassCol;
  181. }
  182.  
  183. cout << "\nPlease pick which seat you would like to sit in, please enter between 1-6: ";
  184. cin >> firstClassCol;
  185.  
  186. if (firstClassCol > 6)
  187. {
  188. cout << "You have entered an incorrect seat number, please enter between 1-6";
  189. cin >> firstClassCol;
  190. }
  191.  
  192. if (coachOneArray[coachROWS - 1][coachCOLS - 1] != '*')
  193. {
  194. coachOneArray[coachROWS - 1][coachCOLS - 1] = '*';
  195. cout << endl << "Your seat has been reserved\n";
  196. countFirstCoach++;
  197. }
  198.  
  199. else {
  200. cout << "I'm sorry the seat is occupied" << endl;
  201. }
  202. break;
  203.  
  204. //---Second Coach Case---//
  205. case SECONDCOACH:
  206. cout << "You have chosen to reserve second coach class" << endl;
  207. cout << "\nThe price for a second coach seat is: $" << coachTwoPrice << endl;
  208. cout << "\n Now please pick which r ow you would like to sit in: ";
  209. cin >> secondClassRow;
  210.  
  211. if (secondClassRow > 15)
  212. {
  213. cout << "\n You have entered an invalid row number, please enter between 11-15 ";
  214. cin >> secondClassRow;
  215. }
  216.  
  217. cout << "\nPlease pick which seat you would like to sit in, please entere between 1-6: ";
  218. cin >> secondClassCol;
  219.  
  220. if (secondClassCol > 6)
  221. {
  222. cout << "You have entered an invalid seat number, please pick between 1-6";
  223. cin >> secondClassCol;
  224. }
  225.  
  226. if (coachTwoArray[coachROWS - 1][coachCOLS - 1] != '*')
  227. {
  228.  
  229. coachTwoArray[coachROWS - 1][coachCOLS - 1] = '*';
  230. cout << endl << "Your seat has been reserved\n";
  231. countSecondCoach++;
  232. }
  233.  
  234. else {
  235. cout <<"I'm sorry, that seat is occupied." << endl;
  236. }
  237. break;
  238.  
  239. //---Display Case---//
  240. case DISPLAYSEAT:
  241. seatChart(firstArray, coachOneArray, coachTwoArray);
  242. break;
  243.  
  244. //---Exit Case---//
  245. case EXIT:
  246. cout <<"You have chosen to exit the program." << endl;
  247. exit(1);
  248. break;
  249. }
  250. }
  251.  
  252. //------------------------------------------------------------------------------
  253. //---Function for the Seating Chart---//
  254. //------------------------------------------------------------------------------
  255.  
  256. void seatChart(double firstArray[firstROWS][firstCOLS], double coachOneArray[coachROWS][coachCOLS], double coachTwoArray[coachROWS][coachCOLS])
  257. {
  258. cout << "The seating chart is as follows:" << endl;
  259. cout << "--------------------------------" << endl;
  260.  
  261. //---First Class Seating---//
  262. cout << "First Class is seats 1-4 and Row 1-5\n" << endl;
  263.  
  264. for (int x = 0; x < firstROWS; x++)
  265. {
  266. for (int y = 0; y < firstCOLS; y++)
  267. {
  268. firstArray[x][y] = '#';
  269. cout << firstArray[x][y];
  270. }
  271. cout << endl;
  272. }
  273. //---First Coach seating---//
  274. cout << "First Coach Class is seats 1-6 and Row 6-10\n" << endl;
  275.  
  276. for (int x = 0; x < coachROWS; x++)
  277. {
  278. for (int y = 0; y < coachCOLS; y++)
  279. {
  280. coachOneArray[x][y] = '#';
  281. cout << coachOneArray[x][y];
  282. }
  283. cout << endl;
  284. }
  285.  
  286. //---Second Coach seating---//
  287. cout << "\nSecond Coach Class are seats 1-6, Rows 11-15\n" << endl;
  288.  
  289. for (int x = 0; x < coachROWS; x++)
  290. {
  291. for (int y = 0; y < coachCOLS; y++)
  292. {
  293. coachOneArray[x][y] = '#';
  294. cout << coachTwoArray[x][y];
  295. }
  296. }
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement