CJCoding With Joseph
15free / daySign inCreate account

Inheriting and Extending a Constructor

You are given a base class Person with protected members name (string) and age (int), plus a constructor and a virtual display() function.

Create a derived class Student that:
- Publicly inherits from Person
- Has a private string member: major
- Has a constructor that takes name, age, and major (call the base constructor for name and age)
- Overrides display() to print all three fields on separate lines:
  Name: [name]
  Age: [age]
  Major: [major]

Do NOT include a main function. Your code will be tested automatically.

Expected Output:

Name: Alice
Age: 20
Major: Computer Science

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

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