Code for ass2 done.