CJCoding With Joseph
15free / daySign inCreate account

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 the output shown in Expected Output.

Do NOT write a main function.

Expected Output:

26

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
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.