Advertisement
Fabled_Knight

Untitled

Mar 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.15 KB | None | 0 0
  1. /* This file includes two functions
  2.    * splitOneLine
  3.    * mergeOneLine
  4.    You should copy these functions and paste to your project as user-defined functions
  5.    Read these functions, try to understand how they work
  6.    Then call them when you need
  7.    For any questions, contact me to get help
  8. */
  9.  
  10.  
  11.  
  12. //SPLIT ONE LINE INTO PIECES OF INFO
  13. 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)
  14. {
  15.     string temp;
  16.     int dash, comma;
  17.  
  18.     comma = line.find(",");
  19.     id = stoi(line.substr(0, comma));
  20.  
  21.     line = line.substr(comma + 1);
  22.     comma = line.find(",");
  23.     last = line.substr(0, comma);
  24.  
  25.     line = line.substr(comma + 1);
  26.     comma = line.find(",");
  27.     first = line.substr(0, comma);
  28.  
  29.     line = line.substr(comma + 1);
  30.     dash = line.find("-");
  31.     phone = line.substr(0, dash);  
  32.  
  33.  
  34.     line = line.substr(dash + 1);
  35.     dash = line.find("-");
  36.     temp = line.substr(0, dash);   
  37.     for (int i = 0; i < QUIZ_SIZE; i++)
  38.     {
  39.         comma = temp.find(",");
  40.         quizzes[i] = (float)stod(temp.substr(0, comma));
  41.         temp = temp.substr(comma + 1);
  42.     }
  43.    
  44.     line = line.substr(dash + 1);
  45.     dash = line.find("-");
  46.     temp = line.substr(0, dash);
  47.     for (int i = 0; i < HOMEWORK_SIZE; i++)
  48.     {
  49.         comma = temp.find(",");
  50.         homeworks[i] = (float)stod(temp.substr(0, comma));
  51.         temp = temp.substr(comma + 1);
  52.     }
  53.  
  54.     line = line.substr(dash + 1);
  55.     dash = line.find("-");
  56.     temp = line.substr(0, dash);
  57.     for (int i = 0; i < LAB_SIZE; i++)
  58.     {
  59.         comma = temp.find(",");
  60.         labs[i] = (float)stod(temp.substr(0, comma));
  61.         temp = temp.substr(comma + 1);
  62.     }
  63.  
  64.     line = line.substr(dash + 1);
  65.     dash = line.find("-");
  66.     temp = line.substr(0, dash);
  67.     for (int i = 0; i < TEST_SIZE; i++)
  68.     {
  69.         comma = temp.find(",");
  70.         tests[i] = (float)stod(temp.substr(0, comma));
  71.         temp = temp.substr(comma + 1);
  72.     }
  73.  
  74.     line = line.substr(dash + 1);
  75.     dash = line.find("-");
  76.     project = (float)stod(line.substr(0, dash));//project
  77.     cout << "project: " << project << endl;
  78.  
  79.     line = line.substr(dash + 1);
  80.     dash = line.find("-");
  81.     discussion = (float)stod(line.substr(0, dash));//discussion
  82.     cout << "discussion: " << discussion << endl;
  83.  
  84.     line = line.substr(dash + 1);
  85.     dash = line.find("-");
  86.     teamWork = (float)stod(line.substr(0, dash));//team work
  87.     cout << "team work: " << teamWork << endl;
  88.  
  89.     line = line.substr(dash + 1);
  90.     dash = line.find("-");
  91.     extra = (float)stod(line.substr(0, dash));//extra
  92.     cout << "extra: " << extra << endl;
  93.  
  94.     line = line.substr(dash + 1);
  95.     dash = line.find("-");
  96.     sumScore = (float)stod(line.substr(0, dash)); //sumScore
  97.  
  98.     line = line.substr(dash + 1);
  99.     dash = line.find("-");
  100.     percentage = (float)stod(line.substr(0, dash)); //average
  101.  
  102.     letterGrade = line.substr(dash + 1)[0];
  103. }
  104.  
  105.  
  106. //MERGE INFO TO ONE LINE
  107. 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)
  108. {
  109.     stringstream stream;
  110.     stream << fixed << setprecision(2) << to_string(id) + "," + last + "," + first + "," + phone + "-";
  111.  
  112.     //quizzes
  113.     for (int i = 0; i < QUIZ_SIZE - 1; i++)
  114.     {
  115.         stream << fixed << setprecision(2) << quizzes[i] << ",";
  116.     }
  117.     stream << quizzes[QUIZ_SIZE - 1] << "-";
  118.  
  119.     //homework
  120.     for (int i = 0; i < HOMEWORK_SIZE - 1; i++)
  121.     {
  122.         stream << homeworks[i] << ",";
  123.     }
  124.     stream << homeworks[HOMEWORK_SIZE - 1] << "-";
  125.    
  126.     //labs
  127.     for (int i = 0; i < LAB_SIZE - 1; i++)
  128.     {
  129.         stream << labs[i] << ",";
  130.     }
  131.     stream << labs[LAB_SIZE - 1] << "-";
  132.  
  133.     //tests
  134.     for (int i = 0; i < TEST_SIZE - 1; i++)
  135.     {
  136.         stream << tests[i] << ",";
  137.     }
  138.     stream << tests[TEST_SIZE - 1] << "-";
  139.  
  140.     //project
  141.     stream << project << "-";
  142.  
  143.     //discussion
  144.     stream << discussion << "-";
  145.  
  146.     //team work
  147.     stream << teamWork << "-";
  148.  
  149.     //extra
  150.     stream << extra << "-";
  151.  
  152.     //sumScore
  153.     stream << sumScore << "-";
  154.  
  155.     //percentage
  156.     stream << percentage << "-";
  157.  
  158.     //letterGrade
  159.     stream << letterGrade;
  160.  
  161.     return stream.str();
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement