-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
108 lines (88 loc) · 3.22 KB
/
main.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
//main.cpp - Handles user interaction
// and uses the modularized functions from trip.h, BudgetUtils.h, FileUtils.h, DateUtils.h
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include "DateUtils.h"
#include "BudgetUtils.h"
#include "FileUtils.h"
using namespace std;
int main() {
vector<tuple<string, string, double>> trips;
string destination, travelDate;
double budget;
char addMore;
// Load previously saved trips
loadTrips(trips);
cout << "Welcome to the AI Travel Planner Project, WIP, stay-tuned!" << endl;
// Display previously loaded trips
if (!trips.empty()) {
cout << "\nPreviously Saved Trips:\n";
for (size_t i = 0; i < trips.size(); ++i) {
cout << "Trip " << (i + 1) << ": "
<< "Destination: " << get<0>(trips[i]) << ", "
<< "Date: " << get<1>(trips[i]) << ", "
<< "Budget: INR " << get<2>(trips[i]) << endl;
}
}
do {
// Take input for destination
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "\nEnter your Travel Destination: ";
getline(cin, destination);
// Input and validate travel date
bool validDate = false;
do {
cout << "Enter your travel date in format DD/MM/YYYY: ";
getline(cin, travelDate);
if (!validateDate(travelDate)) {
cout << "Invalid date format! Please try again.\n";
}
else {
validDate = true;
}
} while (!validDate);
// Input and validate budget
bool validBudget = false;
do {
cout << "Enter your Budget (in INR): ";
cin >> budget;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
if (!validateBudget(budget)) {
cout << "Invalid budget! Please enter a positive value.\n";
}
else {
validBudget = true;
}
} while (!validBudget);
// Confirm trip details before saving
char confirm;
cout << "\nPlease review your trip details:" << endl;
cout << "Destination: " << destination << endl;
cout << "Travel Date: " << travelDate << endl;
cout << "Budget: INR " << fixed << setprecision(2) << budget << endl;
char confirm;
cout << "Are these details correct? (y/n): ";
cin >> confirm;
if (confirm == 'y' || confirm == 'Y') {
trips.push_back(make_tuple(destination, travelDate, budget));
cout << "\nTrip added successfully!" << endl;
}
cout << "Do you want to add another trip? (y/n): ";
cin >> addMore;
} while (addMore == 'y' || addMore == 'Y');
cout << "\nSummary of Your Planned Trips\n";
for (size_t i = 0; i < trips.size(); ++i) {
cout << "Trip " << (i + 1) << ": "
<< "Destination: " << get<0>(trips[i]) << ", "
<< "Date: " << get<1>(trips[i]) << ", "
<< "Budget: INR " << get<2>(trips[i]) << endl;
}
saveTrips(trips);
cout << "\nPress Enter to exit...";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
return 0;
}