Question: 11.3 (Composition as an Alternative to Inheritance) Many programs written with inheritance can be written with composition instead, and vice versa. Rewrite class BasePlusCommissionEmployee of




11.3 (Composition as an Alternative to Inheritance) Many programs written with inheritance can be written with composition instead, and vice versa. Rewrite class BasePlusCommissionEmployee of the CommissionEmployee-BasePlusCommissionEmployee hierarchy to use composition rather than inheritance. After you do this, assess the relative merits of the two approaches for designing classes CommissionEmployee and BasePlusCommissionEmployee, as well as for object-oriented pro- grams in general. Which approach is more natural? Why? I /Fig. 11.14: CommissionEmployee.cpp 2 II Class CommissionEmployee member-function definitions #incl ude #include = 1.0) { 58 59 60 throw invalid argument(" Commission rate must be0.0 and1.0 commissionRate -rate: 62 63 64 IIreturn commission rate 65 double CommissionEmployee::getCommissionRateO const return commissionRate; 67 68 69 calculate earnings 70 double CommissionEmployee::earningsO const return getCommissionRateOgetGrossSales O 72 73 74 I/ return string representation of CommissionEmployee object 5 string CommissionEmployee: :toStringO const 76 77 output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
