Adding c++ solution to problems 2 and 3