Correct. By setting up this system of equations, you will be able to solve for t, the amount of time it will take the trains to pass each other.
Since the trains are 40 miles apart, they will meet somewhere in the middle of the two stations. If Train A travels d distance then Train B will need to travel a distance of 40 – d so that the total distance traveled for the two trains is 40 miles, the distance that stations are apart from each other.