-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_view.h
More file actions
215 lines (169 loc) · 5.52 KB
/
customer_view.h
File metadata and controls
215 lines (169 loc) · 5.52 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// Created by hussein on 8/2/22.
//
#ifndef EXPEDIA_COM_CUSTOMER_VIEW_H
#define EXPEDIA_COM_CUSTOMER_VIEW_H
using namespace std;
#include "customer_mgr.h"
class CustomerView {
private:
CustomerManager &customer_manager;
const Customer & customer;
ItineraryReservation current_itinerary;
// reading a flight request from user
void ReadFlightRequest(FlightRequest &request) const {
string str;
int val;
cout << "Enter From: ";
cin >> str;
request.SetFrom(str);
cout << "Enter From Date (dd-mm-yy): ";
cin >> str;
request.SetDatetimeFrom(str);
cout << "Enter To: ";
cin >> str;
request.SetTo(str);
cout << "Enter To Date (dd-mm-yy): ";
cin >> str;
request.SetDatetimeTo(str);
cout << "Enter # of adults children (5-16) and infants: ";
cin >> val;
request.SetAdults(val);
cin >> val;
request.SetChildren(val);
cin >> val;
request.SetInfants(val);
}
// reading a hotel request from user
void ReadHotelRequest(HotelRequest &request) const {
string str;
int val;
cout << "Enter From Date (dd-mm-yy): ";
cin >> str;
request.SetFromDate(str);
cout << "Enter From Date (dd-mm-yy): ";
cin >> str;
request.SetToDate(str);
cout << "Enter Country: ";
cin >> str;
request.SetCountry(str);
cout << "Enter City: ";
cin >> str;
request.SetCity(str);
cout << "Enter # of adults and children: ";
cin >> val;
request.SetAdults(val);
cin >> val;
request.SetChildren(val);
}
int ChooseFlight(const vector<Flight> &flights) const {
if(flights.size() == 0) {
cout << "No trips for this request info" << endl;
return -1;
}
for(const Flight& flight : flights) {
cout << flight.ToString() << "\n";
}
return ReadInt(1, flights.size(), true);
}
int ChooseRoom(const vector<HotelRoom> &rooms) const {
if(rooms.size() == 0) {
cout << "No rooms for this request info" << endl;
return -1;
}
for(const HotelRoom& room : rooms) {
cout << room.ToString() << "\n";
}
return ReadInt(1, rooms.size(), true);
}
void AddFlight() {
FlightRequest request;
ReadFlightRequest(request);
vector<Flight> flights = customer_manager.FindFlights(request);
int fight_choice = ChooseFlight(flights);
if(fight_choice == -1)
return;
Flight &flight = flights[fight_choice - 1];
FlightReservation reservation(request, flight);
current_itinerary.AddReservation(reservation);
}
void AddHotel() {
HotelRequest request;
ReadHotelRequest(request);
vector<HotelRoom> rooms = customer_manager.FindHotels(request);
int hotel_choice = ChooseRoom(rooms);
if (hotel_choice == -1)
return;
HotelRoom &room = rooms[hotel_choice - 1];
HotelReservation reservation(request, room);
current_itinerary.AddReservation(reservation);
}
void PayItinerary() {
vector<string> payment_choices = customer_manager.GetPaymentChoices();
int payment_choice = ShowReadMenu(payment_choices, "Select a payment choice");
PaymentCard* payment_card = customer.GetCards()[payment_choice - 1];
bool status = customer_manager.MakeReservation(current_itinerary, *payment_card);
if (status) {
cout << "Itinerary reserved\n";
} else
cout << "Failed to reserve the Itinerary\n";
}
public:
// constructor with initializer list
CustomerView(CustomerManager &customer_manager) :
customer_manager(customer_manager), customer(*customer_manager.GetCustomer()) {
}
void Display() {
cout << "\n\nHello " << customer.GetName() << " | User View\n";
vector<string> menu;
menu.push_back("View Profile");
menu.push_back("Make Itinerary");
menu.push_back("List my itineraries");
menu.push_back("Logout");
while (true) {
int choice = ShowReadMenu(menu);
if (choice == 1)
ViewProfile();
else if (choice == 2)
MakeItinerary();
else if (choice == 3)
ListItineraries();
else
break;
}
}
void ViewProfile() const {
cout << "\n" << customer.ToString() << "\n";
}
void MakeItinerary() {
vector<string> menu;
menu.push_back("Add Flight");
menu.push_back("Add Hotel");
menu.push_back("Done");
menu.push_back("Cancel");
while (true) {
int choice = ShowReadMenu(menu);
if (choice == 1)
AddFlight();
else if (choice == 2)
AddHotel();
else if (choice == 3) {
PayItinerary();
current_itinerary.Clear();
break;
} else {
current_itinerary.Clear();
break;
}
}
}
void ListItineraries() const {
vector<string> itineraries = customer_manager.GetItineraries();
if (itineraries.size() == 0) {
cout << "No itineraries so far!\n";
}
for (string& str : itineraries)
cout << str << "\n";
}
};
#endif //EXPEDIA_COM_CUSTOMER_VIEW_H