completed ex.3(c++)