Advertisement
Guest User

Cheat Sheet

a guest
Nov 25th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. double Student::computeMajorGpa() {
  2. double cumulativeGPA = 0;
  3. int numCourses = 0;
  4. int i;
  5.  
  6. for (i = 0; i <coursesTaken.size(); i++) {
  7. if (coursesTaken[i].name == "CS" || coursesTaken[i].name == "MATH") {
  8. numCourses++;
  9. switch(coursesTaken[i].grade) {
  10. case 'A': cumulativeGPA += 4.0; break;
  11. case 'B': cumulativeGPA += 3.0; break;
  12. case 'C': cumulativeGPA += 2.0; break;
  13. case 'D': cumulativeGPA += 1.0; break;
  14. default: cumulativeGPA += 0.0; // F
  15. }
  16. }
  17. }
  18. if (numCourses == 0)
  19. return -1;
  20. else
  21. return cumulativeGPA / numCourses;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement