Implemented a solution in C++ to problem 1.2.