-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleAirlineSystem.cpp
More file actions
107 lines (83 loc) · 3.71 KB
/
Copy pathsimpleAirlineSystem.cpp
File metadata and controls
107 lines (83 loc) · 3.71 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
#include <iostream>
#include <string.h>
using namespace std;
void airlineSystem () {
//All of the seats in the plane array & other variable initializations//
bool seats[10] = {0,0,0,0,0,0,0,0,0,0};
int selection, seat;
int counter = 0;
//CLASS CHOICE//
reset: cout << "Please type 1 for 'first class. " << endl;
cout << "Please type 2 for 'economy'. "<< endl;
cout << "Your choice: ";
cin >> selection;
reselect: //USED TO GO BACK IF THEY DECIDE TO GO INTO OTHER CLASS WHEN ONE IS FILLED//
switch (selection) {
case 1:
for (int i = 0; i < 5; i++){
if (i == 4 && seats[i] != 0) {
//CHECKS IF THE PERSON ALREADY SWAPPED CLASSES//
if (counter == 1) {cout << "No available spaces in this plane, next one is in 3 hours."; return;}
//ALLOWS THE PERSON TO SWITCH CLASS IF NO FREE SEATS AND THEY HAVENT SWITCHED ALREADY//
cout << "No available spaces in 'first class' would you like to be placed into 'economy'? y/n: ";
char choice;
cin >> choice;
if (choice == 'y' || choice == 'Y') {selection = 2; counter = counter + 1; goto reselect;}
//CASE WHERE THEY REFUSE TO CHANGE CLASSES//
else {cout << "Next flight leaves in 3 hours."; return;}
}
//CHECKING FOR FREE SEATS IN THE SELECTED FIRST CLASS//
if (seats[i] == 0) {
seats[i] = 1;
seat = i+1;
break;
}
}
break;
case 2:
//ECONOMY CLASS/
//THIS ENTIRE THINGS WORKS THE SAME AS PREVIOUS JUST THE SWAPS ARE TO FS INSTEAD OF ECONOMY//
//I LITERALLY COPIED IT AND EDITED IT, YOU WILL LEARN THAT THIS IS 90% OF PROGRAMMING//
for (int i = 5; i < 10; i++) {
if (i == 9 && seats[i] != 0) {
if (counter == 1) {cout << "No available spaces in this plane, next one is in 3 hours."; return;}
cout << "No available spaces in 'economy' would you like to be placed into 'first class'? y/n: ";
char choice;
cin >> choice;
if (choice == 'y' || choice == 'Y') {selection = 1;counter = counter + 1; goto reselect; }
else {cout << "Next flight leaves in 3 hours."; return;}
}
if (seats[i] == 0) {
seats[i] = 1;
seat = i+1;
break;
}
}
break;
//THIS IS JUST WHEN THEY USE A NUMBER OTHER THAN 1 OR 2 FOR CLASS SELECT
default:
cout <<"Please enter an existing option!"<<endl;
goto reset;
}
//JUST A STRING FOR OUTPUT OF CLASS//
string classOfFlight;
char selection2;
//CHECKS FOR THE CLASS SO IT CAN OUTPUT IT//
if (selection == 1) classOfFlight = "First Class";
else if (selection == 2) classOfFlight = "Economy";
cout << endl;
//NEW TICKET BOOKED OUTPUT//
cout << "New ticket booked!" << endl;
cout << "Class: " << classOfFlight << endl;
cout << "Seat: " << seat << endl;
cout << endl;
//BOOK ANOTHER TICKET OPTION//
cout << "Would you like to book another ticket? y/n: ";
cin >> selection2;
if (selection2 == 'y' || selection2 == 'Y') goto reset;
else return;
}
int main() {
airlineSystem();
return 0;
}