-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.cpp
135 lines (109 loc) · 3.14 KB
/
Input.cpp
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
/****************************************************************
FILE: Input.cpp
AUTHOR: Tommy Deng
s199762338
PURPOSE: Handles getting user input for common variables.
****************************************************************/
#include "Input.h"
Input::Input()
{
}
Input::~Input()
{
}
void Input::setReservation( vector<Plane*> *plane,
int flightId,
int seatId,
string firstName,
string lastName,
string ssStreet,
string phone,
string classType,
string from,
string toCity,
string toCountry,
string drink,
string meal)
{
// assign information to objects
(*plane)[flightId]->getSeat(seatId).setPassenger(firstName, lastName, ssStreet, phone);
(*plane)[flightId]->getSeat(seatId).getPassenger().setFlightId(flightId);
(*plane)[flightId]->getSeat(seatId).getPassenger().setSeatId(seatId);
(*plane)[flightId]->getSeat(seatId).setReserved(true);
if (classType == "E")
{
(*plane)[flightId]->getSeat(seatId).getPassenger().getEconomy().setHasEcon(true);
(*plane)[flightId]->getSeat(seatId).getPassenger().getEconomy().setFrom(from);
(*plane)[flightId]->getSeat(seatId).getPassenger().getEconomy().setToCity(toCity);
(*plane)[flightId]->getSeat(seatId).getPassenger().getEconomy().setToCountry(toCountry);
}
else if (classType == "B")
{
(*plane)[flightId]->getSeat(seatId).getPassenger().getBusiness().setHasBus(true);
(*plane)[flightId]->getSeat(seatId).getPassenger().getBusiness().setFrom(from);
(*plane)[flightId]->getSeat(seatId).getPassenger().getBusiness().setToCity(toCity);
(*plane)[flightId]->getSeat(seatId).getPassenger().getBusiness().setToCountry(toCountry);
(*plane)[flightId]->getSeat(seatId).getPassenger().getBusiness().setDrink(drink);
(*plane)[flightId]->getSeat(seatId).getPassenger().getBusiness().setMeal(meal);
}
}
int Input::flightId(int numPlanes)
{
int flightId;
cout << "Flight number: ";
cin >> flightId;
while (flightId < 0 || flightId > numPlanes - 1)
{
cout << "Invalid input. Enter numbers 0 to " << numPlanes - 1 << endl;
cin >> flightId;
}
return flightId;
}
int Input::seatId(const vector<Plane*>* plane, int flightId)
{
int seatId;
cout << "Seat number: ";
cin >> seatId;
while (seatId < 0 || seatId >(*plane)[flightId]->getNumOfSeats() - 1)
{
cout << "Invalid input. Enter numbers 0 to " << (*plane)[flightId]->getNumOfSeats() - 1 << endl;
cin >> seatId;
}
return seatId;
}
string Input::drink()
{
string drink;
cout << "Preferred drink: ";
cin >> drink;
return drink;
}
string Input::meal()
{
string meal;
cout << "Preferred meal: ";
cin >> meal;
return meal;
}
string Input::boardingPass()
{
string classType;
cin >> classType;
while (classType != "E" && classType != "B")
{
cout << "Invalid input. Enter letters \"E\" or \"B\"" << endl;
cin >> classType;
}
return classType;
}
int Input::destinationChoice(int numPlanes)
{
int destinationChoice;
cin >> destinationChoice;
while (destinationChoice < 1 || destinationChoice > numPlanes)
{
cout << "Invalid input. Select destinations from 1 to " << numPlanes << endl;
cin >> destinationChoice;
}
return destinationChoice;
}