Wrote functions for Programmingassignment2