Added code for problems 4.1, 4.7, 17.8, 17.12