Question: Please solve this Maze problem using C++ Please help me complete the Maze.cpp and Maze.h code in C++ Also write a main.cpp file that -read

Please solve this Maze problem using C++

Please help me complete the Maze.cpp and Maze.h code in C++

Also write a main.cpp file that

-read first a maze from an input file and print it on the screen and

-another print function that display the right path to solve the maze ( use 'X' to mark the path)

-Print the total of bonuses accumulated

Notice about Maze.cpp and Maze.h files

I already did the printMaze() function, what I'm asking is solveMaze function that will display

the right path to take in order to solve the maze, please mark the path with " X" and also

display the total of bonus accumulated when going throught the right path.

-----------------------------------Maze.h-----------------------------------------------------

#ifndef Maze_h

#define Maze_h

#include

#include

#include

#include

#include

using namespace std;

class Maze{

private :

int **data;

char **maze;

int col, row;

int startX, startY;// Starting X and Y values of maze

int endX, endY; // Ending X and Y values of maze

const char Wall = '#';//wall

const char Free = ' ';// free space

const char Bonus = '$';

const char Start = 'S';

const char Destination = 'D';

int r, c;

public

void printMaze();

};

#endif /* Maze_h */

---------------------------------------Maze.cpp----------------------------------------

#include

#include "Maze.h"

#include

#include

#include

#include

#include

#include

#include

using namespace std;

void Maze::printMaze ()

{

string filename;

cout << "Input filename :";

cin >> filename;

ifstream myFile;

myFile.open(filename);//read input file

stringstream convert;

string word;

int note = 0;

getline(myFile, word, ',');//get maze column

convert << word;

convert >> col;

word.clear();

convert.clear();

getline(myFile, word, ' ');//get maze row

convert << word;

convert >> row;

word.clear();

convert.clear();

int** data = new int*[row];

for(int i = 0; i < row; i++)

{ data[i] = new int[col];}

char** maze = new char*[row];

for(int i = 0; i < row; i++)

{ maze[i] = new char[col];}

int l = 0;

while (myFile.good()){

for (int j = 0; j < col-1; j++){//store maze map in data array

getline(myFile, word, ',');

convert << word;

convert >> note;

data[l][j] = note;

word.clear();

convert.clear();

}

getline(myFile, word, ' ');//storing the last column

convert << word;

convert >> note;

data[l][col-1] = note;

word.clear();

convert.clear();

l++;

if(l == row){break;}//file reading stop right in the end of last row

}

myFile.close();

for (int i = 0; i < row; i++)//Print maze

{

for (int j = 0; j < col; j++)

{ if(j==col-1)

{

if (data[i][j] > 201){maze[i][j] = Bonus;cout <

else if (data[i][j] == 0){maze[i][j] = Free;cout <

else if (data[i][j] == 1){ maze[i][j] = Wall;cout <

else if (data[i][j] == 200){ maze[i][j] = Start;cout <

else if (data[i][j] == 201){ maze[i][j] = Destination;cout <

}

else

{

if (data[i][j] > 201){maze[i][j] = Bonus;cout <

else if (data[i][j] == 0){maze[i][j] = Free;cout <

else if (data[i][j] == 1){ maze[i][j] = Wall;cout <

else if (data[i][j] == 200){ maze[i][j] = Start;cout <

else if (data[i][j] == 201){ maze[i][j] = Destination;cout <

}

}

}

}

--------------------------------------maze1.txt----------------------------------------------------

Notice about the input file (maze1.txt)

First row first column is maze number of column

First row second column is maze number of row

0 is a free space

1 is a wall

200 is the starting point

201 is the destination point

202, 203 and so on ( 202+) are the bonus

The content is below

---------------------------------------------------------------------------------------------------------

12,5

1,1,1,1,1,1,1,1,1,1,1,1

1,200,0,0,0,0,0,202,0,0,0,1 1,1,1,1,1,1,1,1,1,1,0,1 1,201,0,0,0,0,0,203,0,0,0,1 1,1,1,1,1,1,1,1,1,1,1,1

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!