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
|
#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;
cout << "Welcome to my system..."
<< "\nHere is all available seat to choose" << endl << endl;
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 << " \nInstruction: "
<< "\n Please press row number, press space bar and press seat number. "
<< "\n\n X mean the seat is not available " << endl;
do
{
seat_availability(seat,MAX_SEAT);
cout << "\nPlease choose your seat: ";
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 << "\nSeat is not available" << endl;
else
{
cout << "\nLatest available seat to choose " << endl << endl;
seat[input_row-1][col]='X';
//now input an 'X' for the seat taken
display_seating(seat,MAX_ROW);
}
cout << "\nBook another seat?(y/n): ";
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 << 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[row-1][MAX_SEAT] != 'X')
{
// do nothing
;
}else
cout << "The seats are full! please try a different one";
}
|