Updated c++ code