solved exercise 8 in chapter5