0. the idea

A lecturer asked for a faster way to compute GPA and CGPA for a class than doing it by hand in a spreadsheet formula that broke every semester the grading scale changed slightly.

1. how it's built

Approach:
  • Plain C++, no external dependencies
  • A Course struct holding grade and credit hours
  • A Student struct holding a vector of Courses
  • Straightforward console-driven input and summary output

2. features

What it does:
  • Per-course grade point calculation from a configurable grading scale
  • Credit-weighted GPA for a semester
  • Running CGPA across multiple semesters
  • Printable summary per student

3. a challenge — grading scales aren't universal

Different institutions map letter grades to grade points differently — an A isn't always a 4.0, and some scales use pluses and minuses. Hardcoding one scale would have made the tool useless anywhere else.

Keep the grade-to-point mapping as data (a lookup table), not as a chain of if/else on letters. Swapping grading scales becomes a config change instead of a recompile.

4. the code

struct Course {
    std::string grade;
    int creditHours;
};

double calculateGPA(const std::vector<Course>& courses,
                     const std::map<std::string, double>& scale) {
    double totalPoints = 0;
    int totalCredits = 0;

    for (const auto& c : courses) {
        totalPoints += scale.at(c.grade) * c.creditHours;
        totalCredits += c.creditHours;
    }

    return totalCredits ? totalPoints / totalCredits : 0.0;
}

5. what i learned

It's a small tool, but it was a good reminder of how far plain C++ and the STL get you without reaching for a framework — vectors, maps, and structs cover most of what a data-shaped problem like this actually needs.