code for Ch03 of iosdev book