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
|
#include <iostream>
#include <iomanip>
using namespace std;
const int ROWS = 7;
const int COLUMNS = 4;
int main()
{
int i, j;
char arraySeats[ROWS][COLUMNS] =
{
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'}
};
for (i = 0; i < ROWS; i++)
{
for (j = 0; j < COLUMNS; j++)
{
cout << setw(5) << arraySeats[i][j] << " ";
}
cout << endl;
}
char again;
do
{
int row;
char seat;
while(true)
{
cout << "\nEnter a row 1-7 : ";
if(cin >> row && row >= 1 && row <= 7) {row--; break;}
if(!cin)
{
cin.clear();
cin.ignore(1000, '\n');
}
}
while(true)
{
cout << "Enter a seat, A, B, C, or D : ";
cin >> seat;
if(seat >= 'A' && seat <= 'D') {seat = seat - 'A'; break;}
if(seat >= 'a' && seat <= 'd') {seat = seat - 'd'; break;}
}
if (arraySeats[row][seat] == 'X')
{
cout << "\nThat seat is taken. Pick another." << endl;
}
else
{
cout << "Seat " << row + 1 << (char)(seat + 'A') << " is now claimed." << endl;
arraySeats[row][seat] = 'X';
}
for (i = 0; i < ROWS; i++)
{
for (j = 0; j < COLUMNS; j++)
{
cout << setw(5) << arraySeats[i][j] << " ";
}
cout << endl;
}
cout << "\nAgain? (Y or y to continue) : ";
cin >> again;
} while (again == 'Y' || again == 'y');
return 0;
}
|