#include <bits/stdc++.h>
using namespace std;

int main(){
    cout << "---------------------- GPA Calculator ----------------------" << endl;
    int numOfSub, totalHours = 0, hours , ans;
    double GPA = 0;
    string grade;
    cout << "\nDo you have Old GPA? (1 for YES, 0 for NO): ";
    cin >> ans;
    if(ans == 1){
        cout << "\nEnter GPA and number of Credit hours: ";
        cin >> GPA >> hours;
        GPA = GPA * hours;
        totalHours += hours;
    }
    cout << "\nEnter the number of subjects: ";
    cin >> numOfSub;
    for(int i = 1; i <= numOfSub; i++) {
        cout << "\nEnter grade and hours for subject [" << i << "] : ";
        cin >> grade >> hours;
        totalHours += hours;
        if (grade == "A+" || grade == "a+" || grade == "ap") // marks >= 90
            GPA += hours * 4.0;
        else if (grade == "A" || grade == "a") // marks >= 85
            GPA += hours * 3.75;
        else if (grade == "B+" || grade == "b+" || grade == "bp") // marks >= 80
            GPA += hours * 3.4;
        else if (grade == "B" || grade == "b") // marks >= 75
            GPA += hours * 3.1;
        else if (grade == "C+" || grade == "c+" || grade == "cp") // marks >= 70
            GPA += hours * 2.8;
        else if (grade == "C" || grade == "c") // marks >= 65
            GPA += hours * 2.5;
        else if (grade == "D+" || grade == "d+" || grade == "dp") // marks >= 60
            GPA += hours * 2.25;
        else if (grade == "D" || grade == "d") // marks >= 50
            GPA += hours * 2;
        else if (grade == "F" || grade == "f") // marks < 50
            GPA += hours * 1;
    }
    cout << "\nThe GPA is: " << setprecision(3) << GPA / totalHours << " ,and total number of hours is " << totalHours << endl;
    return 0;
}