Question: Create a C++ program based on the story Pascal the little rabbit * There was a little rabbit whose name was Pascal. Unlike his well-behaved

Create a C++ program based on the story Pascal the little rabbit

* There was a little rabbit whose name was Pascal. Unlike his well-behaved * brothers and sisters, he loved to adventure into the forest and explore * things although his mom told him not to. One day Pascal explored a new part * of the forest where he had never been. He found some big carrots that could * feed his family for a week during the coming storm. However, he was a little * lost and the storm was coming earlier than had been predicted. Pascal was * convinced that he should be able to find his way home with all the knowledge * that he got when he followed his cousin, Ada, sneaking into CSUF classrooms * to look for food and visit Adas student friends who taught them all the * tricks. Pascal knew about numbers, the magic stack where things put in last * would get pulled out first (LIFO), and the depth first search path finding * technique that can be used when one got lost. * * Stacks properties: * Elements are added from left to right * Elements are removed from right to left * Variable t keeps track of the index of the top element * When an element is pushed onto the top of the stack, t is incremented by 1 * When an element is popped from the top of the stack, t is decremented by 1 * * Pascals technique of finding home: * Mark each intersection, corner and dead end visited * Mark each corridor traversed * Keep track of the path back to the entrance (starting point) by means of a * rope (a stack to keep track of the path between nodes) * As soon as destination is encountered, the path as the contents of the * stack is returned * * In this project, you help Pascal to find his way home safely before the * storm comes. * */

#include

using namespace std;

// 10 TODO: // Define a const global variable for a 10x10 matrix and a stack of size 10. // Thus, no need to pass in the matrix / stack size to any functions.

// 20 TODO: // Initialize adjacency matrix between 2 nodes (vertices) to false // indicating that there are no connections between the 2 nodes void initializeAdjacencyMatrix(bool adjacencyMatrix[][10]) { // insert your code here ... }

// 30 TODO: // Read a list of (integer, integer) pairs representing node (vertex) // identifiers that are next to each other. // If any of the node identifiers are out of range, skip the path (edge). // Return the number of connected nodes (vertices). int retrieveAdjacencyMatrix(bool path[][10]) { // insert your code here ... }

// 40 TODO: // Retrieve the list of nodes (vertices) that are adjacent to node v int getAdjacentNodes(bool adjacencyMatrix[][10], int *adjacentNodes, int v) { // insert your code here ... }

// 50 TODO: // Return a list of node (vertex) identifiers that appear between starting and // ending nodes (vertices). Nodes (vertices) in the list should not be repeated. // Also, return the number of nodes between starting and ending nodes, inclusive. int getPath(bool adjacencyMatrix[][10], int *path, int startNode, int endNode) { // insert your code here ... }

int main() { // initialize adjacency paths bool adjacent_matrix[MAX_NODES][MAX_NODES]; initializeAdjacencyMatrix(MAX_NODES, adjacent_matrix); // display the adjacency matrix after initialization /* for (int iRow = 0; iRow < MAX_NODES; iRow++) { for (int iCol = 0; iCol < MAX_NODES; iCol++) { cout << adjacent_path[iRow][iCol] << " "; } // end for iCol cout << endl; } // endfor iRow cout << endl; */ // Read in the paths between connected nodes retrieveAdjacencyMatrix(adjacent_matrix); // display adjacent paths after reading the paths between connected nodes /* for (int iRow = 0; iRow < MAX_NODES; iRow++) { for (int iCol = 0; iCol < MAX_NODES; iCol++) { cout << adjacent_path[iRow][iCol] << " "; } // end for iCol cout << endl; } // endfor iRow cout << endl; */ int path[MAX_NODES]; // For the small_paths.text // int nNodesOnPath = getPath(adjacent_matrix, path, 1, 5); // For the paths.txt that will be used for grading int nNodesOnPath = getPath(adjacent_matrix, path, 1, 8); if (nNodesOnPath > 0) { cout << "Path: "; for (int ix = nNodesOnPath - 1; ix >= 0; ix--) { cout << path[ix] << " "; } cout << endl; } // Ask user to press [Enter] before exiting the program cout << " Press [Enter] to exit "; cin.get(); return 0; }

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!