ex4 cpp modified