QuestionQuestion

Hand in hard copy of your code. Be prepared to run your code in class.

Write a program that creates a 10 by 10 maze. Represent the maze as an array of characters, where ‘*’ is a wall. Here is an example:

char maze[10][10] =
{ {'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*' },
{'*', '*', ' ', '*', '*', '*', ' ', '*', ' ', '*' },
{'*', '*', ' ', '*', '*', '*', '*', '*', '*', '*' },
{'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*' },
{'*', '*', '*', '*', '*', '*', '*', ' ', '*', '*' },
{'*', '*', '*', ' ', '*', '*', '*', ' ', '*', '*' },
{'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
{'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' }
};

Here is an example display. The entrance is on the upper left and the exit is on the lower right:

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

Later we will add a robot and, using random numbers, have it find a path out of the maze.

OPTIONAL
Store your maze in a text file, and read it in rather than initializing it in your code.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <cstdlib>
#include <iostream> /// for cout cin
#include <fstream> // for file reading
using namespace std;

// size of maze
#define SIZE 10

void printMaze(char maze [][SIZE]) {
    int i;
    int j;
    // iterate over rows
    for (i = 0; i < SIZE; i++) {
       // iterate over columns
       for (j = 0; j < SIZE; j++) {
       // print the character
            cout << maze[i][j];            
       }
       cout << "\n";      
    }
}

void readMaze(char maze [][SIZE]) {
    char name[20];
    fstream file;
    char c;
    int i, j;
   
    // read file name
    cout << "Enter name of file that contains the maze: ";
    cin >> name;   
   
    // open file
    file.open(name, ios::in);   
   
    if (file.is_open()) { // file can be opened
      
       // read maze.
       // assume that the input is legal
       for (i = 0; i < SIZE; i++) {...

By purchasing this solution you'll be able to access the following files:
Solution.cpp.

$18.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats