Untitled
unknown
plain_text
2 years ago
1.2 kB
1
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 { protected: int damage; public: void setdamage(int b) { damage = b; } }; class sniper : public Defender { public: void Attack() { cout << "Sniper! - " << damage << endl; } }; class superman : public Defender { public: void Attack() { cout << "Superman!- " << damage << endl; } }; int main() { Ninja n; Monster m; Enemy* e1 = &n; Enemy* e2 = &m; e1->setAttackPower(20); e2->setAttackPower(80); n.attack(); m.attack(); sniper k; superman s; Defender* D1 = &k; Defender* D2 = &s; D1->setdamage(60); D2->setdamage(90); k.Attack(); s.Attack(); };