code for second written assignment.