Code for programming assignement 2