Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication11.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using std::cout;
- using std::endl;
- using std::cin;
- using std::vector;
- using std::string;
- using std::system;
- using std::getline;
- typedef struct {
- std::string Subject_Name;
- double Hours;
- double Score;
- }myStruct;
- double Points(double myVariable) {
- if (myVariable > 100)
- {
- return -1;
- }
- else if (myVariable >= 90)
- {
- return 4;
- }
- else if (myVariable >= 85)
- {
- return 3.75;
- }
- else if (myVariable >= 80)
- {
- return 3.4;
- }
- else if (myVariable >= 75)
- {
- return 3.1;
- }
- else if (myVariable >= 70)
- {
- return 2.8;
- }
- else if (myVariable >= 65)
- {
- return 2.5;
- }
- else if (myVariable >= 60)
- {
- return 2.25;
- }
- else if (myVariable >= 50)
- {
- return 2;
- }
- else if (myVariable >= 0)
- {
- return 1;
- }
- else
- {
- return -2;
- }
- }
- double findGPA(std::vector<myStruct> myvect) {
- double Hours_Total = 0;
- double Points_Total = 0;
- for each (myStruct x in myvect) {
- Hours_Total += x.Hours;
- Points_Total += Points(x.Score) * x.Hours;
- }
- double ans = Points_Total / Hours_Total;
- return ans;
- }
- int main()
- {
- std::vector<myStruct> Student;
- myStruct tmpStudent;
- cout << "Enter Course Name, Hours and Score each in a seperate line\nEnter FCIH to Stop" << endl;
- for (int i = 0;; i++) {
- // cin >> tmpStudent.Subject_Name;
- string s;
- cin.clear();
- getline(cin, tmpStudent.Subject_Name);
- cin.clear();
- if ("FCIH" == tmpStudent.Subject_Name) {
- break;
- }
- cin >> tmpStudent.Hours;
- cin >> tmpStudent.Score;
- Student.push_back(tmpStudent);
- }
- cout << "Here is What You Entered" << endl;
- for each (myStruct x in Student) {
- cout << x.Subject_Name << "\t" << x.Hours << "\t" << x.Score << endl;
- }
- double finalAnswer = findGPA(Student);
- cout << "Your Final GPA is" << " " << finalAnswer << endl;
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement