implementation of functions of Programming Assignment 2