View Single Post
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

airplane seating prices

 
0
  #1
Jul 26th, 2005
hi, I'm working on a project and I'm almost done. However, I'm having a few problems with the prices.
this is the guide for the project:
Airplane Seat Allocation System
Write a C++ program for the following task using modular approach.
a) 48 seats in 12 rows with a Aisle in the center. Seats at end of each row is a “Window Seat�. The middle two seats in a row are “Aisle� seats and 4 Seats in row one are “Leg Room� Seats.

b) The program should display the seat plan.

c) Display a welcome greeting ,

d) Menu driven program to allow request for, ‘Window’, ‘Aisle’ and ‘Leg Room’ Seats, display seat # and block (if available). If the seats are not available in existing category, display a sorry message.

e) Provide a ‘Quit’ facility to exit from the program.

AND THIS IS MY CODE SO FAR:

  1.  
  2. //Airplanes Seating Allocation System
  3.  
  4. //libraries included
  5. #include <iostream.h>
  6. #include <stdlib.h>
  7. #include <iomanip.h>
  8.  
  9. char airplane [12] [4];
  10. float ticketPrice [12] = { 0.0 };
  11. float totalsales = 0.0f;
  12. int row, seat;
  13.  
  14. //Function Prototypes
  15. void DisplaySeats (void);
  16. void DisplayPrices (float []);
  17. void DisplaySales ();
  18. void PurchaseTicket (float[]);
  19.  
  20. void main ()
  21. {
  22. int choice;
  23. char response = 'Y';
  24.  
  25. cout << "WELCOME TO C++ AIRPLANES SEATING ALLOCATION SYSTEM!\n";
  26. cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n";
  27.  
  28. //initialize airplane with labels (A, S, W, L) - all seats available
  29. for (int y =0; y < 1; y++)
  30. for (int q = 0; q <4; q++)
  31. airplane [y][q] = 'L'; //Leg Room Seats
  32. for (y = 1; y < 12; y++)
  33. {
  34. for (int z = 0; z < 4; z++)
  35. {
  36. for (int x = 0; x < 1; x++)
  37. airplane [y][x] = 'S'; //Regular Seats
  38. for (int v = 1; v < 3; v++)
  39. airplane [y][v] = 'A'; //Aisle Seats
  40. for (int w = 3; w <4; w++)
  41. airplane [y][w] = 'W'; //Window Seats
  42. }
  43. }
  44.  
  45. //initialize seat prices for each of the 12 rows
  46. for (int i = 0; i < 12; i++)
  47. {
  48. cout << "\nPlease enter ticket price for Row " << i + 1 << ": ";
  49. cin >> ticketPrice [i];
  50. }
  51.  
  52. while (response = 'Y')
  53. {
  54. //display menu of choices
  55.  
  56. cout << "\n\n\n\tC++ Airplane Seating Allocation System" << endl << endl;
  57. cout << "\n\t1. View Availabe Seats";
  58. cout << "\n\t2. View Seating Prices";
  59. cout << "\n\t3. View Ticket Sales";
  60. cout << "\n\t4. Purchase a Ticket";
  61. cout << "\n\t5. Exit the Program\n\n";
  62. cout << "\n\tEnter your choice (1-5): ";
  63. cin >> choice;
  64. switch (choice)
  65. {
  66. case 1:
  67. cout << "Testing. DisplaySeats() called\n";
  68. DisplaySeats();
  69. break;
  70. case 2:
  71. DisplayPrices(ticketPrice);
  72. break;
  73. case 3:
  74. DisplaySales();
  75. break;
  76. case 4:
  77. PurchaseTicket(ticketPrice);
  78. break;
  79. case 5:
  80. exit (0);
  81. break;
  82. default:
  83. exit(0);
  84. break;
  85. } //end switch
  86. }; //end while
  87. } //end main
  88.  
  89. //Display a seating chart of the airplane
  90. void DisplaySeats (void)
  91. {
  92. cout << "\n\tSEATS\n";
  93. cout << " 1234";
  94. cout << endl;
  95.  
  96. for (int r = 0; r < 12; r++)
  97. {
  98. cout << "\nRow " << setw(2) << r + 1 << "\t";
  99. for (int s =0; s < 4; s++)
  100. {
  101. cout << airplane[r][s];
  102. }
  103. }
  104. cout << "\n\n\n\tLegend:\t* = Sold";
  105. cout << "\n\t\tA = Aisle Seats (Available)";
  106. cout << "\n\t\tW = Window Seats (Available)";
  107. cout << "\n\t\tS = Regular Seats (Avaiable)";
  108. cout << "\n\t\tL = Leg Room Seats (Available)";
  109. cout << endl;
  110.  
  111. char keyin;
  112. cout << endl << endl;
  113. cout << "\nPress an alphanumeric key to continue.";
  114. cin >> keyin;
  115.  
  116. } //end DisplaySeats
  117.  
  118. void DisplayPrices(float price[])
  119. {
  120. cout << "\n\tTicket Prices By Row: " << endl << endl;
  121. cout << "\tRow Price" << endl;
  122. cout << "\t------ -------" << endl << endl;
  123. cout.precision(2);
  124. cout.setf(ios::fixed | ios::right);
  125. for (int m =0; m < 12; m++)
  126. {
  127. cout << "\n\tRow " << setw(2) << m+1 << ":\t\t" << setw(5) << price[m];
  128. }
  129.  
  130. char keyin;
  131. cout << endl << endl;
  132. cout << "\nPress an alphanumeric key to continue.";
  133. cin >> keyin;
  134. }
  135.  
  136. void PurchaseTicket(float price[])
  137. {
  138. int a, b = 0;
  139. char response;
  140.  
  141. cout << "\n\t C++ Airplane Seating Allocation System" << endl;
  142. cout << "\t\tTicket Purchase Opportunity" << endl;
  143. do
  144. {
  145. do
  146. {
  147. cout << "\nPlease enter row number (1-12): ";
  148. cin >> a;
  149. } while (a <1 || a > 12);
  150. do
  151. {
  152. cout << "\nPlease enter seat number (1-4): ";
  153. cin >> b;
  154. } while ( b < 1 || b > 4);
  155.  
  156. if (airplane [a-1][b-1] == 'A' || airplane [a-1][b-1] == 'L' ||
  157. airplane [a-1][b-1] == 'W' || airplane [a-1][b-1] == 'S') //if the seat is available
  158. {
  159. airplane[a-1][b-1] = '*'; //indicate that the seat is taken
  160. totalsales +=ticketPrice[a-1];
  161. cout << "\nYour purchase of Seat " << b << "in Row " << a << "is confirmed." << endl;
  162. }
  163. else //seat has bee sold
  164. {
  165. cout << "\nSorry. That seat has been sold.\n";
  166. }
  167.  
  168. cout << "\nWould you like to purchase another seat?";
  169. cin >> response;
  170. } while (toupper(response) == 'Y');
  171. }
  172.  
  173. void DisplaySales ()
  174. {
  175. cout.setf(ios::fixed);
  176. cout << "\n\nTotal Sales to Date: $" << setprecision(2) << totalsales << endl;
  177. }

I tried to set different prices for the seats but I don't know how to work around the array problem. what I mean is that, how can I put these different prices in dirrent arrays and have them added up and stored inthe totalsales function?

I also don't know how to separate the column so that it would have an aisle down the middle.

Can you please help?

Thanks in advance,
Karen
Reply With Quote