Advertisement
Rohmany

GPA_CALC_FCIH

Jun 30th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ConsoleApplication11.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8. #include <algorithm>
  9.  
  10. using std::cout;
  11. using std::endl;
  12. using std::cin;
  13. using std::vector;
  14. using std::string;
  15. using std::system;
  16. using std::getline;
  17.  
  18. typedef struct {
  19.     std::string Subject_Name;
  20.     double Hours;
  21.     double Score;
  22. }myStruct;
  23.  
  24. double Points(double myVariable) {
  25.     if (myVariable > 100)
  26.     {
  27.         return -1;
  28.     }
  29.     else if (myVariable >= 90)
  30.     {
  31.         return 4;
  32.     }
  33.     else if (myVariable >= 85)
  34.     {
  35.         return 3.75;
  36.     }
  37.     else if (myVariable >= 80)
  38.     {
  39.         return 3.4;
  40.     }
  41.     else if (myVariable >= 75)
  42.     {
  43.         return 3.1;
  44.     }
  45.     else if (myVariable >= 70)
  46.     {
  47.         return 2.8;
  48.     }
  49.     else if (myVariable >= 65)
  50.     {
  51.         return 2.5;
  52.     }
  53.     else if (myVariable >= 60)
  54.     {
  55.         return 2.25;
  56.     }
  57.     else if (myVariable >= 50)
  58.     {
  59.         return 2;
  60.     }
  61.     else if (myVariable >= 0)
  62.     {
  63.         return 1;
  64.     }
  65.     else
  66.     {
  67.         return -2;
  68.     }
  69.  
  70. }
  71.  
  72. double findGPA(std::vector<myStruct> myvect) {
  73.     double Hours_Total = 0;
  74.     double Points_Total = 0;
  75.     for each (myStruct x in myvect) {
  76.         Hours_Total += x.Hours;
  77.         Points_Total += Points(x.Score) * x.Hours;
  78.     }
  79.     double ans = Points_Total / Hours_Total;
  80.     return ans;
  81. }
  82.  
  83. int main()
  84. {
  85.     std::vector<myStruct> Student;
  86.     myStruct tmpStudent;
  87.     cout << "Enter Course Name, Hours and Score each in a seperate line\nEnter FCIH to Stop" << endl;
  88.     for (int i = 0;; i++) {
  89.         // cin >> tmpStudent.Subject_Name;
  90.         string s;
  91.         cin.clear();
  92.         getline(cin, tmpStudent.Subject_Name);
  93.         cin.clear();
  94.         if ("FCIH" ==  tmpStudent.Subject_Name) {
  95.             break;
  96.         }
  97.         cin >> tmpStudent.Hours;
  98.         cin >> tmpStudent.Score;
  99.         Student.push_back(tmpStudent);
  100.        
  101.     }
  102.  
  103.     cout << "Here is What You Entered" << endl;
  104.     for each (myStruct x in Student) {
  105.         cout << x.Subject_Name << "\t" << x.Hours << "\t" << x.Score << endl;
  106.     }
  107.  
  108.  
  109.     double finalAnswer = findGPA(Student);
  110.     cout << "Your Final GPA is" << " " << finalAnswer << endl;
  111.     system("Pause");
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement