solution code for chapter4