Untitled
unknown
plain_text
2 years ago
1.3 kB
3
Indexable
Never
#include <iostream> using namespace std; class Enemy { protected: int attackPower; public: void setAttackPower(int a) { attackPower = a; } }; class Ninja : public Enemy { public: void attack() { cout << "Ninja! - " << attackPower << endl; } }; class Monster : public Enemy { public: void attack() { cout << "Monster! - " << attackPower << endl; } }; class Defender : public Enemy { public: void attack() { cout << "Defender! - " << attackPower << endl; } }; class Sniper : public Enemy { public: void attack() { cout << "Sniper! - " << attackPower << endl; } }; class Superman : public Enemy { public: void attack() { cout << "Superman! - " << attackPower << endl; } }; int main() { Ninja n; Monster m; Defender d; Sniper s; Superman superman; Enemy* e1 = &n; Enemy* e2 = &m; Enemy* e3 = &d; Enemy* e4 = &s; Enemy* e5 = &superman; e1->setAttackPower(20); e2->setAttackPower(80); e3->setAttackPower(50); e4->setAttackPower(70); e5->setAttackPower(100); n.attack(); m.attack(); d.attack(); s.attack(); superman.attack(); }