← Back to Inheritance
Question 440
Reusing an Inherited Setter and Getter
Reusing an Inherited Setter and Getter
When base data isprivate, a derived class cannot touch it directly and must go through the inherited public accessors. Base classTemperature(already written) has a PRIVATEdouble celsiuswithvoid setCelsius(double c)anddouble getCelsius() const. Create a derived classWeatherwith a methoddouble toFahrenheit() constthat uses the inheritedgetCelsius()to computecelsius * 9.0 / 5.0 + 32.0. For 100 degrees Celsius the result is 212.0. The runner prints it with one decimal place (see Expected Output). Do NOT write a main function.
Expected Output:
212.0= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.