Program 8.1 and 8.2 from chapter 8