-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.cpp
More file actions
159 lines (140 loc) · 5.5 KB
/
Copy pathInterface.cpp
File metadata and controls
159 lines (140 loc) · 5.5 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
#include "metro.hpp"
// ---------------------------------------------------------
// Core globals (original)
// ---------------------------------------------------------
map<int, double> mp;
vector<string> search_history;
int total_fare_collected = 0;
// ---------------------------------------------------------
// NEW globals for this feature set
// ---------------------------------------------------------
map<string, double> smartcard_balances;
map<string, ActiveJourney> active_journeys;
StationAmenities station_amenities[57];
vector<TicketRecord> ticket_log;
int tickets_sold_count = 0;
map<string, int> route_popularity;
string getCurrentTime() {
time_t now = time(0);
tm *ltm = localtime(&now);
char buffer[80];
strftime(buffer, sizeof(buffer), "%I:%M %p", ltm);
return string(buffer);
}
string getArrivalTime(int travel_time_mins) {
time_t now = time(0);
now += (travel_time_mins * 60);
tm *ltm = localtime(&now);
char buffer[80];
strftime(buffer, sizeof(buffer), "%I:%M %p", ltm);
return string(buffer);
}
double getETA(double distance_km, int stops) {
return (distance_km * 1.5) + (stops * 0.5);
}
// Official HMRL fare slabs (revised chart effective 24 May 2025).
// Source-verified: Rs.11 (<=2km), 17 (2-4km), 28 (4-6km), 37 (6-9km),
// 47 (9-12km), 51 (12-15km), 56 (15-18km), 61 (18-21km), 65 (21-24km),
// 69 (beyond 24km).
int getFare(double distance_km) {
if (distance_km <= 2.0) return 11;
if (distance_km <= 4.0) return 17;
if (distance_km <= 6.0) return 28;
if (distance_km <= 9.0) return 37;
if (distance_km <= 12.0) return 47;
if (distance_km <= 15.0) return 51;
if (distance_km <= 18.0) return 56;
if (distance_km <= 21.0) return 61;
if (distance_km <= 24.0) return 65;
return 69;
}
int levenshteinDist(string word1, string word2) {
int m = word1.length(), n = word2.length();
vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= m; i++) dp[i][0] = i;
for (int j = 1; j <= n; j++) dp[0][j] = j;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (word1[i - 1] == word2[j - 1]) dp[i][j] = dp[i - 1][j - 1];
else dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;
}
}
return dp[m][n];
}
static string toLowerCopy(const string& s) {
string out = s;
transform(out.begin(), out.end(), out.begin(), [](unsigned char c){ return tolower(c); });
return out;
}
bool validateStation(string& stationName) {
if (code.count(stationName)) return true;
// Case-insensitive exact match before falling back to fuzzy matching.
string lowerInput = toLowerCopy(stationName);
for (auto const& pair : code) {
if (toLowerCopy(pair.first) == lowerInput) {
stationName = pair.first;
return true;
}
}
int minDist = INF;
string closest = "";
for (auto const& pair : code) {
int dist = levenshteinDist(stationName, pair.first);
if (dist < minDist) { minDist = dist; closest = pair.first; }
}
cout << RED_COL << "!! Station '" << stationName << "' doesn't exist !!" << RESET << "\n";
cout << "Did you mean '" << YEL_COL << closest << RESET << "'? (y/n): ";
char ch; cin >> ch;
if (ch == 'y' || ch == 'Y') { stationName = closest; return true; }
return false;
}
void printRoute(vector<int> path) {
cout << "\n~~ Route Map :\n\n";
for (size_t i = 0; i < path.size(); i++) {
string currentLine = getLine(path[i]);
if (currentLine == "RED Line") cout << RED_COL;
else if (currentLine == "GREEN Line") cout << GRN_COL;
else if (currentLine == "BLUE Line") cout << BLU_COL;
cout << stations[path[i]] << RESET;
if (i == path.size() - 1) {
char gate = 'A' + (path[i] % 4);
cout << MAG_COL << " [EXIT GATE " << gate << "]" << RESET;
}
if (i < path.size() - 1) {
string nextLine = getLine(path[i+1]);
if (currentLine != nextLine) {
cout << YEL_COL << "\n |\n +--> [TRANSFER TO " << nextLine << "]\n |\n" << RESET;
} else {
cout << " --> ";
}
}
}
cout << "\n\n";
}
void generateTicket(string src, string dst, double distance, int stops, int eta_mins, vector<int> path) {
ofstream ticket("ticket.txt");
if (!ticket) return;
int fare = getFare(distance);
total_fare_collected += fare;
ticket << "======================================\n";
ticket << " HYDERABAD METRO TICKET \n";
ticket << "======================================\n";
ticket << "FROM: " << src << "\nTO: " << dst << "\n";
ticket << "--------------------------------------\n";
ticket << "Departs: " << getCurrentTime() << "\n";
ticket << "Arrives: " << getArrivalTime(eta_mins) << "\n";
ticket << fixed << setprecision(2);
ticket << "Distance: " << distance << " km (" << stops << " stops)\n";
ticket << "Fare: Rs. " << fare << "\n";
ticket << "--------------------------------------\nROUTE:\n";
for (size_t i = 0; i < path.size(); i++) {
ticket << stations[path[i]];
if (i < path.size() - 1) {
if (getLine(path[i]) != getLine(path[i+1])) ticket << " [CHANGE TO " << getLine(path[i+1]) << "]";
ticket << " -> ";
}
}
ticket << "\n======================================\n";
ticket.close();
cout << YEL_COL << "[SUCCESS] Ticket printed to 'ticket.txt'!" << RESET << "\n";
}