Completed code of assignment 2