-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileIO.h
More file actions
57 lines (53 loc) · 1.86 KB
/
FileIO.h
File metadata and controls
57 lines (53 loc) · 1.86 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
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include "School.h"
#pragma once
struct Filereading{
//Reads the csv
static void readFile(std::vector<School*>& schools){
std::ifstream file("..\\cmake-build-debug\\Public_School_Characteristics_-_Current.csv");
std::string line;
bool first = true;
//Reads the ifstream
while(getline(file,line)){
std::vector<std::string> data;
std::string value;
std::stringstream ss(line);
if(first){
first = false;
continue;
}
while(getline(ss,value,',')){
data.push_back(value);
}
//Doesn't add invalid/incomplete schools
School* school = new School(data);
if(school->status == "1" and !school->checkBlank()) {
schools.push_back(school);
}
else
delete school;
}
file.close();
}
//Filters the data by a state from user input
static std::vector<School*> filterState(const std::vector<School*>& schools, std::string targetstate){
std::vector<School*> filtered_schools;
copy_if(schools.begin(),schools.end(), back_inserter(filtered_schools),[targetstate](School* school) {
return school->state == targetstate;
});
return filtered_schools;
}
//Filters the data by user chosen school level
static std::vector<School*> filterLevel(const std::vector<School*>& schools, std::string targetlevel){
std::vector<School*> filtered_schools;
copy_if(schools.begin(),schools.end(), back_inserter(filtered_schools),[targetlevel](School* school) {
return school->level == targetlevel;
});
return filtered_schools;
}
};