In: Computer Science
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade point average (GPA) Each A is worth 4 points. Each B is worth 3 points. Each C is worth 2 points. Each D is worth 1 point, and Each F is worth 0 points. The total quality points earned is the sum of the product of letter grade points and associated course credit hours. The GPA is the quotient of the quality points divided by the total number of credit hours. Gather the student's first name, last name, number of coursed taken. Then for each course gathered the letter grade and number of credit hours for the course. Compute and display the student's GPA with 2 places after the decimal point.
#include <iostream>
#include <iomanip> // std::setprecision
using namespace std;
int main()
{
//Declaring variables
string fname,lname;
int number_Of_courses;
double GPA=0.0;
int quality_points=0,tot_credit_hrs=0,letterGradePts=0;
//Setting the precision to two decimal points
std::cout << std::setprecision(2) << std::fixed;
//getting the firstname entered by the user
cout<<"Enter the First name:";
cin>>fname;
//getting the lastname entered by the user
cout<<"Enter the Last name:";
cin>>lname;
//getting the no of courses taken entered by the user
cout<<"Enter the no of courses taken :";
cin>>number_Of_courses;
//Creating the arrays which hold letter grades and credit
hours
char letterGrade[number_Of_courses];
int credit_hrs[number_Of_courses];
//Getting the letter grades and credit hours
for(int i=0;i<number_Of_courses;i++)
{
cout<<"Enter the letter grade for
course#"<<i+1<<":";
cin>>letterGrade[i];
cout<<"Enter the credit hours :";
cin>>credit_hrs[i];
}
//calculating the quality Points and total credit
hours
for(int i=0;i<number_Of_courses;i++)
{
if(letterGrade[i]=='A')
letterGradePts=4;
else if(letterGrade[i]=='B')
letterGradePts=3;
else if(letterGrade[i]=='C')
letterGradePts=2;
else if(letterGrade[i]=='D')
letterGradePts=1;
else if(letterGrade[i]=='F')
letterGradePts=0;
quality_points+=letterGradePts*credit_hrs[i];
tot_credit_hrs+=credit_hrs[i];
}
//Calculating GPA
GPA=(double)quality_points/tot_credit_hrs;
//Displaying the Student GPA
cout<<"The Student GPA is
:"<<GPA<<endl;
return 0;
}
____________
Output:
_________________Thank You