code for program assignment 2