-
Notifications
You must be signed in to change notification settings - Fork 0
/
H10_1.cpp
89 lines (67 loc) · 1.33 KB
/
H10_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//Simple Boss 2.0
//Demonstrates access control under inheritance
#include <iostream>
using namespace std;
class Enemy
{
public:
Enemy();
void Attack() const;
protected:
int m_Damage;
};
Enemy::Enemy():
m_Damage(10)
{}
void Enemy::Attack() const
{
cout << "Attack inflicts " << m_Damage << " damage points!\n";
}
class Boss : public Enemy
{
public:
Boss();
void SpecialAttack() const;
private:
int m_DamageMultiplier;
};
Boss::Boss():
m_DamageMultiplier(3)
{}
void Boss::SpecialAttack() const
{
cout << "Special Attack inflicts " << (m_DamageMultiplier * m_Damage);
cout << " damage points!\n";
}
class FinalBoss : public Boss
{
public:
FinalBoss();
void MegaAttack() const;
private:
int m_DamageMultiplier;
};
FinalBoss::FinalBoss():
m_DamageMultiplier(3)
{}
void FinalBoss::MegaAttack() const
{
cout << "Mega Attack inflicts " << (10 * m_DamageMultiplier * m_Damage);
cout << " damage points!\n";
}
int main()
{
cout << "Creating an enemy.\n";
Enemy enemy1;
enemy1.Attack();
cout << "\nCreating a boss.\n";
Boss boss1;
boss1.Attack();
boss1.SpecialAttack();
cout << "\nCreating a final boss.\n";
FinalBoss finalBoss1;
finalBoss1.Attack();
finalBoss1.SpecialAttack();
finalBoss1.MegaAttack();
return 0;
}