This is the solution to Problem 1 in C++