Algorithms in C++: Assignment 7 Solution