create cpp version of problem 3