Code for Chapter 8 and 9