fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. cout << "---------------------- GPA Calculator ----------------------" << endl;
  6. int numOfSub, totalHours = 0, hours , ans;
  7. double GPA = 0;
  8. string grade;
  9. cout << "\nDo you have Old GPA? (1 for YES, 0 for NO): ";
  10. cin >> ans;
  11. if(ans == 1){
  12. cout << "\nEnter GPA and number of Credit hours: ";
  13. cin >> GPA >> hours;
  14. GPA = GPA * hours;
  15. totalHours += hours;
  16. }
  17. cout << "\nEnter the number of subjects: ";
  18. cin >> numOfSub;
  19. for(int i = 1; i <= numOfSub; i++) {
  20. cout << "\nEnter grade and hours for subject [" << i << "] : ";
  21. cin >> grade >> hours;
  22. totalHours += hours;
  23. if (grade == "A+" || grade == "a+" || grade == "ap") // marks >= 90
  24. GPA += hours * 4.0;
  25. else if (grade == "A" || grade == "a") // marks >= 85
  26. GPA += hours * 3.75;
  27. else if (grade == "B+" || grade == "b+" || grade == "bp") // marks >= 80
  28. GPA += hours * 3.4;
  29. else if (grade == "B" || grade == "b") // marks >= 75
  30. GPA += hours * 3.1;
  31. else if (grade == "C+" || grade == "c+" || grade == "cp") // marks >= 70
  32. GPA += hours * 2.8;
  33. else if (grade == "C" || grade == "c") // marks >= 65
  34. GPA += hours * 2.5;
  35. else if (grade == "D+" || grade == "d+" || grade == "dp") // marks >= 60
  36. GPA += hours * 2.25;
  37. else if (grade == "D" || grade == "d") // marks >= 50
  38. GPA += hours * 2;
  39. else if (grade == "F" || grade == "f") // marks < 50
  40. GPA += hours * 1;
  41. }
  42. cout << "\nThe GPA is: " << setprecision(3) << GPA / totalHours << " ,and total number of hours is " << totalHours << endl;
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5440KB
stdin
1
3.68 58
7
a 3
ap 3
ap 3
ap 3
cp 3
b 3
a 3
stdout
---------------------- GPA Calculator ----------------------

Do you have Old GPA? (1 for YES, 0 for NO): 
Enter GPA and number of Credit hours: 
Enter the number of subjects: 
Enter grade and hours for subject [1] : 
Enter grade and hours for subject [2] : 
Enter grade and hours for subject [3] : 
Enter grade and hours for subject [4] : 
Enter grade and hours for subject [5] : 
Enter grade and hours for subject [6] : 
Enter grade and hours for subject [7] : 
The GPA is: 3.67 ,and total number of hours is 79