The question I need help on is from "Big C++: Late Objects, Enhanced eText" by Cay Horstmann third edition question P5.5 from ch | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

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

13th Jul 2020, 9:04 PM
Lucia
1 ответ
0
Your code is truncated due to character limits. Please save the full version of the code in SoloLearn, and then attach the saved code link within your thread's Description. Writing code as raw text into the Description risks the text for truncation because of character limits. People also prefer to analyse saved code for convenient, so I suggest you to save that code and link the saved code instead. Follow the below guide to sharing links 👇 https://www.sololearn.com/post/75089/?ref=app
13th Jul 2020, 9:42 PM
Ipang