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

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

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started