CJCoding With Joseph
15free / daySign inCreate account

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 function calculatePay() 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
   - Override calculatePay() to return baseSalary * hoursWorked

2. BonusEmployee
   - Inherits from Employee
   - Has private double bonus
   - Constructor takes name, baseSalary, and bonus
   - Override calculatePay() 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
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.