-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubject.en.txt
executable file
·94 lines (65 loc) · 3.02 KB
/
subject.en.txt
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
89
90
91
92
93
94
Assignment name : cpp01_02
Expected files : Warlock.cpp Warlock.hpp
ASpell.hpp ASpell.cpp
ATarget.hpp ATarget.cpp
Fwoosh.hpp Fwoosh.cpp
Dummy.hpp Dummy.cpp
--------------------------------------------------------------------------------
In the Warlock class, the switch statement is FORBIDDEN and its use would
result in a -42.
Create an abstract class called ASpell, in Coplien's form, that has the
following protected attributes:
* name (string)
* effects (string)
Both will have getters (getName and getEffects) that return strings.
Also add a clone pure method that returns a pointer to ASpell.
All these functions can be called on a constant object.
ASpell has a constructor that takes its name and its effects, in that order.
Now you will create an ATarget abstract class, in Coplien's form. It has a type
attribute, which is a string, and its associated getter, getType, that return a
reference to constant string.
In much the same way as ASpell, it has a clone() pure method.
All these functions can be called on a constant object.
It has a constructor that takes its type.
Now, add to your ATarget a getHitBySpell function that takes a reference to
constant ASpell.
It will display :
<TYPE> has been <EFFECTS>!
<TYPE> is the ATarget's type, and <EFFECTS> is the return of the ASpell's
getEffects function.
Finally, add to your ASpell class a launch function that takes a reference to
constant ATarget.
This one will simply call the getHitBySpell of the passed object, passing the
current instance as parameter.
When all this is done, create an implementation of ASpell called Fwoosh. Its
default constructor will set the name to "Fwoosh" and the effects to
"fwooshed". You will, of course, implement the clone() method. In the case of
Fwoosh, it will return a pointer to a new Fwoosh object.
In the same way, create a concrete ATarget called Dummy, the type of which
is "Target Practice Dummy". You must also implement its clone() method.
Add to the Warlock the following member functions:
* learnSpell, takes a pointer to ASpell, that makes the Warlock learn a spell
* forgetSpell, takes a string corresponding a to a spell's name, and makes the
Warlock forget it. If it's not a known spell, does nothing.
* launchSpell, takes a string (a spell name) and a reference to ATarget, that
launches the spell on the selected target. If it's not a known spell, does
nothing.
You will need a new attribute to store the spells your Warlock knows. Several
types fit the bill, it's up to you to choose the best one.
Below is a possible test main and its expected output:
int main()
{
Warlock richard("Richard", "the Titled");
Dummy bob;
Fwoosh* fwoosh = new Fwoosh();
richard.learnSpell(fwoosh);
richard.introduce();
richard.launchSpell("Fwoosh", bob);
richard.forgetSpell("Fwoosh");
richard.launchSpell("Fwoosh", bob);
}
~$ ./a.out | cat -e
Richard: This looks like another boring day.$
Richard: I am Richard, the Titled!$
Target Practice Dummy has been fwooshed!$
Richard: My job here is done!$