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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started