Question: This is worth up to six ( 6 ) points extra credit. Consider the following fragment of main and function called letterGrade ( ) .

This is worth up to six (6) points extra credit. Consider the following fragment of main and function called letterGrade(). Assume all other code is correctly defined so that these work. Convert the given code to handle an exception, in which the function throws an exception if the passed-in grade is below 60.0(assumed on a 100-point scale). The section in main should contain the try and catch blocks, and the function should add a correctly written throw statement. Have the catch print a message that says the specific is too low to report a letter grade (include the actual value that caused the throw).
string letterGrade(float grade){
if (grade >92) return "A";
else if (grade >88) return "A-";
else if (grade >85) return "B+";
...// other options omitted for brevity
}
int main(){
float grade;
cout << "What is the score, 0 to 100?";
cin >> grade;
string lgrade = letterGrade(grade);
cout << "The grade was a "<< lgrade << endl;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!