Skip to content

Commit

Permalink
Merge pull request #116 from hwangswan/master
Browse files Browse the repository at this point in the history
Using the same formula for GPA scale 4
  • Loading branch information
trhgquan authored Aug 1, 2022
2 parents 45503aa + b4ac14d commit b5b6152
Show file tree
Hide file tree
Showing 36 changed files with 108 additions and 89 deletions.
24 changes: 17 additions & 7 deletions src/PersonalGPA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ int PersonalGPA::passedCredits() { return _passedCredits; }
int PersonalGPA::failedCredits() { return _failedCredits; }

/**
* Return GPA
* Return GPA in scale 10.
*
* @return Grade
*/
Grade PersonalGPA::resultGPA() { return _resultGPA; }
Grade PersonalGPA::resultGPAScale10() { return _resultGPAScale10; }

/**
* Return GPA in scale 4.
*
* @return Grade
*/
Grade PersonalGPA::resultGPAScale4() { return _resultGPAScale4; }

/**
* Convert passed list to string vector.
Expand All @@ -71,9 +78,9 @@ std::vector<std::string> PersonalGPA::passedListToStringVector() {

stringVector.push_back("Overall");
stringVector.push_back(std::to_string(passedCredits()));
stringVector.push_back(resultGPA().toString());
stringVector.push_back(resultGPA().to4Scale().toString());
stringVector.push_back(resultGPA().toAScale());
stringVector.push_back(resultGPAScale10().toString());
stringVector.push_back(resultGPAScale4().toString());
stringVector.push_back(resultGPAScale10().toAScale());
stringVector.push_back("N/A");

return stringVector;
Expand Down Expand Up @@ -195,8 +202,11 @@ void PersonalGPA::calculateGPA() {

for (const Course &course : _coursesPassed) {
// Calculate new GPA.
_sumGrades += course.grade() * course.credit();
_resultGPA = _sumGrades / (1.0 * _passedCredits);
_sumGradeScale10 += course.grade() * course.credit();
_sumGradeScale4 += course.grade().to4Scale() * course.credit();

_resultGPAScale10 = _sumGradeScale10 / (1.0 * _passedCredits);
_resultGPAScale4 = _sumGradeScale4 / (1.0 * _passedCredits);
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/PersonalGPA.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class PersonalGPA {
// Stores personal grades & credits.
int _passedCredits = 0;
int _failedCredits = 0;
Grade _sumGrades = 0.0;
Grade _resultGPA = 0.0;
Grade _sumGradeScale10 = 0.0;
Grade _sumGradeScale4 = 0.0;
Grade _resultGPAScale10 = 0.0;
Grade _resultGPAScale4 = 0.0;

std::map<std::string, int> _creditDetail;

Expand Down Expand Up @@ -103,11 +105,18 @@ class PersonalGPA {
int failedCredits();

/**
* Return GPA
* Return GPA in scale 10.
*
* @return Grade
*/
Grade resultGPA();
Grade resultGPAScale10();

/**
* Return GPA in scale 4.
*
* @return Grade
*/
Grade resultGPAScale4();

/**
* Convert passed list to string vector.
Expand Down
6 changes: 3 additions & 3 deletions tests/data/has_fail.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ MTH00003,3,5,BB
MTH00041,3,5,BB
MTH00081,1,5.5,BB
MTH00086,1,10,BB
,,
,,,
BAA00102,2,6,BB
CSC10002,4,8.5,BB
BIO00001,3,7,TC
MTH00083,1,6.5,BB
MTH00082,1,9,BB
BAA00101,3,7,BB
MTH00004,3,8,BB
,,
,,,
CSC10004,4,8.5,BB
BAA00005,2,5,TC
BAA00104,2,8,BB
Expand All @@ -22,7 +22,7 @@ MTH00085,1,7.5,BB
MTH00040,3,7.5,BB
BAA00103,2,8,BB
CSC10008,4,8.5,BB
,,
,,,
BAA00003,2,0,BB
CSC10003,4,0,BB
CSC10006,4,0,BB
Expand Down
6 changes: 3 additions & 3 deletions tests/data/no_fail.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ MTH00003,3,5,BB
MTH00041,3,5,BB
MTH00081,1,5.5,BB
MTH00086,1,10,BB
,,
,,,
BAA00102,2,6,BB
CSC10002,4,8.5,BB
BIO00001,3,7,TC
MTH00083,1,6.5,BB
MTH00082,1,9,BB
BAA00101,3,7,BB
MTH00004,3,8,BB
,,
,,,
CSC10004,4,8.5,BB
BAA00005,2,5,BB
BAA00104,2,8,BB
Expand All @@ -22,7 +22,7 @@ MTH00085,1,7.5,BB
MTH00040,3,7.5,BB
BAA00103,2,8,BB
CSC10008,4,8.5,BB
,,
,,,
BAA00003,2,8,BB
CSC10003,4,10,BB
CSC10006,4,8.5,BB
Expand Down
2 changes: 1 addition & 1 deletion tests/data/textart.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
THIS IS TEXTART
THIS IS TEXTART
8 changes: 4 additions & 4 deletions tests/output/1.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/has_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 8 (stod)
Error happened while reading file data/has_fail.csv, on line 16 (stod)
Error happened while reading file data/has_fail.csv, on line 25 (stod)
THIS IS TEXTART

Total passed courses: 22 (78.57%)
Expand Down Expand Up @@ -30,7 +30,7 @@ Total passed courses: 22 (78.57%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
6 changes: 3 additions & 3 deletions tests/output/10.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error happened while reading file data/has_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 8 (stod)
Error happened while reading file data/has_fail.csv, on line 16 (stod)
Error happened while reading file data/has_fail.csv, on line 25 (stod)
Error happened (Input file does not exist)
6 changes: 3 additions & 3 deletions tests/output/13.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error happened while reading file data/has_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 8 (stod)
Error happened while reading file data/has_fail.csv, on line 16 (stod)
Error happened while reading file data/has_fail.csv, on line 25 (stod)
Error happened (Input file does not exist)
8 changes: 4 additions & 4 deletions tests/output/16.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/no_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 8 (stod)
Error happened while reading file data/no_fail.csv, on line 16 (stod)
Error happened while reading file data/no_fail.csv, on line 25 (stod)
THIS IS TEXTART

Total passed courses: 28 (100.00%)
Expand Down Expand Up @@ -36,7 +36,7 @@ Total passed courses: 28 (100.00%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | BB |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 76 | 7.95 | 3.00 | B+ | N/A |
| Overall | 76 | 7.95 | 3.29 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 70 (92.11%)
Expand Down
8 changes: 4 additions & 4 deletions tests/output/17.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/no_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 8 (stod)
Error happened while reading file data/no_fail.csv, on line 16 (stod)
Error happened while reading file data/no_fail.csv, on line 25 (stod)
Total passed courses: 28 (100.00%)
course code,credits,grade (10 - scale),grade (4 - scale),grade (A - scale),course type
CSC10001,4,10.00,4.00,A+,BB
Expand Down Expand Up @@ -31,7 +31,7 @@ MTH00081,1,5.50,2.00,C,BB
MTH00003,3,5.00,2.00,C,BB
MTH00041,3,5.00,2.00,C,BB
BAA00005,2,5.00,2.00,C,BB
Overall,76,7.95,3.00,B+,N/A
Overall,76,7.95,3.29,B+,N/A
Passed credit details:
Courses type BB: 70 (92.11%)
Courses type TC: 6 (7.89%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/18.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Total passed courses: 22 (78.57%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/19.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Total passed courses: 22 (78.57%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
8 changes: 4 additions & 4 deletions tests/output/2.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/has_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 8 (stod)
Error happened while reading file data/has_fail.csv, on line 16 (stod)
Error happened while reading file data/has_fail.csv, on line 25 (stod)
THIS IS TEXTART

Total passed courses: 22 (78.57%)
Expand Down Expand Up @@ -30,7 +30,7 @@ Total passed courses: 22 (78.57%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/20.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Total passed courses: 5 (62.50%)
| CSC10004 | 4 | 8.50 | 3.50 | A | BB |
| CSC10008 | 4 | 8.50 | 3.50 | A | BB |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 20 | 8.80 | 3.50 | A | N/A |
| Overall | 20 | 8.80 | 3.60 | A | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 20 (100.00%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/21.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Total passed courses: 22 (88.00%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/22.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MTH00081,1,5.50,2.00,C,BB
MTH00003,3,5.00,2.00,C,BB
MTH00041,3,5.00,2.00,C,BB
BAA00005,2,5.00,2.00,C,TC
Overall,57,7.61,3.00,B+,N/A
Overall,57,7.61,3.15,B+,N/A
Passed credit details:
Courses type BB: 49 (85.96%)
Courses type TC: 8 (14.04%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/23.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MTH00081,1,5.50,2.00,C,BB
MTH00003,3,5.00,2.00,C,BB
MTH00041,3,5.00,2.00,C,BB
BAA00005,2,5.00,2.00,C,TC
Overall,57,7.61,3.00,B+,N/A
Overall,57,7.61,3.15,B+,N/A
Passed credit details:
Courses type BB: 49 (85.96%)
Courses type TC: 8 (14.04%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/24.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CSC00004,4,8.50,3.50,A,BB
CSC10002,4,8.50,3.50,A,BB
CSC10004,4,8.50,3.50,A,BB
CSC10008,4,8.50,3.50,A,BB
Overall,20,8.80,3.50,A,N/A
Overall,20,8.80,3.60,A,N/A
Passed credit details:
Courses type BB: 20 (100.00%)

Expand Down
2 changes: 1 addition & 1 deletion tests/output/25.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MTH00081,1,5.50,2.00,C,BB
MTH00003,3,5.00,2.00,C,BB
MTH00041,3,5.00,2.00,C,BB
BAA00005,2,5.00,2.00,C,TC
Overall,57,7.61,3.00,B+,N/A
Overall,57,7.61,3.15,B+,N/A
Passed credit details:
Courses type BB: 49 (85.96%)
Courses type TC: 8 (14.04%)
Expand Down
8 changes: 4 additions & 4 deletions tests/output/27.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/no_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 8 (stod)
Error happened while reading file data/no_fail.csv, on line 16 (stod)
Error happened while reading file data/no_fail.csv, on line 25 (stod)
Total passed courses: 28 (100.00%)
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| course code | credits | grade (10 - scale) | grade (4 - scale) | grade (A - scale) | course type |
Expand Down Expand Up @@ -34,7 +34,7 @@ Total passed courses: 28 (100.00%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | BB |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 76 | 7.95 | 3.00 | B+ | N/A |
| Overall | 76 | 7.95 | 3.29 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 70 (92.11%)
Expand Down
8 changes: 4 additions & 4 deletions tests/output/28.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/no_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/no_fail.csv, on line 8 (stod)
Error happened while reading file data/no_fail.csv, on line 16 (stod)
Error happened while reading file data/no_fail.csv, on line 25 (stod)
Total passed courses: 28 (100.00%)
course code,credits,grade (10 - scale),grade (4 - scale),grade (A - scale),course type
CSC10001,4,10.00,4.00,A+,BB
Expand Down Expand Up @@ -31,7 +31,7 @@ MTH00081,1,5.50,2.00,C,BB
MTH00003,3,5.00,2.00,C,BB
MTH00041,3,5.00,2.00,C,BB
BAA00005,2,5.00,2.00,C,BB
Overall,76,7.95,3.00,B+,N/A
Overall,76,7.95,3.29,B+,N/A
Passed credit details:
Courses type BB: 70 (92.11%)
Courses type TC: 6 (7.89%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/29.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Total passed courses: 22 (78.57%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
8 changes: 4 additions & 4 deletions tests/output/3.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error happened while reading file data/has_fail.csv, on line 8 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 16 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 25 (vector::_M_range_check: __n (which is 3) >= this->size() (which is 3))
Error happened while reading file data/has_fail.csv, on line 8 (stod)
Error happened while reading file data/has_fail.csv, on line 16 (stod)
Error happened while reading file data/has_fail.csv, on line 25 (stod)
THIS IS TEXTART

Total passed courses: 5 (62.50%)
Expand All @@ -13,7 +13,7 @@ Total passed courses: 5 (62.50%)
| CSC10004 | 4 | 8.50 | 3.50 | A | BB |
| CSC10008 | 4 | 8.50 | 3.50 | A | BB |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 20 | 8.80 | 3.50 | A | N/A |
| Overall | 20 | 8.80 | 3.60 | A | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 20 (100.00%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/30.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Total passed courses: 22 (78.57%)
| MTH00041 | 3 | 5.00 | 2.00 | C | BB |
| BAA00005 | 2 | 5.00 | 2.00 | C | TC |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 57 | 7.61 | 3.00 | B+ | N/A |
| Overall | 57 | 7.61 | 3.15 | B+ | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 49 (85.96%)
Expand Down
2 changes: 1 addition & 1 deletion tests/output/31.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Total passed courses: 5 (62.50%)
| CSC10004 | 4 | 8.50 | 3.50 | A | BB |
| CSC10008 | 4 | 8.50 | 3.50 | A | BB |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
| Overall | 20 | 8.80 | 3.50 | A | N/A |
| Overall | 20 | 8.80 | 3.60 | A | N/A |
+-------------+---------+--------------------+-------------------+-------------------+-------------+
Passed credit details:
Courses type BB: 20 (100.00%)
Expand Down
Loading

0 comments on commit b5b6152

Please sign in to comment.