In: Computer Science
READ THE FOLLOWING CAREFULLY TO GET FULL VALUE FROM THE PRACTICE. IF NOT COMFORTABLE WITH CLASSES,I WOULD START WITH DEFINING THE CLASS WITH ONE constructor AND GO FROM THEREUse the following to calculate a GPA (the following is for calculation information only):A = 4.00 grade points per credit hourA- = 3.70 grade points per credit hourB+ = 3.33 grade points per credit hourB = 3.00 grade points per credit hourB- = 2.70 grade points per credit hourC+ = 2.30 grade points per credit hourC = 2.00 grade points per credit hourC- = 1.70 grade points per credit hourD+ = 1.30 grade points per credit hourD = 1.00 grade points per credit hourD- = 0.70 grade points per credit hourgpa calculation = total grade points received (see above)/ number hours attemptedIf you took 3 classes; 3 credit hours each; received an 'A' in each classA = 4.00 points per credit hour means a total of 36 grade points earnedfor 9 attempted hoursgpa = 36/9 = 4.01. Create a header file (*.h) for a class named Student defined as follows:Private variables to hold:first namelast namestreet addresscitystatezipearned grade pointsattempted credit hoursgpaPublic methods:constructor of type Student; set all the private variables to spaceor zero, depending on the data typeconstructor of type Student; set all name values and all address values
to values passed in as parameters, do not include earned grade point orattempted credit hours as parametersconstructor of type Student; set ALL private variables to valuespassed in as parametersmethod to display all private variables of the class (i.e., cout)method to calculate the gpa (no parameters)method to calculate the gpa with earned and attempted values passed in as parametersmethod to set the earned value; earned value passed in as parametermethod to set the attempted value; attempted value passed in as parameter2. Create an implementation program (*.cpp file) for class Student and code all the public methods.3. Create a client program (*.cpp) that uses class Student. Create three students using each ofthe three constructors defined in 1. Be aware of what data gets initialized or set to values.4. Calculate the gpa for each of the students.5. Display ALL the data for each of the students after the gpa has been calculated (name, full address,grade points earned, grade points attempted, gpa)6. Be aware that if the first two constructors are used, the earned and attemptedvalues will NOT be set to calculate the gpa. Try using your set methodsto give these a value.You will need to create a project.If you like to include the following line of code: system("pause");You MAY need to: #include <cstdlib>Complete as much as you can before you submit ensuring what you've completed compiles. You do not have to correctlysolve the coding exercise, however, you MUST include code that ATTEMPTS to solve the problem to get credit.The program may be named any name of your choice and must have a .cpp extention. Do NOT includespaces in program names; variables may be any name of your choice.
Short Summary:
Source Code:
Student.h:
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
using namespace std;
class Student {
// private variables
private:
string firstName;
string lastName;
string streetAddress;
string city;
string state;
int zip;
float earnedGradePoints;
int attemptedCreditHours;
float gpa;
// public methods
public:
Student();
Student(string,string,string,string,string,int);
Student(string,string,string,string,string,int,float,float);
void display();
void calculateGpa();
float calculateGpa1(float,int);
void setEarnedValue(float);
void setAttemptedValue(int);
};
#endif
Student.cpp:
#include "Student.h"
#include <iostream>
#include <string>
using namespace std;
// default constructor; all the private variables to space or
zero
Student :: Student(){
firstName = " ";
lastName = " ";
streetAddress = " ";
city = " ";
state = " ";
zip = 0;
earnedGradePoints = 0.0;
attemptedCreditHours = 0;
gpa = 0.0;
}
// parameterized constructor; setting all name values and all
address values
Student :: Student(string fName,string lName,string
streetAdd,
string cty,string sta,int zipcode){
firstName = fName;
lastName = lName;
streetAddress = streetAdd;
city = cty;
state = sta;
zip = zipcode;
earnedGradePoints = 0.0;
attemptedCreditHours = 0;
gpa = 0.0;
}
// parameterized constructor; setting ALL private variables to
values passed in as parameters
Student :: Student(string fName,string lName,string
streetAdd,string cty,
string sta,int zipcode,float gradePoints,float creditHours){
firstName = fName;
lastName = lName;
streetAddress = streetAdd;
city = cty;
state = sta;
zip = zipcode;
earnedGradePoints = gradePoints;
attemptedCreditHours = creditHours;
gpa = 0.0;
}
// method to display all private variables of the class
void Student :: display(){
cout << "Name : " << firstName << " " <<
lastName << endl;
cout << "Address : " << streetAddress << " "
<< city << " " << state << " " << zip
<< endl;
cout << "Earned Grade Points : " << earnedGradePoints
<< " " << endl;
cout << "Attempted Credit Hours: "<<
attemptedCreditHours << " " << endl;
cout <<"GPA: " << gpa << endl;
cout<<"-----------------------------------------------------"
<< endl;
}
// method to calculate the gpa (no parameters)
void Student :: calculateGpa(){
gpa = earnedGradePoints / attemptedCreditHours;
}
// method to calculate the gpa with earned and attempted values
passed in as parameters
float Student :: calculateGpa1(float gradePoints,int
creditHours){
return gradePoints / creditHours ;
}
// setter for earned value;
void Student :: setEarnedValue(float gradePoints){
earnedGradePoints = gradePoints;
}
// setter for attempted value
void Student :: setAttemptedValue(int creditHours){
attemptedCreditHours = creditHours;
}
main.cpp:
#include <iostream>
#include "Student.h"
using namespace std;
int main()
{
// Creating Student objects by calling different constructors
Student student1 = Student();
Student student2 =
Student("Sara","Durgs","12","Atlanta","GA",30456);
Student student3 =
Student("Jospeh","Rama","5","Ohio","OH",39573,36,9);
// calculating GPA for first student object
student1.setEarnedValue(28);
student1.setAttemptedValue(4);
student1.calculateGpa();
// calculating GPA for 2nd student object
student2.setEarnedValue(52);
student2.setAttemptedValue(12);
student2.calculateGpa();
// calculating GPA for 3rd student object
student3.calculateGpa();
// displaying the result
student1.display();
student2.display();
student3.display();
return 0;
}
Refer the following screenshots for code indentation:
Student.h:
Student.cpp:
main.cpp:
Sample Run:
******************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
******************************************************************************