|
| 1 | +# Instructions |
| 2 | + |
| 3 | +You start your first day at an Australian company called "Doctor Data", which specializes in information recovery. |
| 4 | +You aced your job interview through your knowledge of C++ and [von Neumann probes][van-neumann-probes]. |
| 5 | +As you have seen a lot of test files, your new boss wants you to recreate the respective source and header files from some test code the company has recently recovered. |
| 6 | + |
| 7 | +In this exercise, you are going to recreate lost files. |
| 8 | + |
| 9 | +~~~~exercism/note |
| 10 | +The workflow of this concept exercise is very similar to the structure of Exercism's practice exercises. |
| 11 | +The exercise introduction text is only one part of the specification. |
| 12 | +The test file is your definitive guide to solving a given problem. |
| 13 | +Due to the way C++ compilation works, the test results might not show up in the web interface until you have implemented a minimal version of every class, function and enumeration that is required by the tests. |
| 14 | +If you receive compilation errors, they might disappear once you have addressed all tasks and tests. |
| 15 | +~~~~ |
| 16 | + |
| 17 | +You have four tasks, all related to recovering the lost code in the header and source files. |
| 18 | + |
| 19 | +## 1. Try to extract some first clues |
| 20 | + |
| 21 | +You look at two recovered lines from the test files: |
| 22 | + |
| 23 | +```cpp |
| 24 | +heaven::Vessel bob{"Robert Johansson", 1}; |
| 25 | +heaven::Vessel will{"Riker", 2, star_map::System::BetaHydri}; |
| 26 | +``` |
| 27 | +
|
| 28 | +Your sharp eye instantly recognized a namespace `heaven`. |
| 29 | +You also see that there must be a class called `Vessel`. |
| 30 | +The constructor can apparently be called with two or three arguments. |
| 31 | +The first argument seems to be of type `string`, the second one is a number. |
| 32 | +It is possible to initialize the `Vessel` class with a third argument. |
| 33 | +The third argument comes from a `star_map` namespace. |
| 34 | +It is an enumerator of type `System`. |
| 35 | +You even got one of the enumerations: `BetaHydri`. |
| 36 | +
|
| 37 | +Prepare the source and header files with your discovered information. |
| 38 | +You need two namespaces: `heaven` and `star_map`. |
| 39 | +The `heaven` namespace has a class `Vessel`, which can be called with two or three arguments. |
| 40 | +The `System` enum is to be placed in the `star_map` namespace and has an `EpsilonEridani` enumeration. |
| 41 | +Keep an eye out for other enumerations, so that you can constantly update the `System` enum. |
| 42 | +
|
| 43 | +## 2. Find more details |
| 44 | +
|
| 45 | +You uncover more lines from the test: |
| 46 | +
|
| 47 | +```cpp |
| 48 | +heaven::Vessel bob{"Robert Johansson", 1}; |
| 49 | +REQUIRE(bob.current_system == star_map::System::Sol); |
| 50 | +REQUIRE(bob.generation == 1); |
| 51 | +heaven::Vessel bob5 = bob.replicate("Mario"); |
| 52 | +REQUIRE(bob5.current_system == star_map::System::Sol); |
| 53 | +REQUIRE(bob5.generation == 2); |
| 54 | +``` |
| 55 | + |
| 56 | +The newly found test lines uncover another member function of the `Vessel` class: `replicate`. |
| 57 | +This function receives a string and returns another `Vessel` instance. |
| 58 | +You get an idea about the default value of the third argument of the constructor from the previous task. |
| 59 | +You also see two public member variables of the `Vessel` class and the specification of the `replicate` member function. |
| 60 | + |
| 61 | +Add the `replicate` function and the public member variables `current_system` and `generation` to the header and source files. |
| 62 | + |
| 63 | +## 3. Look into the inner workings |
| 64 | + |
| 65 | +You find some more interesting lines in the recovered test files: |
| 66 | + |
| 67 | +```cpp |
| 68 | +heaven::Vessel bob6{"Homer", 3, star_map::System::EpsilonEridani}; |
| 69 | +REQUIRE(bob6.busters == 0); |
| 70 | +bob6.make_buster(); |
| 71 | +REQUIRE(bob6.busters == 1); |
| 72 | +bool success = bob6.shoot_buster(); |
| 73 | +REQUIRE(success); |
| 74 | +REQUIRE(bob6.busters == 0); |
| 75 | +success = bob6.shoot_buster(); |
| 76 | +REQUIRE_FALSE(success); |
| 77 | +``` |
| 78 | +
|
| 79 | +Apparently, the `Vessel` class has a member variable `busters`, that can be changed with the two class member functions `make_buster` and `shoot_buster`. |
| 80 | +Until other information surfaces, you take a guess that the `make_buster` function returns `void`. |
| 81 | +As there is a test for the return value of `shoot_buster`, you assume that the function returns a `bool`. |
| 82 | +
|
| 83 | +Add the two functions and the member variable to the `Vessel` class. |
| 84 | +Keep looking for other `System` enumerators. |
| 85 | +
|
| 86 | +## 4. Complete the picture |
| 87 | +
|
| 88 | +During your scan of the test files you find only two uncovered sections of the code: |
| 89 | +
|
| 90 | +```cpp |
| 91 | +heaven::Vessel bob1{"Bob", 1, star_map::System::AlphaCentauri}; |
| 92 | +heaven::Vessel marv{"Marvin", 2, star_map::System::DeltaEridani}; |
| 93 | +heaven::Vessel milo{"Milo", 3, star_map::System::DeltaEridani}; |
| 94 | +heaven::Vessel howie{"Howard", 4, star_map::System::Omicron2Eridani}; |
| 95 | +
|
| 96 | +REQUIRE("Bob" == heaven::get_older_bob(bob1, marv)); |
| 97 | +REQUIRE(heaven::in_the_same_system(marv, milo)); |
| 98 | +REQUIRE_FALSE(heaven::in_the_same_system(marv, howie)); |
| 99 | +``` |
| 100 | + |
| 101 | +You see two functions, that are not members of the `Vessel` class, as they are not called with an instance. |
| 102 | +`get_older_bob` compares two `Vessel`instances and returns a `string`. |
| 103 | +`in_the_same_system` compares two `Vessel`instances and returns a `bool`. |
| 104 | + |
| 105 | +Implement the last missing functions from the recovered lines above. |
| 106 | + |
| 107 | +[van-neumann-probes]: https://en.wikipedia.org/wiki/Self-replicating_spacecraft |
0 commit comments