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

2) Consider the code below: Employee class: class Employee { public: Employee(st

ID: 3699978 • Letter: 2

Question

2) Consider the code below: Employee class: class Employee { public: Employee(string theName, float thePayRate); protected string getName0 const; float getPayRate() const; float pay(float hours Worked) const; private string name; float payRate; Definitions for some of the methods follow: Employee:Employee(string theName, float thePayRate) name- theName; payRate- thePayRate; float Employee::pay(float hours Worked) const return hours Worked * payRate; Manager Class: #include "employee.h" class Manager : public Employee { public: Manager(string theName, float thePayRate, bool isSalaried); protected: bool getSalaried(0 const; float pay (float hours Worked) const;

Explanation / Answer

Hello, Below are the answers for your questions. Drop a comment if you have any queries. Thanks.

(Manager class is derived publicly from the base class Employee)

Manager class has only one private member variable, that is a boolean variable salaried. As the Manager is derived publicly, all the public members of Employee become public members of Manager, and all the protected members of Employee become protected members of Manager, private members are not inherited. And if the Manager was derived using protected mode, then all the protected members of the Employee class would have been the private members of Manager class.

Employee emp(“John Burke”,25.0)

Manager mgr(“Jan Kovacs”,1200.0,true)

Employee *emp1P=&emp;

cout<<”Pay: ”<< emp1P->pay(40.0);

cout<<”Pay: ”<< emp1P->pay(40.0);

The above code will not compile due to many reasons. First of all, pay() is the protected member method of Employee class as well as the Manager class. A protected member can be ONLY accessed by member functions or by a friend class. Secondly, on the line 5, it will show an error that ‘no known conversion from Manager* to const Employee&’, it will work only if we remove the ‘*’ before emp1P on line 5. If we solve all these problems and then execute the code, both calls will invoke the base class method pay() only. If we want to invoke the child class method like this, we have to declare pay() as the virtual function in the super class.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote