1. you should write down explanation for every line of the code. 2. you should e
ID: 3575020 • 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
SalariedEmployee E 2- T (SalariedEmployee. 1 Fig. 13.15: SalariedEmployee.h 2 salariedEmployee class derived from Employee. 3 #ifndef SALARIED H 4 #define SALARIED H 6 #include Employee.h" Employee class definition 8 class salariedEmployee public Employee salariedEmployee inherits from Employee, must override earnings 10 public: 11 salariedEmployeeC const string &, const to be concrete string & 12 const string &, double 0.0 13 14 void setweeklysalary double set weekly salary 15 double getweeklysalaryC) Const return weekly salary 16 17 keyword virtual signals intent to override 18 virtual double earnings O const U calculate earnings 19 virtual void printO Const. print salariedEmployee object 20 private 21 double weeklysalary; salary per week 22 h; end class salariedEmployee Functions will be overidden 23 (or defined for the first time) 24 #endif SALARIED HExplanation / Answer
Here
#include “employee.h” –file which contain the employee defination
Class salaried employee:public Employee –here the inheritance is takes place because employee class is a base inherited from Class salaried employee. Class salaried employee is derived class.
{
Public:
salaried employee(const string &, const string &, const string &,double=0) -here salaried employee method is called
void setweeklySalary(double)-here set the weekly salary of employee
void getweeklySalary(double)- here get weekly salary of employee i.e weekly salary of employee is calculated
Virtual double earnings()const-
Virtual double print()const-
here polymorphism is takes place because i.e one thing many forms earnings(),print() this two virtual functions are two different forms. one is calculate earnings other is salary employed per object
Private:double weeklysalary()-indicates salary per week
Salaried employee.cpp
Which has the implementation of Salaried employee
salaried employee(const string & first, const string & last, const string & ssn,double salary)
:Employee(first,last,ssn)
{
setweeklySalary(salary);
}
End constructor is salaried employee ended
Void salaried employee:: set weeklySalary( double salary)
{
weeklySalary=(salary<0)?0.0:salary-it is early binding or static binding takes place it is done at compile time
}
Void salaried employee:: get weeklySalary( double salary)const
{
Return weeklySalary; salary-it is early binding or static binding takes place it is done at compile time
}
Void salaried employee::earnings()
{
Return getweeklySalary();here late or dyanamic binding takes palce i.e it is done at run time
}
Void salaried employee::print()const
{
Cout << salaried employee:”; - print salary of employee
employee::print() –reuse the abstract base class print function
Cout << weekly salary employee:<< getweeklySalary();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.