Skip to content

Instantly share code, notes, and snippets.

@abdalla-alothman
Created February 28, 2014 13:12
Show Gist options
  • Save abdalla-alothman/9270835 to your computer and use it in GitHub Desktop.
Save abdalla-alothman/9270835 to your computer and use it in GitHub Desktop.
GPA Calculator with C++ Tuples
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
using namespace std;
int main()
{
vector<tuple<string, unsigned short, unsigned short, string, double>> v2;
// course name, course #, credits, geade, scale value
v2.push_back(make_tuple("Islamic Jurisprudence", 454, 3, "A", 4));
v2.push_back(make_tuple("Judicial Review", 439, 3, "A", 4));
v2.push_back(make_tuple("Competition Law", 157, 3, "A", 4));
v2.push_back(make_tuple("Financial Transactions", 433, 3, "B+", 3.3));
v2.push_back(make_tuple("Advocacy", 457, 2, "A", 4));
v2.push_back(make_tuple("Personal Properties", 451, 3, "A", 4));
double gradePoints = 0.0;
int totalUnits = 0;
for(auto ix = v2.begin(); ix != v2.end(); ++ix)
{
double initialPoint = 0;
cout << get<0>(*ix) << " "
<< get<1>(*ix) << " "
<< get<2>(*ix) << " "
<< get<3>(*ix) << " "
<< get<4>(*ix) << endl;
initialPoint = get<4>(*ix) * get<2>(*ix);
gradePoints += initialPoint;
totalUnits += get<2>(*ix);
}
cout.precision(4);
cout << "Total Units: " << totalUnits << endl;
cout << "Grad Points: " << gradePoints << endl;
cout << "GPA (gradePoints/totalUnits) = " << gradePoints / totalUnits << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment