chapter 4 exercises and a sample function