-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReservationList.cpp
More file actions
221 lines (163 loc) · 5.05 KB
/
Copy pathReservationList.cpp
File metadata and controls
221 lines (163 loc) · 5.05 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
216
217
218
219
220
221
#include "ReservationList.h"
ReservationList::ReservationList(string resFile)
{
loadReservations(resFile);
}
void ReservationList::loadReservations(string resFile)
{
int reservationID;
int guestID;
int roomID;
int checkInDate;
int checkOutDate;
int numberOfGuests;
int reservationDate;
string status; // Booked, Cancelled, Pending Booking
int totalPrice; // whole number
string paymentStatus; // Payment Received, Pending Payment, No Payment
string specialRequests;
string specialDiscount; // military, AAA, None
ifstream inFile(resFile);
if (!inFile) {
cerr << "Error opening file: " << resFile << "\n";
return;
}
// Read file logic
string line_input;
while (getline(inFile, line_input))
{
// filter out white space
if (line_input.empty())
continue;
// filter out comments
if (!line_input.empty() && line_input.at(0) == '#')
continue;
// get reservation info from reservationHistory.txt
stringstream ss(line_input);
string token;
getline(ss, token, ',');
reservationID = stoi(token); // reservation ID
getline(ss, token, ',');
guestID = stoi(token); // guest ID
getline(ss, token, ',');
roomID = stoi(token); // room ID
getline(ss, token, ',');
checkInDate = stoi(token); // check in date
getline(ss, token, ',');
checkOutDate = stoi(token); // check out date
getline(ss, token, ',');
numberOfGuests = stoi(token); //number of guests
getline(ss, token, ',');
reservationDate = stoi(token); // date of reservation
getline(ss, token, ',');
status = token; // status of reservation
getline(ss, token, ',');
totalPrice = stoi(token); // total price of reservation
getline(ss, token, ',');
paymentStatus = token; // payment status
getline(ss, token, ',');
specialRequests = token; //any special requestions for reservation
getline(ss, token, ',');
specialDiscount = token; //special discounts
// Create Reservation
Discount newDiscount = discountType(specialDiscount);
Reservation newRes;
newRes.makeReservation(reservationID, guestID, roomID, checkInDate, checkOutDate, numberOfGuests,
reservationDate, specialRequests, newDiscount);
newRes.setTotalPrice(totalPrice);
reservationList.push_back(newRes);
}
// make sure you close
inFile.close();
}
void ReservationList::saveReservation(Reservation res)
{
ofstream outFile("reservationHistory.txt", ios::app);
int reservationID = res.getReservationID();
int guestID = res.getGuestID();
int roomID = res.getRoomID();
int checkInDate = convertDatetoInt(res.getCheckInDate());
int checkOutDate = convertDatetoInt(res.getCheckOutDate());
int numberOfGuests = res.getNumberOfGuests();
int reservationDate = convertDatetoInt(res.getReservationDate());
string status = res.getStatus(); // Booked, Cancelled, Pending Booking
int totalPrice = res.getTotalPrice(); // whole number
string paymentStatus = res.getPaymentStatus(); // Payment Received, Pending Payment, No Payment
string specialRequests = res.getSpecialRequests();
string specialDiscount = res.getSpecialDiscount().getDiscountName(); // military, AAA, None
outFile << endl;
outFile << reservationID << ",";
outFile << guestID << ",";
outFile << roomID << ",";
outFile << checkInDate << ",";
outFile << checkOutDate << ",";
outFile << numberOfGuests << ",";
outFile << reservationDate << ",";
outFile << status << ",";
outFile << totalPrice << ",";
outFile << paymentStatus << ",";
outFile << specialRequests << ",";
outFile << specialDiscount << endl;
outFile.close();
}
int ReservationList::convertDatetoInt(string date)
{
int year = stoi(date.substr(0, 4));
int month = stoi(date.substr(5, 2));
int day = stoi(date.substr(8, 2));
int numericDate = year * 10000 + month * 100 + day;
return numericDate;
}
void ReservationList::addReservation(const Reservation& r)
{
reservationList.push_back(r);
saveReservation(r);
}
void ReservationList::printReservationList()
{
for (int i = 0; i < reservationList.size(); i++)
{
cout << "Reservation #: " << reservationList.at(i).getReservationID();
cout << endl;
}
}
vector<Reservation> ReservationList::getReservationList() const
{
return reservationList;
}
int ReservationList::getReservationListSize() const
{
return reservationList.size();
}
Reservation ReservationList::getReservation(int resID)
{
for (int i = 0; i < reservationList.size(); i++)
{
if (reservationList.at(i).getReservationID() == resID)
{
return reservationList.at(i);
}
}
}
Discount ReservationList::discountType(string type)
{
float rate;
if (type == "military")
{
rate = 0.10;
return Discount(rate, "military");
}
if (type == "AAA")
{
rate = 0.25;
return Discount(rate, "AAA");
}
return Discount(0, "None");
}
void ReservationList::printAllReservations()
{
for (const Reservation& res : reservationList)
{
cout << res.getReceipt() << endl;
}
}