-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
198 lines (159 loc) · 6.93 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
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
#include "SeparateChaining.h"
#include "LinearProbing.h"
#include <fstream>
#include <sstream>
#include <limits>
using namespace std;
int main() {
// Create two hash maps, one for rain data, and one for temperature data
chainingHashMap mapA(1000);
linearHashMap mapB(1000);
string line;
// Open the weather.csv file
ifstream file("weather.csv");
if (file.is_open()) {
while(getline(file, line)){ // Read each line from the file
stringstream ss(line);
string token;
vector<string> row;
// Break each line into tokens separated by commas
while (std::getline(ss, token, ',')) {
// Remove double quotes from the token if they exist
if (token.front() == '"' && token.back() == '"')
token = token.substr(1, token.size() - 2);
// Add each token to the row vector
row.push_back(token);
}
if (row.size() < 15) { // Change the number to match your column count
continue; // Skip this iteration of the loop if the row is too short
}
// Parse the needed values from each row
string precipitation = row[0]; //0: precipitation
string dateFull = row[1]; //1: dateFull
string city = row[5]; //5:city
string maxTemp = row[11]; //10:max temp
string minTemp = row[12]; //11: min temp
string windSpeed = row[14]; //13: wind speed
// the rows are off becuase theres a comma in row 8 that extends the row value by 1 after it
// Insert parsed values into the hash maps
mapA.insert(dateFull + city, precipitation, windSpeed);
mapB.insert(dateFull + city, minTemp, maxTemp);
}
file.close();
}
else {
cout << "Unable to open the file." << endl;
return 1;
}
bool interface = true;
while(interface){ // Interface loop
string input;
string date;
string city;
cout << " Welcome to the Weather Almanac " << endl
<< "--------------------------------" << endl
<< "1. Insert your own findings" << endl
<< "2. Remove errors found in data" << endl
<< "3. Find recorded temperatures" << endl
<< "4. Find recorded downpours" << endl
<< "5. Exit" << endl
<< "--------------------------------" << endl;
cin >> input;
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Clear the input buffer
cout << endl;
if (input == "1"){ // If the user chooses to insert their own findings
string choice;
cout << "rain or temp" << endl;
getline(cin, choice);
// Get the date and city for the data the user wants to insert
cout << "Enter the Full Date (YYYY-MM-DD)" << endl;
getline(cin, date);
cout << "Enter the Specific city" << endl;
getline(cin, city);
string key = date + city;
if(choice == "rain"){ // If the user is inserting rain data
string precipitation;
string windSpeed;
cout << "Enter precipitation: ";
getline(cin, precipitation);
cout << "Enter wind speed: ";
getline(cin, windSpeed);
mapA.insert(key, precipitation, windSpeed);
}
else if(choice == "temp"){ // If the user is inserting temperature data
string minTemp;
string maxTemp;
cout << "Enter minimum temperature: ";
getline(cin, minTemp);
cout << "Enter maximum temperature: ";
getline(cin, maxTemp);
// Insert the data into the temperature data hash map
mapB.insert(key, minTemp, maxTemp);
cout << "Data inserted!" << endl;
}
cout << endl;
}
if (input == "2") { // If the user chooses to remove data
cout << "Enter the Full Date (YYYY-MM-DD)" << endl;
getline(cin, date);
cout << "Enter the Specific city" << endl;
getline(cin, city);
string key = date + city;
mapA.remove(key);
mapB.remove(key);
cout << endl;
cout << "Data removed successfully." << endl;
cout << endl;
cout << endl;
}
if (input == "3") { // If the user chooses to find temperature data
cout << "Enter the Full Date (YYYY-MM-DD)" << endl;
getline(cin, date);
cout << "Enter the Specific city" << endl;
getline(cin, city);
string key = date + city;
pair<string, string> temps = mapB.find(key);
if (temps.first != "-1" && temps.second != "-1") {
cout << "Min Temp: " << temps.first << " || " << "Max Temp: " << temps.second << endl;
cout << endl;
cout << endl;
}
else { // If the data was not found, print a message saying so
cout << "No data found." << endl;
cout << endl;
cout << endl;
}
}
if (input == "4") { // If the user chooses to find rain data
// Get the date and city for the data the user wants to find
cout << "Enter the Full Date (YYYY-MM-DD)" << endl;
getline(cin, date);
cout << "Enter the Specific city" << endl;
getline(cin, city);
string key = date + city;
// Find the rain data in the rain data hash map
pair<string, string> weather = mapA.find(key);
// If the data was found, print it
if (weather.first != "-1" && weather.second != "-1") {
cout << "Precipitation: " << weather.first << " || " << "Wind Speed: " << weather.second << endl;
cout << endl;
cout << endl;
}
// If the data was not found, print a message saying so
else {
cout << "No data found." << endl;
cout << endl;
cout << endl;
}
}
// If the user chooses to exit
if (input == "5"){
cout << "Goodbye for now!" << endl;
cout << endl;
cout << "Terminating Program....." << endl;
// End the interface loop
interface = false;
}
}
return 0;
}