The question I need help on is from "Big C++: Late Objects, Enhanced eText" by Cay Horstmann third edition question P5.5 from ch
P 5.5: Implement the number_to_grade function of [Worked Example 5.3 ] so that you use two sets of branches: one to determine whether the grade should be A, B, C, D, or F, and another to determine whether a + or - should be appended. [Worked example 5.3]: #include <iostream> #include <string> using namespace std; /** Converts a letter grade to a number. @param grade a letter grade (A+, A, A-, ..., D-, F) @return the equivalent number grade */ double grade_to_number(string grade) { double result = 0; string first = grade.substr(0, 1); if (first == "A") { result = 4; } else if (first == "B") { result = 3; } else if (first == "C") { result = 2; } else if (first == "D") { result = 1; } if (grade.length() > 1) { if (grade.substr(1, 1) == "+") { result = result + 0.3; } else { result = result - 0.3; } } return result; } /** Converts a number to the nearest letter grade. @param x a number between 0 and 4.3 @return the nearest letter grade */ string number_to_grade(double x) { if (x >= 4.15) { return "A+"; } if (x >= 3.85) { return "A"; } if (x >= 3.5) { return "A-"; } if (x >= 3.15) { return "B+"; } if (x >= 2.85) { return "B"; } if (x >= 2.5) { return "B-"; } if (x >= 2.15) { return "C+"; } if (x >= 1.85) { return "C"; } if (x >= 1.5) { return "C-"; } if (x >= 1.15) { return "D+"; } if (x >= 0.85) { return "D"; } if (x >= 0.5) { return "D-"; } return "F"; } /** Returns the smaller of two numbers. @param x a number @param y a number @return the smaller of x and y */ double min(double x, double y) { if (x < y) { return x; } else { return y; } } /** Processes one line of input. @return true if the sentinel was not encountered */ bool process_line() { cout << "Enter four grades or Q to quit: "; string g1; cin >> g1; if (g1