travelled

CF

Distance Travelled + or –

The program must accept a string S representing the direction of movement as the input. The string S contains only the…