Implement class structure described below on a diagram UML diagram.
Add all files in the Entities
directory separating classes into .h
and .cpp
files.
Include all relevant headers in the Entities/Entities.h
file.
Zaimplementuj strukturę klas przedstawioną poniżej na diagramie UML.
Dodaj wszystkie pliki w katalogu Entities
, dzieląc klasy na pliki .h
i .cpp
.
Załącz wszystkie potrzebne pliki nagłówkowe w Entities/Entities.h
.
The weight of the character is the sum of its body mass and all equipment he carries.
Character can carry any number of items that fit in a sack of size 10
.
Character can wield only one weapon, and wear only one armor.
Character's speed is equal to it's strength divided by his total weight.
Only files in the Entities
directory will be considered as solution.
Everything have to be properly destroyed, this means virtual destructor.
The getDescription
function should return a string that (as the name suggest) describe the item/character, and should include (for a character):
- Name (if present)
- Decorators
- Race
- Weapon (if any)
- Armor (if any)
- other Items (if any)
for instance:
John the half-wit orc, wielding a brick, wearing a plate armor, and carrying some socks and a severed hand
Character * orc = new Orc();
// an orc
orc->wield(new Brick());
// an orc, wielding a brick
orc->carry(new Socks());
// an orc, wielding a brick, and carrying some socks
orc = new HalfWit(orc);
// a half-wit orc, wielding a brick, and carrying some socks
orc->setName("John");
// John the half-wit orc, wielding a brick, and carrying some socks
orc->wear(new PlateArmor());
// John the half-wit orc, wielding a brick, wearing a plate armor, and carrying some socks
orc->carry(new SeveredHand());
// John the half-wit orc, wielding a brick, wearing a plate armor, and carrying some socks and a severed hand
orc->getSpeed();
// (100)/(95+0.5+20+0.03+5) = 0.82966896208
orc->getArmor();
// 50
orc->getPower();
// 5
The getJSON
function should return a computer-readable data about the item/character in the JSON format. For example (for the same character as above):
{
"type": "Character",
"name": "John",
"race": "orc",
"adjectives": [ "half-wit" ],
"wield": {
"type": "Weapon",
"name": "brick",
"power": 5,
"weight": 1,
"size": 0.5
},
"wear": {
"type": "Armor",
"name": "plate armor",
"armor": 50,
"weight": 20,
"size": 3
},
"carry": [
{
"type": "Armor",
"name": "socks",
"armor": 2,
"weight": 0.03,
"size": 0.01
},
{
"type": "Item",
"name": "severed hand",
"weight": 5,
"size": 1
}
]
}
The JSON string doesn't have to be formated the same way! But it have to be a valid JSON.
Only files in the Entities
directory will be considered as solution.
#include <stdio.h>
class A {
public:
virtual double getIQ() = 0;
virtual void doStuff() = 0;
virtual ~A() {};
};
class C : public A {
public:
virtual double getIQ() { return 10; };
virtual void doStuff() { printf("Stuff is done.\n"); };
virtual ~C() { printf("C died\n"); }
};
class Decorator : public A {
protected:
A* ptr;
public:
Decorator(A* ptr_) { ptr = ptr_; };
virtual double getIQ() { return ptr->getIQ(); };
virtual void doStuff() { ptr->doStuff(); };
virtual ~Decorator() { delete ptr; }
};
class D : public Decorator {
public:
D(A* ptr_) : Decorator(ptr_) {};
virtual double getIQ() { return ptr->getIQ() * 3; };
virtual ~D() {};
};
int main() {
A * obj;
obj = new C();
obj = new D(obj);
printf("IQ: %lg\n", obj->getIQ());
obj->doStuff();
delete obj;
}
Idea by G. Gruszczynski. UML diagram done with yuml.me
.