Updated C++ Code