C++ Code and Test Cases