implementation of the Programming Assignment 2