โ 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: 212.0 Do NOT write a main function.
Expected Output:
212.0
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.