fork download
  1. //GPA calculator for ASU-science
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <random>
  7. using namespace std;
  8. #define t "\t\t";
  9.  
  10. struct course {
  11. string name, rank;
  12. int credits;
  13. float gpa,grade;
  14. course(string Cname, int Ccredits, float Cgrade) {
  15. name = Cname; credits = Ccredits; grade = Cgrade;
  16. gpa = calcCGPA();
  17. }
  18. float calcCGPA() {
  19. float n = grade / (credits * 0.5);
  20. if (n >= 90) { rank = 'A'; gpa = 4; }
  21. else if (n >= 85) { rank = "A-";gpa = 3.67; }
  22. else if (n >= 80) { rank = "Β+";gpa = 3.33; }
  23. else if (n >= 75) { rank = 'B'; gpa = 3.00; }
  24. else if (n >= 70) { rank = "C+";gpa = 2.67; }
  25. else if (n >= 65) { rank = 'C'; gpa = 2.33; }
  26. else if (n >= 60) { rank = 'D'; gpa = 2.00; }
  27. else { rank = 'F'; gpa = 0; }
  28. return gpa;
  29. }
  30. void gpa2rank() {
  31. float n = grade / (credits * 0.5);
  32. if (n >= 4) { rank = 'A'; }
  33. else if (n >= 3.67) { rank = "A-";}
  34. else if (n >= 3.33) { rank = "Β+";}
  35. else if (n >= 3.00) { rank = 'B'; }
  36. else if (n >= 2.67) { rank = "C+";}
  37. else if (n >= 2.33) { rank = 'C'; }
  38. else if (n >= 2.00) { rank = 'D'; }
  39. else { rank = 'F';}
  40. }
  41. void display() {
  42. cout << name << t;
  43. cout << credits << t;
  44. cout << grade << t;
  45. cout << rank << "\n";
  46. }
  47. };
  48. void pastSem(float& nomerator, int& Tcredits) {
  49. char ans;
  50. cout << "Do you want to calculate the total GPA or a semester GPA?\na)Yes\tb)No\n"; cin >> ans;
  51. if (ans == 'a' || ans == 'y' || ans == 'Y')
  52. {
  53. float gpa; int credits;
  54. cout << "Insert the total GPA for the past semesters : "; cin >> gpa;
  55. cout << "Insert the total credit hours for the past semesters : "; cin >> credits;
  56. nomerator += gpa * credits;
  57. Tcredits += credits;
  58. }
  59. else if (ans == 'b' || ans == 'n' || ans == 'N')
  60. return;
  61. else
  62. {
  63. cout << "Invalid insert!\nPlease insert a valid character\n\n"; pastSem(nomerator,Tcredits);
  64. }
  65. }
  66. string message(float gpa) {
  67. int i;
  68. srand((int)gpa);
  69. i = rand() % 10;
  70. string quote[4][10] =
  71. {
  72. "You rock!","Top tier!","On fire!","So smart!","Ace mode","Too easy","Wow, A!","Nailed it","Brainy!","Slayed!",
  73. "Keep it up!","Nice try!","You got it!","So close!","Not bad!","Push more","Stay cool","Keep grind","Halfway!","Try hard!",
  74. "U got this","Next time!","Don’t quit","Try again","Head up!","Go harder","Fix this","Be brave","You can!","One shot!",
  75. "Wake up!","Yikes!","Do work!","KYS","Low batt","GPA who?","Help?","Oof...","Fix it!","Come on!"
  76. };
  77. if (gpa >= 3.5) return quote[0][i];
  78. else if (gpa >= 2.5) return quote[1][i];
  79. else if (gpa >= 1.0) return quote[2][i];
  80. else return quote[3][i];
  81. }
  82. int main() {
  83. int num, credits;
  84. float grade,nomerator = 0;
  85. int totalcredits = 0;
  86. int totalpassed ;
  87. string name;
  88. vector<course> C;
  89. pastSem(nomerator, totalcredits);
  90. totalpassed = totalcredits;
  91. cout << "Insetrt the number of courses for the semster : "; cin >> num;
  92. for (int i = 0; i < num; i++) {
  93. cout << "Course " << i + 1 << endl;
  94. cout << " Insert the course's name : "; cin >> name;
  95. cout << " Insert the course's credit hours : "; cin >> credits;
  96. cout << " Insert the course's degree : "; cin >> grade;
  97. C.push_back({ name,credits,grade });
  98. totalcredits += credits;
  99. }
  100. cout << "Name" << t;
  101. cout << "Credits" << t;
  102. cout << "Degree" << t;
  103. cout << "Grade" << "\n";
  104.  
  105. for (auto it : C) {
  106. nomerator += it.credits * it.gpa;
  107. if (it.gpa != 0) totalpassed += it.credits;
  108. it.display();
  109. }
  110. C.push_back({ "Final\nGrade", totalcredits,nomerator/2 });
  111. cout << "\n";
  112. cout << C.back().name << t;
  113. cout << totalpassed << t;
  114. cout << nomerator/totalcredits << t;
  115. C.back().gpa2rank();
  116. cout << C.back().rank << t;
  117. cout << message(C.back().gpa) << "\n";
  118. return 0;
  119. }
Success #stdin #stdout 0.01s 5312KB
stdin
a 
2.231 
33 
7 
COMP201 
3 
92 
COMP207 
4 
113 
ENGL201 
2 
90 
MATH225 
3 
60 
PHYS201 
2 
50 
PHYS203 
2 
75 
PHYS205 
2 
54
stdout
Do you want to calculate the total GPA or a semester GPA?
a)Yes	b)No
Insert the total GPA for the past semesters : Insert the total credit hours for the past semesters : Insetrt the number of courses for the semster : Course 1
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Course 2
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Course 3
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Course 4
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Course 5
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Course 6
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Course 7
  Insert the course's name :   Insert the course's credit hours :   Insert the course's degree : Name		Credits		Degree		Grade
COMP201		3		92		D
COMP207		4		113		F
ENGL201		2		90		A
MATH225		3		60		F
PHYS201		2		50		F
PHYS203		2		75		B
PHYS205		2		54		F

Final
Grade		40		1.83575		F		KYS