CJCoding With Joseph

Protected Helper Method

A protected method can be called by a derived class but not from outside the hierarchy.

Base class Calculator (already written) has a PROTECTED method int square(int x) const returning x * x.

Create a derived class StatsCalculator with a PUBLIC method int squarePlusOne(int x) const that returns square(x) + 1 by calling the inherited protected helper.

For input 5, square(5) is 25 and the result is 26, so the program prints:
26

Do NOT write a main function.

Expected Output:

26
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.