-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPLD_FinalProject - Airplane Seating Assignment.cpp
More file actions
177 lines (159 loc) · 4.68 KB
/
PLD_FinalProject - Airplane Seating Assignment.cpp
File metadata and controls
177 lines (159 loc) · 4.68 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <iostream>
/*
Created by Theron Adrianne Bueno
February 7, 2021
Subject: Programming Logic and Design (CPE 0112.1) - Pamantasan ng Lungsod ng Maynila (PLM)
Task: Final Project: (Airplane Seating Assignment) Write a program that can be used to
assign seats for a commercial airplane. The airplane has 13 rows, with six
seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business
class, and rows 8 through 13 are economy class. program must prompt the user to enter the following information:
a. Ticket type (first class, business class, or economy class)
b. Desired seat
*/
using namespace std;
const int rows = 13; //Rows 1 to 13 in the Table
const int columns = 6;// Columns A to F in the Table
char classType; // Ticket type (first class, business class, or economy class)
int rowNumber, Pcolumn;
char column, choice;
char seats[rows][columns];
//function prototypes
void showstatus();
void seatAllocate();
int main()
{
cout << "\n\n\tProgram: Airplane Seating Assignment\n\n";
//initialize seats
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
seats[i][j] = '*';
}
}
do
{
showstatus();
cout << "\n";
cout << "\nChoose the ticket type you want to reserve a seat?\n" << endl;
cout << "Enter (F/f) for First Class" << endl;
cout << "Enter (B/b) for Business Class" << endl;
cout << "Enter (E/e) for Economy Class\n" << endl;
cout << "Choose Ticket Type: ";
cin >> classType;
switch (classType)
{
case 'F':
case 'f':
{
cout << "Choose row (1 or 2): ";
cin >> rowNumber;
if (rowNumber == 1 || rowNumber == 2)
{
cout << "Choose which Column(A-F): ";
cin >> column;
column = tolower(column);
seatAllocate();
showstatus();
}
else
{
cout << "Invalid row number for First class seat";
}
break;
}
//Business Class
case 'B':
case 'b':
{
cout << "\nChoose row (3 to 7): ";
cin >> rowNumber;
if (rowNumber == 3 || rowNumber == 4 || rowNumber == 5 || rowNumber == 6 || rowNumber == 7)
{
cout <<"\nChoose which Column(A-F)";
cin >> column;
column = tolower(column);
seatAllocate();
showstatus();
}
else
{
cout << "Invalid row number for business class seat";
}
}
break;
//Economy class:
case 'E':
case 'e':
{
cout << "\nChoose row (8 to 13): ";
cin >> rowNumber;
if (rowNumber == 8 || rowNumber == 9 || rowNumber == 10 || rowNumber == 11 || rowNumber == 12 || rowNumber == 13)
{
cout << "\nChoose which Column(A-F)";
cin >> column;
column = tolower(column);
seatAllocate();
showstatus();
}
else
{
cout << "\n Invalid row number for Economy class";
}
break;
}
default:
{
cout << "\nInvalid class type" << endl;
exit(0);
}
}
cout << "\n\n Do you want to reserve more seats? (Y/N): ";
cin >> choice;
if (choice != 'n')
{
system("cls");
cout << "\n\n\tProgram: Airplane Seating Assignment\n\n";
}
}
while (tolower(choice) != 'n');
return 0;
}
//function to show the current status of the seats, which is * or X
void showstatus()
{
cout << "\n\t\tA\tB\tC\tD\tE\tF";
for (int i = 0; i < rows; i++)
{
cout << "\n\tRow " << (i + 1);
for (int j = 0; j < columns; j++)
cout << "\t" << seats[i][j];
}
}
void seatAllocate()
{
Pcolumn = static_cast<int>(tolower(column) - 97); //To make sure value is between 0 and 5 which is equal to columns A to F
if (Pcolumn<0 || Pcolumn>columns)
{
cout << "Invalid Column" << endl;
exit(0);
}
else
{
if (seats[rowNumber-1][Pcolumn] == 'X')
{
cout << "\n\n\tAlready reserved. Please select other seats.";
}
else
{
cout << "\n\tSeat reserved succesfully!\n\n";
}
for (int i = 0; i < rowNumber; i++)
{
for (int j = 0; j <= Pcolumn; j++)
{
seats[rowNumber-1][Pcolumn] = 'X';
}
}
}
}