Implemented and tested problem 6.