← Back to Inheritance
Question 144
Virtual Function With Return Value
Virtual Function With Return Value
You are given a base class Employee with protected members name (string) and baseSalary (double), a constructor, and a virtual functioncalculatePay()that returns baseSalary. Create two derived classes: 1. HourlyEmployee - Inherits from Employee - Has private double hoursWorked - Constructor takes name, hourly rate (as baseSalary), and hoursWorked - OverridecalculatePay()to return baseSalary * hoursWorked 2. BonusEmployee - Inherits from Employee - Has private double bonus - Constructor takes name, baseSalary, and bonus - OverridecalculatePay()to return baseSalary + bonus Do NOT include a main function. Your code will be tested automatically.
Expected Output:
Alice: 800 Bob: 5500
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
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.