Practice

Manager Pay with Inheritance

HARDObject-Oriented Programming12 marks

Class Employee stores private EmpName and Salary, with constructor NEW(N, S), GetName() and GetSalary().

Class Manager INHERITS Employee adds private Bonus. Its constructor must call SUPER.NEW(N, S) then store Bonus. Override GetPay() on both classes: an employee is paid Salary; a manager is paid Salary + Bonus.

The test harness reads name, salary and bonus, constructs a Manager, and outputs <name> earns <pay>.

Input: Name, salary, bonus. Output: One formatted line.

Example:

Input:  Asha
        40000
        5000
Output: Asha earns 45000
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Typical manager pay
Inputs: Asha, 40000, 5000
Expected: Asha earns 45000
Test 2: Zero bonus
Inputs: Ben, 30000, 0
Expected: Ben earns 30000