Question: please would you help me with this program in c++, I would really approciate it :) The following figure is called a graph. The circles

please would you help me with this program in c++, I would really approciate it :)

The following figure is called a graph. The circles are called nodes, and the lines are called edges. An edge connects two nodes. You can interpret the graph as a maze of rooms and passages. The nodes can be thought of as rooms and an edge connects one room to another. Note that each node has at most four edges in the following graph.

please would you help me with this program in c++, I would

Write a program implements the above maze using references to instances of a Node which contains the name of the node and four pointers, one for each of the directions (North n, South s, East e and West w). Each node in the graph will correspond to an instance of Node. The edges correspond to links that connect one node to another and can be represented as pointers to other nodes.

Start the user at node A. The users goal is to reach the finish in node. The program should output possible moves in the north (n), south (s), east (e), or west (w) direction. Then the user inputs any of the four directions (n, s, e, w). After that your program checks whether thats a valid move or not. If valid, it will usher her/him to the desired room, otherwise prints an error message and prompt again for desired direction.

Sample execution scenario is shown next:

*********************************************************************************************************************

You are in room A of a maze of twisty little passages, all alike. You can go east or south.

Which direction would you like to go? e

You are in room B of a maze of twisty little passages, all alike. You can go west or south.

Which direction would you like to go? s

You are in room F of a maze of twisty little passages, all alike. You can go north or east.

Which direction would you like to go?

You are in room G of a maze of twisty little passages, all alike. You can go north or east or west.

Which direction would you like to go? s

ERROR: No way! Please try either north or east or west. E

You are in room H of a maze of twisty little passages, all alike. You can go north or south or west.

Which direction would you like to go? s You are in room L. You have arrived at the finish point.

Good job!

******************************************************************************************************************************

Instead of constructing the maze from the given figure, you need to read a file named Maze.txt to get a maze configuration. First line of the input file will be an integer, N, denoting total number of nodes (rooms) in our maze. Following that, there will be N room names separated by a single space character. The first room is the room where the user starts, and last room is where s/he wants to go.

Following the room names, there will be another integer, M, denoting number of edges (passages) connecting two rooms (i.e., nodes). Then, there will be M lines each containing an edge between two nodes and a direction in the following format:

Here, Node1 and Node2 can be any of the N nodes specified above. They are connected via a passage (i.e., edge). The direction value (either n, s, e, w) tells the position of Node2 with respect to Node1. Here, n, s, e, w means North, South, East and West directions. For example, A B e means, node B is to the east of node A, and are connected. The same link can also be specified using B A w, meaning node A is to the west of node B, and they are connected.

Maze.txt:

12

A B C D E F G H I J K L

11

A B e
A E s
E I s
I J e
B F s
F G e
C G s
H G w
H D n
H L s
K J w

START LFINISH START LFINISH

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!