adding problem 4.7ii code