fixed problem 1, and added C++ version of Probl. 2