Added the codes for exercise 6.1