Implemented the two functions described in the programming assignment 2.