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

INSTRUCTIONS In this problem, you will be prompting a student for grades and cre

ID: 3731470 • Letter: I

Question

INSTRUCTIONS In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA. This site: http://www.back2college.com/gpa.htm shows you how to calculate a GPA Keep prompting the student if they want to add more courses IMPORTANT NOTES! . The course name is prompted for, but nothing is done . We are just using the grades A, B, c, D, and F so you . You will need to use the "set precision" command as . You will need to use the "cin.ignoreO" function as with it. won't have to do so much typing! shown in the book. Set it to "fixed" and "2" discussed earlier in the course.

Explanation / Answer

Hi, please find the program below. Reach out in case of issue.

PS: cin.ignore() function was not shared so have not been used in the program. Thanks

Program::

#include <iostream>

#include <stdlib.h>

#include <cstring> //Added to use strcmp function

using namespace std;

void calculateGPA(); //Function to calculate GPA

int main()

{

  

int input;

cout<<"--------------------------------------------------------------------------"<<endl;

cout<<" GPA Calculator "<<endl;

cout<<"-------------------------------------------------------------------------- "<<endl;

cout<<" MENU:"<<endl;

cout<<" 1. Calculate GPA (Grade Point Average)"<<endl;

cout<<" 2. Exit Application"<<endl;

cout<<"--------------------------------------------------------------------------"<<endl;

sub:

cout<<"Enter your choice: ";

cin>>input;

switch(input)

{

case 1:

calculateGPA();

break;

case 2:

exit(EXIT_SUCCESS);

break;

default:

cout<<"You have entered wrong input.Try again! "<<endl;

goto sub;

break;

}

}

//Function to calculate GPA

void calculateGPA()

{

int q;

cout<<"-------------- GPA Calculating -----------------"<<endl;

cout<<" How many subject's points do you want to calculate? : ";

cin>>q;

float creditHours [q]; //To take in Credit Hours

float gradePoints [q]; // To store Grade points

char grade[2]; //To take in Grade

float temp; //Temporary variable

cout<<endl;

for(int i=0;i<q;i++)

{

cout<<"Enter the credit hours for the subject "<<i+1<<": ";

cin>>creditHours[i];

cout<<endl;

cout<<"Enter the Grade of the subject "<<i+1<<": ";

cin>>grade;

if (strcmp(grade,"A")==0) { //Compares the grade and store the grade point in temp variable

temp=4.00;

}

else if(strcmp(grade,"A-")==0){

temp=3.70;

}

else if(strcmp(grade,"A")==0){

temp=3.33;

}

else if(strcmp(grade,"B")==0){

temp=3.00;

}

else if(strcmp(grade,"B-")==0){

temp=2.70;

}

else if(strcmp(grade,"C+")==0){

temp=2.30;

}

else if(strcmp(grade,"C")==0){

temp=2.00;

}

else if(strcmp(grade,"C-")==0){

temp=1.70;

}

else if(strcmp(grade,"D+")==0){

temp=1.30;

}

else if(strcmp(grade,"D")==0){

temp=1.00;

}

else if(strcmp(grade,"D-")==0){

temp=0.70;

}

else if(strcmp(grade,"WF")==0 || strcmp(grade,"F")==0){

temp=0.00;

}

else

cout<<"You have entered wrong input.Try again! "<<endl;

gradePoints[i]=temp;

cout<<"----------------------------------- "<<endl;

}

float sum=0;

float tot;

//Looping to total of credit hours and grade points

for(int j=0;j<q;j++)

{

tot=creditHours[j]*gradePoints[j];

sum=sum+tot;

}

float totCr=0;

//For loop to calculate total total credit hours

for(int k=0;k<q;k++)

{

totCr=totCr+creditHours[k];

}

cout<<" Total Grade Points: "<<sum<<" . Total Credits: "<<totCr<<" .Total GPA: "<<sum/totCr<<" ."<<endl;

sub:

int inmenu;

//Menu creation

cout<<" 1. Calculate Again"<<endl;

cout<<"2. Exit This App "<<endl;

cout<<"Your Input: "<<endl;

cin>>inmenu;

switch(inmenu)

{

case 1:

calculateGPA();

break;

case 2:

exit(EXIT_SUCCESS);

default:

cout<<" You have Entered Wrong Input!Please Choose Again!"<<endl;

goto sub;

}

}

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