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
|
//Airplane seat assignment
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
typedef char* charArray;
typedef charArray* char2Array;
char again;
void check_row(int& input_row);
void check_seat(char& input_seat, int& col);
void display_seating(char2Array a, int rows, int seats);
//void assign_seat(char2Array a, int rows, int row, int col, char& valid);
int main()
{
using namespace std;
int row, col;
int input_row;
char valid = 'T';
char input_seat;
int rows, seats;
cout << "Please list the number of rows the plane has: ";
cin >> rows;
cout << "Seats in each row: ";
cin >> seats;
charArray *seat = new charArray[rows];
for(row = 0; row < rows; row++)
seat[row] = new char[seats];
for(row = 0; row < rows; row++)
for(col = 0; col < seats; col++)
seat[row][col] = static_cast<char>(toupper('A') + col);
do
{
cout << endl;
display_seating(seat,rows,seats);
cout << "\nPlease select a seating assignment from the seating arrangement displayed above."
<< "Enter the numeric row number"
<< " followed by the letter of your seat choice: ";
cin >> input_row >> input_seat;
col = toupper(input_seat) - toupper('A');
do
{
//check_row(input_row);
if (seat[input_row][col] == 'X')
{
cout << "\nYou chose: "<< input_row << static_cast<char>(toupper('A') + col) << " which was reserved by another customer.";
valid = 'F';
}
else
{
seat[input_row][col] = 'X';
cout << "\nYou successfully reserved seat: " << input_row << static_cast<char>(toupper('A') + col) << " Thank you for flying with Argyle Express.";
valid = 'T';
}
}while (valid = 0);
cout << "\nWould you like to make another reservation?";
cin >> again;
}while (again != 'N' || again != 'n');
return 0;
}
void display_seating(char2Array a, int rows, int seats)
{
using namespace std;
for(int row = 0; row < rows; row++)
{
cout << row;
for(int col = 0; col < seats; col++)
{
cout << a[row][col];
}
cout << endl;
}
}
void assign_seat(char2Array a, int rows, int row, int col, char& valid)
{
using namespace std;
// if the chosen seat has a x in it, then the seat is not valid
if (a[row][col] == 'X')
{
valid = 'F';
}
else //The seat is valid and will become reserved by placing a x in it
{
a[row][col] = 'X';
valid = 'T';
}
}
void check_row(int& input_row)
{
if (input_row < 0 || input_row > input_row -1 || input_row != isdigit(input_row))
cout << "The row you selected is not available.";
return;
}
void check_seat(char& input_seat, int& col)
{
// This function checks to make sure the input is within the acceptable range for 'row' and 'col'
using namespace std;
if (!isalpha(input_seat))
cout << "You must select a letter";
if ((col < 'a' || col > input_seat) || (col < 'A' || col > input_seat ))
cout << "You chose seat " << static_cast<char>(toupper('A') + col) << " but must choose a seat \n "
<< "that is between A and " << static_cast<char>(toupper('A') + col);
}
| |