solved exercise 7 in chapter5