Write a C++ program, [login to view URL], that randomly finds a path from the center of a two dimensional array.
The program first initializes a two dimensional char array to all periods. The program starts at the middle of the array. It places an ‘a’ at this spot in the array. It then repeatedly picks a random direction (up, down, left or right) that travels to a spot not yet visited and places the next letter of the alphabet there. The program stops when the pathway reaches an edge of the array or there is no legal spot to move.
You are required to write the following functions to help solve the problem:
// set all spots in the board equal to period
// characters
void init_board (char board [max_row][max_col]);
// sets row and col equal to a new row and column using
// a random move (up, down, left or right) to a spot in
// the array not yet visited
void move (char box[max_row][max_col], int& row, int& col);
// prints the array in two dimensional format preceded by
// a label
void print (char box [max_row][max_col]);
max_row and max_col are constants giving the size of the array. The program should work for different values of max_row and max_col.
When the lowercase alphabet is exhausted, the markers should change to the uppercase alphabet. When the uppercase alphabet is exhausted, the markers should change back to lowercase alphabet, and so on.
If an edge of the array is reached, the word “Success” should be printed along with the array. When there is no legal move from a spot, the word “Failure” should be printed along with the array.
Two runs of the program with max_row = 20 and max_col = 50 are shown on the back of this handout. The program should run differently each run.
When done, place the [login to view URL] file in the Homework 2 Drop Box on Angel.
Run 1 (max_row = 20, max_col = 30):
Success!
The path is:
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
.........................vwzA.
...............a.........uxyBC
.............feb.....VWXst....
.............gdcPQRSTU.Yr.....
............ih..ON.....Zqp....
............juv..M.....ano....
..........mlktw.KLGF...bml....
..........norsxyJIHE...c.kji..
...........pq..zABCD...defgh..
..............................
..............................
..............................
Run 2 (max_row = 15, max_col = 30):
Failure!
The path is:
..............................
..............................
..............................
..............................
..............................
............gf................
............hedc..............
.........nmli..b..............
.........oxkj..a..............
.........pwv..................
.........q.u..................
.........rst..................
..............................
..............................
..............................