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
|
#include<iostream>
#include <sstream>
#include <locale>
const int MAX_ROWS = 7, MAX_SEATS = 4;
void initialize_seating(char seating[][MAX_SEATS],
int total_rows, int total_seats);
void display_seating(char seating[][MAX_SEATS],
int total_rows, int total_seats);
void new_line();
//subtract from again loop //
using namespace std;
int main ()
{
char seating[MAX_ROWS][MAX_SEATS];
int row, i, j;
char seat;
char again; // ask if User would like to choose additional seats //
char happy; // check if happy with initial seat selection//
initialize_seating(seating, MAX_ROWS, MAX_SEATS);
display_seating(seating, MAX_ROWS, MAX_SEATS);
do {
do {
do {
cout << "Enter a Row (1-7) you wish to sit: \n>" ;
cin >> row;
while (cin.fail())
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please enter a number. \n" ;
}
} while (row!=1&&row!=2&&row!=3&&row!=4&&row!=5&&row!=6&&row!=7);
do {
cout << "Now Enter the seat (A-D) you wish to sit: \n>";
cin >> seat;
if (islower(seat))
seat = toupper(seat);
} while (seat!='A'&&seat!='B'&&seat!='C'&&seat!='D');
cout << "You chose " << row << seat << endl;
cout << "Are you happy with your selection? \n>";
cin >> happy;
new_line();
} while (happy != 'Y' && happy != 'y');
i = row - 1;
j = toupper(seat) - toupper('A');
seating[i][j] = 'X';
display_seating(seating, MAX_ROWS, MAX_SEATS);
//if (i >= MAX_ROWS && j >= MAX_SEATS)
if (seating[i][j] == 'X')
{
cout << "All seats are now booked.\n" ;
cin.get();
return 0;
}
cout << "Would you like to reserve another seat? \n>" ;
cin >> again ;
new_line();
}while (again != 'N' && again != 'n');
cin.get();
///return 0;
}
void display_seating(char seating[][MAX_SEATS],
int total_rows, int total_seats)
{
for(int i = 0; i < total_rows; i++)
{
cout << i+1;
for(int j = 0; j < total_seats; j++)
{
cout << seating[i][j];
}
cout << endl;
}
}
void initialize_seating(char seating[][MAX_SEATS],
int total_rows, int total_seats)
{
for(int i = 0; i < total_rows; i++)
{
for(int j = 0; j < total_seats; j++)
{
seating[i][j] = static_cast<char>(toupper('A') + j);
}
}
}
void new_line()
{
char symbol;
do
{
cin.get(symbol);
} while (symbol != '\n');
}
|