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
|
//Airplane seat assignment
#include <iostream>
#include <cmath>
const int MAX_ROW = 8;//this translates to 7 since row-1 is used for the printing of the table
const int MAX_SEAT = 4;
void display_seating(char a[][MAX_SEAT], int rows);
void seat_availability(char a[][MAX_SEAT], int rows);
bool assign_seat(char a[][MAX_SEAT], int rows, int row, int col);
int main()
{
using namespace std;
int row, col;
int input_row;
char input_seat;
char seat[MAX_ROW][MAX_SEAT], ans;
for(row = 0; row < MAX_ROW; row++)
for(col = 0; col < MAX_SEAT; col++)seat[row][col] = static_cast<char>(toupper('A') + col);
display_seating(seat,MAX_ROW);
cout << "\nWelcome to the airline seating reservation system!\n"
<< "Please choose a row and seat that you would like to "
<< "\nsit in from the above seating chart.";
do
{
seat_availability(seat,MAX_SEAT);
cout << " \n\nEnter 1-7 for the row and "
<< "\neither 'A', 'B', 'C', or 'D' for the seat selection: ";
cin >> input_row >> input_seat;
col = toupper(input_seat) - toupper('A');
input_seat = col;
// Check to see if seat is taken
if (seat[input_row-1][col] == 'X')
cout << "\nSorry, " << input_row << static_cast<char>(toupper('A') + col) << " is already taken.\n" << endl;
else
{
cout << "\nOK, you've got " << input_row << static_cast<char>(toupper('A') + col) << endl << endl;
seat[input_row-1][col]='X';
}
//now input an 'X' for the seat taken
display_seating(seat,MAX_ROW);
cout << "\nWould you like to enter another reservation?";
cin >> ans;
}while (ans == 'Y' || ans == 'y');
return 0;
}
void display_seating(char a[][MAX_SEAT], int rows)
{
using namespace std;
for(int row = 1; row < rows; row++)
{
cout << "\t" << "\t" <<row;
for(int col = 0; col < MAX_SEAT; col++)
{
//I subtracted 1 from row to match row to the index
cout << a[row-1][col];
}
cout << endl;
}
}
void seat_availability(char a[][MAX_SEAT], int rows)
{
using namespace std;
for(int row = 1; row < rows; row++)
for(int col = 0; col < MAX_SEAT; col++);
// if my target array does not have an 'X' in it
if (a[][MAX_SEAT] != 'X')
{
// do nothing
;
}else
cout << "The plane is full please try a different airline";
}
| |