Skip to content

Instantly share code, notes, and snippets.

@sr229
Created August 26, 2019 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sr229/84fecd92a85578e2e51cf5c2cdc5cc92 to your computer and use it in GitHub Desktop.
Save sr229/84fecd92a85578e2e51cf5c2cdc5cc92 to your computer and use it in GitHub Desktop.
CS-111: College Grade calculation
/* Copyright 2019 (c) Ralph Wilson Aguilar
* For CS-111
* Do not copy or redistribute without permission
*/
#include <iostream>
using namespace std;
// This is based on the Philippine College Grading System.
// To calculate the score we subtract minimum to the difference of minimum subtracted to the points.
// then divide it against the quantity of the total change in score divided by the total change in points.
//
// See: https://www.scholaro.com/pro/countries/Philippines/Grading-System
double getGrade(double points)
{
if (points < 70) return 5;
if (points < 75) return 5 - (points - 70) / 5;
if (points < 77) return 4 - (points - 75) / 2;
if (points < 89) return 3 - (points - 77) / 12;
if (points < 91) return 2 - (points - 89) / 8;
if (points < 94) return 1.75 - (points - 91) / 12;
if (points < 96) return 1.5 - (points - 94) / 8;
return 1.25 - (points - 96) /16;
}
// Same energy as above but we define this range to print the grade status.
// Its easier to read what the integer meant according to some people.
auto printGradeStatus(double points)
{
if (points < 70) return "Conditional/Failed";
if (points < 75) return "Passing - Below Average";
if (points < 77) return "Passing - Average";
if (points < 89) return "Passing - Above Average";
if (points < 94) return "Above Average";
// now you may wonder why there's a default one here? This is for anything 96 and above.
// catch my drift?
return "Excellent";
}
int main ()
{
double gradeInput;
cout << "Enter your grade in percent (without the %): ";
cin >> gradeInput;
if (gradeInput > 100)
{
cout << "Illegal input. Exiting.\n";
return 1;
}
// we store getGrade's value in a var so we can compare
// it to certain heuristics.
double gradeOutput = getGrade(gradeInput);
// printf is the only sane way to print out decimals in the first 2 decimal places.
printf("Your grade is : %.2f \n", gradeOutput);
cout << "This grade is " << printGradeStatus(gradeInput) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment