problem 5 cpp solution updated