added sample code for chapter 5 and 6