Documented code of the programming question 2