Refactored Working C++ code
Adding the working and refactored C++ code