can you translate this code to c++ please?