Question: C++ fix the code #include stdafx.h #include using namespace std; class Enemy { protected: int attackPower; public: int setAttackPower(int a) { attackPower = a; }
C++ fix the code
#include "stdafx.h" #include
class Enemy { protected: int attackPower; public: int setAttackPower(int a) { attackPower = a; }
};
class Ninja : public Enemy { public: void attack() { cout << " i am a ninja ninja chop! -" << attackPower << endl;}
};
class Monster : public Enemy { public: void attack() { cout << "monster must eat you !!!-" << attackPower << endl; } };
int main() { Ninja n; Monster m; Enemy *enemy1 = &n; Enemy *enemy2 = &m; enemy1->attackPower(22); enemy2->attackPower(99);
n.attackPower(); m.attackPower();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
