Age Check Using an Inherited Field
easyQuestion 438A derived class can build new logic on top of a field it inherits.
Base class Person has a protected int age and a constructor Person(int a).
Create a derived class Citizen with:
1. a constructor Citizen(int a) that forwards a to Person
2. a method bool canVote() const that returns whether the inherited age is at least 18
The runner prints the boolean (C++ prints 1 for true, 0 for false). For age 20 it prints the output shown in Expected Output.
Do NOT write a main function.
Expected output
1= newline. The output ends with a newline, so print one after the last line.
Hints3 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.