-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsaurabhmain.cpp
54 lines (49 loc) · 1.56 KB
/
saurabhmain.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
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <sstream>
#include "Tree.h"
#include "Tree.cpp"
#include "Car.h"
using namespace std;
void parseInput (string filename, unordered_map <string, Tree*> &carBrandTrees) {
ifstream file(filename);
if (!file) {
cout << "faulty file name";
return;
}
vector<string> row;
string line, word;
getline (file,line); // header
int debugLimit = 5; // limit the number of lines to parse for debugging purposes
while (getline (file, line) && debugLimit) {
row.clear();
stringstream str(line);
while (getline(str, word, ','))
row.push_back(word);
// make the current car a Car object
Car* car = new Car(
row[12], // model
row[13], // brand
stoi(row[15]), // year
stoi(row[16]), // horsepower
stoi(row[8]), // cityMPG
stoi(row[10]), // highwayMPG
row[9], // fuel
stoi(row[18]) // price
);
// if the current brand does not exist as a key in the map, add it
if (carBrandTrees.find(row[13]) == carBrandTrees.end()) {
carBrandTrees[row[13]] = new Tree(3, 2);
}
// add the current car to its respective brand Tree
carBrandTrees[row[13]]->Insert(car);
// debugLimit--; // comment out line if not debugging
}
}
int main() {
unordered_map <string, Tree*> carBrandTrees;
parseInput("cmake-build-debug/cars.csv", carBrandTrees);
return 0;
}