Repository navigation
Expand file tree
/
Copy pathheader.h
More file actions
83 lines (69 loc) · 1.75 KB
/
Copy pathheader.h
File metadata and controls
83 lines (69 loc) · 1.75 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
#ifndef __header_h
#define __header_h
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <iterator>
#include <algorithm>
#include <boost/algorithm/string.hpp>
using namespace std;
// the struct student encapsulates a student that must be placed on a trip.
typedef struct _student {
string year, lastName, firstName;
int gender; // -1 for male, 1 for female, 0 for non-binary
int swimmingAbility, activityLevel, activityIntensity; // each on a 1-5 scale
vector<int> preferences; //
bool placed;
bool got_choice;
bool best_trip_got_choice;
int request_score;
} student;
// the struct trip encapsulates a trip that must be filled with students.
typedef struct _trip {
string name;
int index;
int capacity;
int minSwimmingAbility, minActivityLevel, minActivityIntensity;
vector<int> requests_vector;
int total_requests;
int num_of_females;
int num_of_males;
bool full;
vector<int> participants;
} trip;
/*
* A class to read data from a csv file.
*/
class CSVReader
{
string fileName;
string delimeter;
public:
CSVReader(string filename, string delm = ",") :
fileName(filename), delimeter(delm)
{ }
// Function to fetch data from a CSV File
vector<vector<string> > getData();
};
/*
* Parses through csv file line by line and returns the data
* in vector of vector of strings.
*/
vector<vector<string> > CSVReader::getData()
{
ifstream file(fileName);
vector<vector<string> > dataList;
string line = "";
// Iterate through each line and split the content using delimeter
while (getline(file, line))
{
vector<string> vec;
boost::algorithm::split(vec, line, boost::is_any_of(delimeter));
dataList.push_back(vec);
}
// Close the File
file.close();
return dataList;
}
#endif