Implemented and tested problem 5.