Question: Please help me rewrite this code in C++ that works exactly the same as the original one In a word i need to submit this

Please help me rewrite this code in C++ that works exactly the same as the original one

In a word i need to submit this homework but i dont have enough time to write it but i found this from my friend, please help me

if possible a short description of the main function. Thanks

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

#include

#include

#include"Maze.h"

using namespace std;

int main()

{

MAZE test;

test.readMaze();

test.printMaze();

cout << "Wait a second..." << endl;

Sleep(1000);

test.printRoad();

system("pause");

}

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

#include "Maze.h"

#include

#include

#include

#include

#include

#include

using namespace std;

char find(int** copy, int *sr, int *sc, int row, int col,vector route)//Finding the path

if (copy[*sr][*sc + 1] != 1 && *sc + 1 < col) {//right

copy[*sr][*sc] = 1;

*sc = *sc + 1;

return 'r';

}

else if (copy[*sr + 1][*sc] != 1 && *sr + 1 < row) {//down

copy[*sr][*sc] = 1;

*sr = *sr + 1;

return'd';

}

else if (copy[*sr][*sc - 1] != 1 && *sc >= 1) {//left

copy[*sr][*sc] = 1;

*sc = *sc - 1;

return'l';

}

else if (copy[*sr - 1][*sc] != 1 && *sr >= 1) {//up

copy[*sr][*sc] = 1;

*sr = *sr - 1;

return'u';

}

else {// if no path

copy[*sr][*sc] = 1;

switch (route.back())

{

case'r':*sc = *sc - 1; break;

case'd':*sr = *sr - 1; break;

case'l':*sc = *sc + 1; break;

case'u':*sr = *sr + 1; break;

}

route.pop_back();//pop route

find(copy, &*sr, &*sc, row, col, route);

}

}

void MAZE::readMaze()

{

ifstream input;//open file

string filename;//maze name

string size;//

string line;//

stringstream convert;//convert string to integer

int temp = 0;//

int tcol = 0, trow = 0;//

cout << "Please enter the filename of maze(xxx.txt):";

cin >> filename;

input.open(filename, ios::in);

//find row

getline(input, size,',');//First line before comma

convert << size;//

convert >> row;

convert.str("");//clear

convert.clear();

//find col

getline(input, size, ' ');//

convert << size;

convert >> col;

convert.str("");

convert.clear();

Map = new int*[row];//dynamic array to store maze data

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

Map[i] = new int[col];

}

while (!input.eof()) {

if (tcol!=col-1) {

getline(input, line, ',');

convert << line;

convert >> temp;

Map[trow][tcol] = temp;

tcol++;

convert.str("");

convert.clear();

}

else {

getline(input, line, ' ');

convert << line;

convert >> temp;

Map[trow][tcol] = temp;

convert.str("");

convert.clear();

tcol = 0;

trow++;

}

if (trow == row)break;

}

input.close();

}

void MAZE::printMaze()

{

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

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

if (i == 0||i==row-1) {

cout << "==";

}

else if (j == 0 || j == col - 1) {

cout << "||";

}

else {// maze display on screen

switch (Map[i][j])

{

case 1:cout << "=="; break;

case 0:cout << " "; break;//There is way

case 200:cout << "s "; break;// starting point

case 201:cout << "e "; break;// destination

case -1:cout << "XX"; break;//good road

default:cout << "o "; break;//not in maze board

}

}

}

cout << endl;

}

}

void MAZE::printRoad()

{

//find start and end

int sr, sc;

int er, ec;

int index1, index2;

int **copy;//

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

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

if (Map[i][j] == 200) {

sr = i;

sc = j;

}

if (Map[i][j] == 201) {

er = i;

ec = j;

}

}

}

index1 = sr;

index2 = sc;

//save map in copy

copy = new int*[row];

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

copy[i] = new int[col];

}

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

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

copy[i][j] = Map[i][j];

}

}

//a char vector

vectorroute;

char way;//Th right path

while (sr != er || sc != ec) {

way=find(copy, &sr, &sc, row, col,route);

route.push_back(way);

}

//change the original map

for (int i = 0; i < route.size(); i++) {

switch (route[i])

{

case'r':

index2++;

if (Map[index1][index2] > 201)bouns++;

Map[index1][index2] = -1;

break;

case'l':

index2--;

if (Map[index1][index2] > 201)bouns++;

Map[index1][index2] = -1;

break;

case'u':

index1--;

if (Map[index1][index2] > 201)bouns++;

Map[index1][index2] = -1;

break;

case'd':

index1++;

if (Map[index1][index2] > 201)bouns++;

Map[index1][index2] = -1;

break;

}

}

printMaze();//

cout << "Total treasure is " << bouns << "Congrats!!" << endl << endl;

}

-----------------------------------------------------------------main.cpp-------------------------------------------------------------------------------------------------------------------------------

#include

#include

#include"Maze.h"

using namespace std;

int main()

{

MAZE test;

test.readMaze();

test.printMaze();

cout << "Wait a second..." << endl;

Sleep(1000);

test.printRoad();

system("pause");

}

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

12,12 1,1,1,1,1,1,1,1,1,1,1,1 1,200,0,0,0,0,0,0,0,0,0,1 1,0,1,1,1,1,1,1,1,1,0,1 1,0,0,1,0,0,0,0,0,0,0,1 1,1,0,1,1,1,1,0,1,1,1,1 1,0,0,0,0,0,0,0,0,0,0,1 1,0,1,1,1,0,1,1,1,1,0,1 1,0,1,0,1,0,0,0,0,0,0,1 1,0,0,0,1,0,1,1,1,1,1,1 1,0,1,0,1,0,1,0,0,0,0,1 1,0,1,0,1,0,0,0,1,0,201,1 1,1,1,1,1,1,1,1,1,1,1,1

--------------------------------------------------------------------------Original Problem-------------------------------------------------------------------------------------------

Array representation of a maze

Store and print a maze which includes

?Walls as 1

?Pavements as 0

?A starting point 200

?A destination 201

?Bonus points 202+

Input format

?col,row

?maze

Maze Representation

Requirement:

?Read a maze from a given text file

?Generate a maze with the input size and start/dest positions

?Add bonus points

?Print a maze on the screen

?Show a route from the starting point to the destination using X mark

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!