-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.cpp
More file actions
59 lines (48 loc) · 1.61 KB
/
Copy pathmain2.cpp
File metadata and controls
59 lines (48 loc) · 1.61 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
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include "record.h"
#include "state.h"
#include <iomanip>
using namespace std;
int main() {
int index = 0;
bool stateExists = false;
ifstream infile;
string inputfile;
state states[50];
cout << "Please input a data-file:" << endl;
cin >> inputfile;
infile.open(inputfile);
vector<record> allRecords;
string line;
while (getline(infile, line)) { // Read line by line from the CSV
record newRecord;
newRecord.readFromCSV(line); // Use the new method to read from CSV
stateExists = false;
for (int i = 0; i < index; i++) {
if (newRecord.getState() == states[i].getName()) {
states[i].addRecord(newRecord);
stateExists = true;
break; // Exit loop early if state is found
}
}
if (!stateExists && index < 50) { // Ensure not to exceed array size
states[index].setName(newRecord.getState());
states[index].addRecord(newRecord);
index++;
}
allRecords.push_back(newRecord);
}
// Output state information
cout << "State Easternmost Westernmost Northernmost Southernmost" << endl;
for (int i = 0; i < index; i++) {
cout << states[i].getName()
<< " " << states[i].getnorthZIP()
<< " " << states[i].getsouthZIP()
<< " " << states[i].geteastZIP()
<< " " << states[i].getwestZIP() << endl;
}
return 0;
}