Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will create a class to store information about a student’s courses and calcu

ID: 3662380 • Letter: Y

Question

You will create a class to store information about a student’s courses and calculate their GPA. Your GPA is based on the class credits and your grade. Each letter grade is assigned a point value as follows:

A = 4 points
B = 3 points
C = 2 points
D = 1 point

Therefore, an A in a 3 unit class is equivalent to 12 grade points (4 for the A times 3 unit class)
A C in a 4 unit class is equivalent to 8 grade points (2 for the C times 4 unit class)
This is a total of 20 grade points. Your GPA is calculated by dividing the total grade points by the total class credits, so in this case:

20 grade points / 7 credits = 2.85 GPA

Create a class called StudentInfo that represents the following information (private data) about a student:

Student name

Total grade points

Total credits

Create the following public member functions. (Note that the program may not require all functions to be used, but they should all exist for a complete class.)

Default constructor to initialize grade points and credits

setName                 Set value for name

getName                 Returns the name

addClass                 receives as input the class units and grade, updates grade points and credits appropriately

getGPA                   Calculates and returns the GPA

displayStudent          Displays all info about student. GPA should be displayed with 2 decimal places of precision  (i.e., 3.25).

Note that ONLY student name will be “set” from the outside. The grade points and credits will be modified with the method addClass which takes as parameters the number of units for the class and the grade awarded. This method then adds the appropriate grade points to the total, and also adds the credits to the total.

Write a program to test the class as shown below. You should ask for the student’s name, then allow them to add multiple classes. When done, display the GPA. ALL INPUT SHOULD BE RECEIVED IN MAIN AND PASSED TO THE OBJECT

Must include

StudentInfo class with required methods Methods correctly implemented GPATest class, which drives the application, is created A driver class with the main method. Inputcollected and passed to the object. Output displayed correctly

Explanation / Answer

StudentInfo.h

#pragma once
#include<string>
using namespace std;
class StudentInfo
{
public:
   StudentInfo();
   ~StudentInfo();
   void setName(string name);
   string getName();
   void addClass(int credits, char grade);
   double getGPA();
   void displayStudent();

private:
   string studentName;
   int totalGradePoints;
   int totalCredits;
};

StudentInfo.cpp

#include "StudentInfo.h"
#include<iostream>
#include<iomanip>
using namespace std;


StudentInfo::StudentInfo()
{
   totalCredits = 0;
   totalGradePoints = 0;
}


StudentInfo::~StudentInfo()
{
}

void StudentInfo::setName(string name)
{
   studentName = name;
}

string StudentInfo::getName()
{
   return studentName;
}

void StudentInfo::addClass(int credits, char grade)
{
   if (grade == 'A')
   {
       totalGradePoints += 4 * credits;
   }
   else if (grade == 'B')
   {
       totalGradePoints += 3 * credits;
   }
   else if (grade == 'C')
   {
       totalGradePoints += 2 * credits;
   }
   else if (grade == 'D')
   {
       totalGradePoints += 1 * credits;
   }
   totalCredits += credits;
}

double StudentInfo::getGPA()
{
   if (totalCredits != 0)
   {
       double GPA = totalGradePoints / (double)totalCredits;
       return GPA;
   }
   return -1;
}

void StudentInfo::displayStudent()
{
   cout << fixed << setprecision(2);
   cout << "Student Name: " << studentName << endl;
   cout << "Total grade points " << totalGradePoints <<endl;
   cout << "Total Credits " << totalCredits << endl;
   cout << "GPA: " << getGPA() << endl;
}

GPATest.cpp

#include "StudentInfo.h"
#include<iostream>
#include<iomanip>
using namespace std;


int main()
{
   StudentInfo s;
   s.setName("Jhon");
   s.addClass(3, 'A');
   s.addClass(4, 'B');
   s.addClass(2, 'C');

   cout << fixed << setprecision(2);
   cout<<"GPA is "<<s.getGPA()<<endl;

   s.displayStudent();

   cout << "Enter the name of the student" << endl;
   string name;
   cin >> name;
   StudentInfo test;
   test.setName(name);
   while (true)
   {
       cout << "Enter the classes in format of credits grade and enter -1 to exit" << endl;
       int credit;
       char grade;
       cin >> credit >> grade;
       if (credit == -1)
       {
           break;
       }
   }
  
   cout << "GPA is " << test.getGPA() << endl;

   test.displayStudent();

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote