Question: EXERCISE B Override the getSalary() method in the Chief class by calling the super getSalary() and adding a salary bonus depending of the chief years

EXERCISE B

Override the getSalary() method in the Chief class by calling the super getSalary() and adding a salary bonus depending of the chief years in Service as follows:

  • If chief has more than 3 years and less than 5 years of service his salary will be raised 25%.
  • If chief has 5 or more years and less that 10 years of service his salary will be raised 50%.
  • If chief has 10 or more years of service his salary will be raised 75%.
  • Else the salary will not be raised.

See method comments in the code base for more details about how the method works.

test result
Chief *chief1 = new Chief("Felipe", 60, 100, 0); cout << chief1->getSalary() << endl;
50000
Chief *chief2 = new Chief("Mario", 65, 120, 1); cout << chief2->getSalary() << endl;
50000

#include "VillageQ2.cpp" /* * EXERCISE B * * Override the getSalary method in the Chief class by calling the super * getSalary method and adding the bonus times yearInService. * If chief has more than 3 years and less than 5 years of service his salary will be raised 25% * If chief has 5 years or more and less that 10 years of service his salary will be raised 50% * If chief has 10 years or more of service his salary will be raised 75% * Else the salary will not be raised. */

int Chief::getSalary() { //Implement here!

return 0; //Dummy Return }

________________________

class Chief : public Police

{

private:

int yearsInService;

public:

Chief(string name, int height, int weight, int yearsInService);

int getYearsInService() { return yearsInService; }

void setYearInService(int yearsInService) { this->yearsInService = yearsInService; }

virtual int getSalary();

virtual string toString();

virtual bool canDisableAlarm();

virtual string greet();

virtual bool equals(Player *p);

};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!