Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This file includes two functions
- * splitOneLine
- * mergeOneLine
- You should copy these functions and paste to your project as user-defined functions
- Read these functions, try to understand how they work
- Then call them when you need
- For any questions, contact me to get help
- */
- //SPLIT ONE LINE INTO PIECES OF INFO
- void splitOneLine(string line, int& id, string& last, string& first, string& phone, float quizzes[], float homeworks[], float labs[], float tests[], float& project, float& discussion, float& teamWork, float& extra, float& sumScore, float& percentage, char& letterGrade)
- {
- string temp;
- int dash, comma;
- comma = line.find(",");
- id = stoi(line.substr(0, comma));
- line = line.substr(comma + 1);
- comma = line.find(",");
- last = line.substr(0, comma);
- line = line.substr(comma + 1);
- comma = line.find(",");
- first = line.substr(0, comma);
- line = line.substr(comma + 1);
- dash = line.find("-");
- phone = line.substr(0, dash);
- line = line.substr(dash + 1);
- dash = line.find("-");
- temp = line.substr(0, dash);
- for (int i = 0; i < QUIZ_SIZE; i++)
- {
- comma = temp.find(",");
- quizzes[i] = (float)stod(temp.substr(0, comma));
- temp = temp.substr(comma + 1);
- }
- line = line.substr(dash + 1);
- dash = line.find("-");
- temp = line.substr(0, dash);
- for (int i = 0; i < HOMEWORK_SIZE; i++)
- {
- comma = temp.find(",");
- homeworks[i] = (float)stod(temp.substr(0, comma));
- temp = temp.substr(comma + 1);
- }
- line = line.substr(dash + 1);
- dash = line.find("-");
- temp = line.substr(0, dash);
- for (int i = 0; i < LAB_SIZE; i++)
- {
- comma = temp.find(",");
- labs[i] = (float)stod(temp.substr(0, comma));
- temp = temp.substr(comma + 1);
- }
- line = line.substr(dash + 1);
- dash = line.find("-");
- temp = line.substr(0, dash);
- for (int i = 0; i < TEST_SIZE; i++)
- {
- comma = temp.find(",");
- tests[i] = (float)stod(temp.substr(0, comma));
- temp = temp.substr(comma + 1);
- }
- line = line.substr(dash + 1);
- dash = line.find("-");
- project = (float)stod(line.substr(0, dash));//project
- cout << "project: " << project << endl;
- line = line.substr(dash + 1);
- dash = line.find("-");
- discussion = (float)stod(line.substr(0, dash));//discussion
- cout << "discussion: " << discussion << endl;
- line = line.substr(dash + 1);
- dash = line.find("-");
- teamWork = (float)stod(line.substr(0, dash));//team work
- cout << "team work: " << teamWork << endl;
- line = line.substr(dash + 1);
- dash = line.find("-");
- extra = (float)stod(line.substr(0, dash));//extra
- cout << "extra: " << extra << endl;
- line = line.substr(dash + 1);
- dash = line.find("-");
- sumScore = (float)stod(line.substr(0, dash)); //sumScore
- line = line.substr(dash + 1);
- dash = line.find("-");
- percentage = (float)stod(line.substr(0, dash)); //average
- letterGrade = line.substr(dash + 1)[0];
- }
- //MERGE INFO TO ONE LINE
- string mergeOneLine(int id, string last, string first, string phone, float quizzes[], float homeworks[], float labs[], float tests[], float project, float discussion, float teamWork, float extra, float sumScore, float percentage, char letterGrade)
- {
- stringstream stream;
- stream << fixed << setprecision(2) << to_string(id) + "," + last + "," + first + "," + phone + "-";
- //quizzes
- for (int i = 0; i < QUIZ_SIZE - 1; i++)
- {
- stream << fixed << setprecision(2) << quizzes[i] << ",";
- }
- stream << quizzes[QUIZ_SIZE - 1] << "-";
- //homework
- for (int i = 0; i < HOMEWORK_SIZE - 1; i++)
- {
- stream << homeworks[i] << ",";
- }
- stream << homeworks[HOMEWORK_SIZE - 1] << "-";
- //labs
- for (int i = 0; i < LAB_SIZE - 1; i++)
- {
- stream << labs[i] << ",";
- }
- stream << labs[LAB_SIZE - 1] << "-";
- //tests
- for (int i = 0; i < TEST_SIZE - 1; i++)
- {
- stream << tests[i] << ",";
- }
- stream << tests[TEST_SIZE - 1] << "-";
- //project
- stream << project << "-";
- //discussion
- stream << discussion << "-";
- //team work
- stream << teamWork << "-";
- //extra
- stream << extra << "-";
- //sumScore
- stream << sumScore << "-";
- //percentage
- stream << percentage << "-";
- //letterGrade
- stream << letterGrade;
- return stream.str();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement