tutorial code for chapter 4