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
|
vector < vector <int> > LoadShiftBidResults (vector <Guard> ParticipationList, vector <string> &ShiftList)
{
// Variables
string filename, shift, name, ColumnHeader, input;
int preference, number_of_unique_shifts(101), number_participating(ParticipationList.size());
vector < vector <int> > ShiftBidResults(number_participating, number_of_unique_shifts);
ifstream ShiftBidResultsFile;
cout << "\nWhat is the name of the file that contains the shift bid results that you will load into the\nprogram? (i.e. shiftbidresults.csv)" << endl;
getline(cin,filename);
ShiftBidResultsFile.open(filename);
// This is needed because the first input is a column headers
getline(ShiftBidResultsFile, ColumnHeader, ',');
// Load the names of the unique shifts
for (unsigned i = 0; i < number_of_unique_shifts; i++)
{
getline(ShiftBidResultsFile, shift, ',');
ShiftList.push_back(shift);
}
// Load the shift bid results for each guard. The position will be found from the Guard information (shift_bid_location).
for (unsigned i = 0; i < number_participating; i++)
{
for (unsigned j = 0; j < number_of_unique_shifts; j++)
{
// It is necessary to check for blanks. If a blank is read in, then a value of 0 will be given. If an int is read in, then that value will be assigned.
preference = 0;
getline(ShiftBidResultsFile, input, ',');
stringstream ss(input);
ss >> preference;
ShiftBidResults[i][j] = preference;
}
}
return ShiftBidResults;
}
|