cpp partial solution fo exercise 2