Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2: Path Finding Problem Using C++ A robot is positioned on an integral point in a two-dimensional coordinate grid (x,, y). There is a

image text in transcribed

Problem 2: Path Finding Problem Using C++ A robot is positioned on an integral point in a two-dimensional coordinate grid (x,, y). There is a treasure that has been placed at a point in the same grid at (xt, yt). All x's and y's are integers. The robot can move up (North), down (South), left (West), or right (East). Commands can be given to the robot to move one position in one of the four direction. That is, "E" moves a robot one slot East (to the right) so if the robot was on position (3, 4), it would now be on (4, 4). The command N would move the robot one position north so a robot at position (4, 4) would be at (4, 5) Because the robot cannot move diagonally, the shortest distance between a robot at (xr, yr) and a treasure at (xt, Vt) is xr-Xt r -yt ShortestPossibleDistance Write a recursive program which determines all the unique shortest possible paths from the robot to the treasure The input to the program will be the starting position of the robot (xr, y) and the position of the treasure (xt, Vt). These will be in read from cin as four integers. For instance, an input of 1 3 -2 4 corresponds to the robot starting at position (1, 3) and needing to get to position (-2, 4). Do not worry about error conditions on input as we will assume the input is well formed. Read the input from cin The output of the program should be the listing of all the unique shortest possible paths followed by the number of unique paths. A path should be output as a string of characters with each character corresponding to a direction the Robot should move. For instance, NNENE corresponds to having the robot move North, North, East, North and East. This would be one answer to the input: 3 3 5 6, which corresponds to (3,3) -> (5,6) For the sake of efficiency, do not make two separate recursive calls in your program (one to count and one to print). Make sure that one recursive call handles both For the input 1 2 3 5 which corresponds to (1,2) -> (3,5) the output should be NNENE NNEEN NENNE NENEN NEENN ENNNE ENNEN ENENN Number of paths: 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago