Question
EXERCISE C Implement methods enterEvent () in Villagers, Police and Mayor class. And canDisableAlarm() in Chief class as follows: PART 1 enterEvent() : Villagers can
EXERCISE C
Implement methods enterEvent() in Villagers, Police and Mayor class. And canDisableAlarm() in Chief class as follows:
PART 1
enterEvent():
- Villagers can only enter the Party event
- Police can only enter the Party and PDMeeting events
- Mayor can enter the Party, PDMeeting and Presidential Reunion events
PART 2
canDisableAlarm():
- Only the chief can disable the alarm
See the method comments in the code base for more details about how these methods work.
You MAY NOT declare any methods that could be inherited from super classes unless they must be overriden to achieve different behavior.
test | result |
Villager *v = new Villager("Alberto", 72, 100, "BlackSmithShop"); cout << v->canEnterEvent("Party") << endl; cout << v->canEnterEvent("PDMeeting") << endl; cout << v->canEnterEvent("Presidential Reunion") << endl; | true false false |
Villager *v1 = new Villager("Tato", 60, 100, "PizzaPlace"); Villager v2 = Villager("David", 61, 100, "PizzaPlace"); Player *v3 = new Villager("Jaime", 62, 100, "PizzaPlace"); Villager *v4 = new Villager("Alberto", 63, 100, "PizzaPlace"); Chief *c = new Chief("Harry", 61, 100, 5); cout << (v1->canDisableAlarm()) << endl; cout << (v2.canDisableAlarm()) << endl; cout << (v3->canDisableAlarm()) << endl; cout << (v4->canDisableAlarm()) << endl; cout << (c->canDisableAlarm()) << endl; | false false false false true |
#include "VillageQ3.cpp"
/* * EXERCISE C PART 1-a * * Override object's method (canEnterEvent) considering * the parameter's type string * Villager's can only enter the "Party" event */
bool Villager::canEnterEvent(string event) { //Implement here!
return false; //Dummy Return }
/* * EXERCISE C PART 1-b * * Override object's method canEnterEvent considering * the parameter event string * Police can only enter the "Party" and "PDMeeting" events */
bool Police::canEnterEvent(string event) { //Implement here!
return false; //Dummy Return }
/* * EXERCISE C PART 1-c * * Override object's method canEnterEvent considering * the parameter event string. * Mayor can enter the Party, PDMeeting and Presidential Reunion events. */
bool Mayor::canEnterEvent(string event) { //Implement here!
return false; //Dummy Return }
/* * EXERCISE C PART 2 * * Create and Override the canDisableAlarm method in the Chief class to * return true. Remember that only a Chief can disable alarms. */
bool Chief::canDisableAlarm() { //--->>> Implement here! <<<--- return false; // Dummy return }
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