Skip to content

Commit

Permalink
Calculate scale 4 the same way as scale 10
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangswan committed Aug 1, 2022
1 parent a19a7de commit b4ac14d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 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

0 comments on commit b4ac14d

Please sign in to comment.