Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. you should write down explanation for every line of the code. 2. you should e

ID: 3574390 • Letter: 1

Question

1. you should write down explanation for every line of the code.

2. you should explain about the example code. explanation for following contents should be included in this part.

- the inheritance structure of the Employee class

- mechanism of polymorphism in Employee class (explain with handle and virtual function)

- definition of dynamic binding and static binding

- the implementation mechanism and effect of polymorphism using vector

Commission Employee E BRA TR (CommissionEmployee.h) 1 Fig. 13.19: CommissionEmployee.h 2 CommissionEmployee class derived from Employee. 3 Hifindef COMMISSION H 4 #define COMMISSION H 6 #include Employee. h" Employee class definition 8 class commissionEmployee public Employee Commission Employee 9 inherits from Employee, 10 public must overnde earnings to 11 ssionEmployee const string & const string & be concrete const string &, double 0.0, double 0.0 12 13 14 void setcommissionRated double Set commission rate 15 double getCommissionRateO const return commission rate 16 17 void setGrosssales C double set gross sales amount 18 double getGrosssales C) Const. return gross sales amount 19 20 keyword virtual signals intent to override 21 virtual double earnings O const calculate earnings 22 virtual void print O Const. print. ission Employee object 23 private 24 double grosssales gross weekly sales Functions will be overridden 25 double commissionRate; commission percentage (or defined for first time) 26 Y; end class commissionEmployee 27 28 #endif COMMISSION H

Explanation / Answer

Overview:

The file CommissionEmployee.cpp defines the attributes and functions for the CommissionEmployee object, which is inherited from an Employee. If you just observe the class file, you will be able to infer that CommissionEmployee can do the following:

Part1:

Explanation:

CommissionEmployee.h

Public functions:

Private fields:

CommissionEmployee.cpp

Constructor: The constructor defined uses a ‘super constructor’ (name given to a parent class constructor when being called as a first step from the child class) to the Employee class with parameters (first, last, ssn). Once the constructor of CommissionEmployee is invoked with 5 values, the values of first, last and ssn will be first used to invoke the super constructor Employee(first, last, ssn) and once that is executed, the CommissionEmployee constructor’s execution will continue, which sets the grossSales, and the Commissionrate.

setCommisionRate: The method uses a shorthand conditional operator ? to compare a Boolean expression, and based on the result, assigns value of rate. The logic given is “If the CommissionEmployee object tries to set the rate, whose value is between 0 and 1, assign it to the commissionRate, else assign commissionRate = 0.0”

getCommissionRate: fetches the commissionRate from the commissionRate variable.

setGrossSales: just like setCommissionRate, this method uses a shorthand conditional operator to set the grossSales. If the value being assigned is less than 0, then assign 0 to the grossSales variable, else assign the input value to the variable

getGrossSales: fetches the grossSales.

Part2: