| .. | ||
| src | ||
| tests | ||
| CMakeLists.txt | ||
| main.cpp | ||
| README.md | ||
Linux compilation
> mkdir build
> cd build
> cmake -DCMAKE_BUILD_TYPE=Debug ..
> make
Exercise 1
- Go into directory
Coreand implement a base classPrintVisitorwhich should implementvisitmethod for two objects:ShipandStore - Create
PrettyPrintVisitorwhich will print cargo fromShipandSotore(just move the implementationprintCargo). - Add the rest of necessary implementation for
ShipandStore. Visitor should be taken asstd::unique_ptr - Verify in the
main.cppif cargo print in the same way as previously.
Example:
Ship
|----------------|----------------|
| NAME | AMOUNT |
|----------------|----------------|
|Rum | 300 |
|Banana | 200 |
|Banana | 150 |
|----------------|----------------|
Store
|----------------|----------------|----------------|
| NAME | AMOUNT | PRICE |
|----------------|----------------|----------------|
|Rum | 1000 | 40 |
|Banana | 1000 | 20 |
|Item | 1000 | 30 |
|----------------|----------------|----------------|
Exercise 2
- Create another visitor:
BasicPrintVisitorwhich should print the cargo but without special frames, just raw info. - For
Shipprint Name and Amount - For
Storeprint Name Amount and Price - You shouldn't modify anything in your code, just change the visitor in
main.cppand you should get a new output
Example:
Ship
Rum 300
Banana 200
Banana 150
Store
Rum 1000 40
Banana 1000 20
Item 1000 30
Exercise 3
- Create CargoDamageVisitor. You don't need to create a base class, because we know that we will not extend this code,
- You should create three
operator()one for each cargo type: Alcohol, Fruit, Item, - For fruit, you should draw a number between 0 and 5 and subtract such an amount of cargo
- For alcohol, you should draw a number between 0 and 10 and subtract half an amount of cargo
- For item, you should draw a number between 0 and 20 and subtract one quarter of cargo
- Visitor should be taken as a template argument by Player class
- Apply visitor whenever you successfully deal damage to ship
- Check in the main class if ship lost cargo after get damaged.