1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
// global constants
const int numOfRows = 14;
const int numOfSeats = 6;
char ArrayOfSeats [numOfRows] [numOfSeats];
// function prototypes
// takes Seat array and initializes to empty seats
void InitializeSeatingArray ();
// reads row index, seat index, and seat status from binary file, the stores row and seat index values to enumerated seat status in array.
void ReadAndStoreBinaryFile ();
// counts and displays total number of empty, reserved, and purchased seats to console
void DisplaySeatStatus ();
// displays a seating preference menu for user and prompts for preference
void DisplaySeatPrefMenu ();
// determines validity of user's seat choice
void GetAndValidateUserSeatPref ();
// saves data from Seat array to Binary file
void SaveBinaryFile ();
// displays all remaining empty seats to console
void DisplayEmptySeats ();
int main()
{
return 0;
// h) Exit the program
}
void InitializeSeatingArray ()
{
// a) Initialize a two-dimensional array, representing the seats in the plane, to all empty seats
for (numOfRows = 0; numOfRows < 15; numOfRows++ )
for (numOfSeats = 0; numOfSeats < 6; numOfSeats++ )
ArrayOfSeats [numOfRows][numOfSeats] = '0';
}
void ReadAndStoreBinaryFile ()
{
/* b) If the PLANE.BIN file exists, read the data about purchased and reserved seats from the file.
First read three items (the row index, the seat index, and the seat status value) from the file.
Then use the row and seat index values to store the enumerated seat status in the correct location
in the 2D array. Continue to read three items from the file, and use them to store the seat status
in the array, until you reach the end of the file.
Be sure to read the row index, the seat index and seat status in the same order that they were
written to the file. A program's correct interpretation of the binary data is dependent upon
reading the data in the same order that it was originally written.
NOTE: After you read the data from the file, you will not be using the file again while the
user chooses seats. All modifications will be made in the 2D array. You will not access the
file again until the user chooses to exit the program.*/
}
void DisplaySeatStatus ()
{
/*c) Using the data in the array, count and display the total number of Empty, Reserved, and
Purchased seats in the entire plane to the screen.
Sample Output:
Current Status:
22 purchased seats
2 reserved seats
66 empty seats
---
90 Total
If the plane is full (i.e. there are 0 empty seats), do not display the status. Instead, the program
should just issue a "all seats on plane are full" type message and exit the program. */
}
void DisplaySeatPrefMenu ()
{
/* d) If the plane is not full, loop, letting the user reserve or purchase more seats:
i) Display a seating preference menu, prompting the user for "Window", "Middle", or "Aisle"
preference, or the user can choose "Done choosing seats" from this menu. Use mnemonic
letters as menu options (not numbers).
ii) Display all empty seats (1A, 1F, etc) of the specified type only (window, middle, or aisle).
NOTE: You may format the output however you wish, as long as it does not run off the
screen before the user can read it.
If there are zero empty seats of the specified type, tell the user, and return to the seating
preference menu. */
}
void GetAndValidateUserSeatPref ()
{
/* iii) Ask for the user's seat choice from the list of empty seats displayed.
Read and error check a row Number and a seat Letter from the user.
- Verify the row choice is in the correct range (1-15).
- Verify the seat choice matches his/her original preference (window, middle or aisle).
- Verify the row/seat choice is an empty seat
NOTES ABOUT USER INPUT:
1) The user should be able to enter row numbers as 1-15 and the seat letters A-F. And
the program should always display the rows as 1-15 and the seats as A-F.
Since the 2D array indexes begin at 0, the program should transparently (without the
user's knowledge) take care of converting the user's choices to the correct indexes in the
array, and visa versa.
2) You can make the following assumption about data entered by the user (i.e. you do
not have to error check these situations):
If you request a number, the user will enter a number.
If you request one character, the user will enter one character
iv) If seat is in range, and of the correct type and empty, ask whether to Purchase or Reserve
the requested seat. Then store RESERVED or PURCHASED in the array at the correct location.
Otherwise give an error message, telling the user why s/he cannot choose that seat (wrong type,
not empty, etc).
Continue to let the user select seats until s/he chooses "Done choosing seats" from the menu.
e) Again count and display the total number of Empty, Reserved, and Purchased seats on the whole
plane to the screen (same as (c) above). Pause until the user is done viewing the data. */
}
void SaveBinaryFile ()
{
/* f) Save the data in the array back to the PLANE.BIN file in binary format.
Store the data on the reserved and purchased seats only. This means that you will not be able
to just write the entire array out to the file at once (because that would also save data on empty
seats).
The array holds one enumerated value in each cell (EMPTY, PURCHASED, or
RESERVED). But your program will need to write out three data values for each
purchased/reserved seat (a row index, a seat index, and a seat status).
Use nested loops to examine each cell in the array. If the seat is not empty, write the data
(row index, seat index, and seat status) for that seat out to the file. Continue until all cells
have been examined.
The data should overwrite the original PLANE.BIN, if it previously existed. */
}
void DisplayEmptySeats ()
{
/*g) Finally, display all remaining empty seats to the screen (nicely formatted in 15 rows and
6 columns). Pause until the user is done viewing the data
Sample Output:
All remaining EMPTY seats:
[] 1A 1B 1C [ ] 1D 1E 1F []
[] 2A 2B 2C [ ] 2D 2E 2F []
[] [ ] []
[] 4B 4C [ ] 4D 4E 4F []
[] 5B 5C [ ] 5D 5E 5F []
[] [ ] []
[] [ ] []
[] [ ] []
[] [ ] []
[] [ ] []
[] 11A 11C [ ] 11D 11E 11F []
[] 12A 12B 12C [ ] 12D 12F []
[] 13A 13B 13C [ ] 13D 13F []
[] [ ] []
[] 15B [ ] 15E [] */
}
|