Microsoft Word - 211_Assignment_2.docx Assignment #2 Due October 18th 60 points You can write your programs in the environment of your preference (e.g. Visual Studio, or Unix). Turn in your source...

1 answer below »
I need little help on question number 3


Microsoft Word - 211_Assignment_2.docx Assignment #2 Due October 18th 60 points You can write your programs in the environment of your preference (e.g. Visual Studio, or Unix). Turn in your source code files via Blackboard by submitting a single zip file LASTNAME_assignment_2.zip. This zip file should contain a folder containing the source code for each problem. The zip file should also contain a LASTNAME_README.txt file that describes how to run each program as well as what doesn't work. 1) System Crash – 10 pts The following C++ code has a problem where the loop can exceed the size of the array if the user inputs too many numbers. #include using namespace std; int main() { int nums[20] = { 0 }; int a[10] = { 0 }; cout < a="">< endl;="" cout="">< nums="">< endl;="" cout="">< "how="" many="" numbers?="" (max="" of="" 10)"="">< endl;="" cin="">> nums[0]; for (int i = 0; i < nums[0];="" i++)="" {="" cout="">< "enter="" number="" "="">< i="">< endl;="" cin="">> a[i]; } // Output the numbers entered for (int i = 0; i < 10;="" i++)="" cout="">< a[i]="">< endl;="" return="" 0;="" }="" if="" this="" program="" is="" run="" and="" we="" enter="" 255="" for="" how="" many="" numbers,="" and="" 9="" for="" every="" single="" number,="" then="" the="" program="" does="" something="" like="" this:="" how="" many="" numbers?="" (max="" of="" 10)="" 255="" enter="" number="" 0="" 9="" enter="" number="" 1="" 9="" enter="" number="" 2="" 9="" enter="" number="" 3="" 9="" enter="" number="" 4="" 9="" enter="" number="" 5="" 9="" enter="" number="" 6="" 9="" enter="" number="" 7="" 9="" enter="" number="" 8="" 9="" enter="" number="" 9="" 9="" enter="" number="" 10="" 9="" enter="" number="" 11="" 9="" enter="" number="" 12="" 9="" 9="" 9="" 9="" 9="" 9="" 9="" 9="" 9="" 9="" (program="" may="" crash="" at="" this="" point,="" or="" possibly="" just="" exit)="" your="" results="" may="" vary,="" depending="" on="" what="" compiler,="" operating="" system,="" and="" cpu="" that="" you="" are="" using.="" if="" the="" program="" does="" not="" crash="" on="" your="" compiler,="" try="" it="" on="" transformer="" or="" the="" windows="" machines="" in="" the="" lab="" and="" you="" should="" get="" the="" behavior="" shown="" above.="" why="" didn't="" the="" program="" loop="" 255="" times?="" your="" answer="" should="" be="" detailed="" and="" reference="" the="" way="" in="" which="" memory="" is="" organized="" and="" what="" is="" put="" into="" memory.="" 2)="" maze="" solving="" –="" 20="" pts="" start="" with="" the="" computer="" maze-solving="" program="" covered="" in="" class.="" the="" source="" code="" is="" posted="" along="" with="" the="" homework.="" 1.="" change="" the="" dimensions="" of="" the="" maze="" to="" 20x20="" with="" walls="" around="" the="" borders.="" out="" of="" the="" empty="" space="" in="" the="" middle,="" randomly="" fill="" 25%="" of="" them="" with="" walls.="" then="" pick="" a="" random="" start="" location="" (that="" is="" empty)="" and="" a="" random="" exit="" location="" (that="" is="" empty).="" since="" you="" are="" using="" random="" numbers,="" you="" should="" get="" a="" different="" maze="" with="" a="" different="" start="" and="" end.="" there="" is="" a="" small="" chance="" that="" it="" is="" impossible="" to="" get="" from="" the="" start="" to="" the="" exit,="" but="" don't="" worry="" about="" that="" possibility="" (when="" the="" program="" runs="" it="" should="" just="" not="" print="" any="" solution).="" 2.="" the="" algorithm="" we="" covered="" in="" class="" prints="" out="" the="" path="" from="" the="" start="" to="" the="" exit="" in="" reverse="" order.="" modify="" the="" program="" so="" the="" path="" is="" output="" in="" forward="" order.="" one="" way="" to="" do="" this="" is="" to="" make="" an="" array="" (or="" arrays)="" that="" store="" the="" (x,y)="" coordinates="" of="" the="" current="" position="" as="" the="" recursive="" function="" exits.="" with="" all="" of="" the="" coordinates="" in="" an="" array,="" inside="" the="" main="" function="" you="" can="" now="" loop="" through="" the="" array="" in="" the="" proper="" order="" to="" output="" the="" moves="" from="" start="" to="" exit.="" 3.="" your="" program="" should="" output="" a="" solution="" to="" the="" randomly="" generated="" maze,="" if="" one="" exists.="" 3)="" recursive="" maze="" generation="" –="" 20="" pts="" implement="" the="" following="" recursive="" algorithm="" to="" randomly="" generate="" a="" maze.="" in="" the="" example="" below="" i="" have="" made="" the="" maze="" 10x10="" to="" save="" space="" but="" your="" maze="" should="" be="" 40x40.="" start="" with="" a="" 2d="" array="" of="" char="" like="" we="" used="" previously="" and="" assign="" walls="" to="" the="" borders:="" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9="" 0="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" 1="" x="" x="" 2="" x="" x="" 3="" x="" x="" 4="" x="" x="" 5="" x="" x="" 6="" x="" x="" 7="" x="" x="" 8="" x="" x="" 9="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" call="" the="" recursive="" function="" with="" parameters="" that="" specify="" the="" blank="" area="" in="" the="" middle,="" in="" this="" case,="" highlighted="" by="" yellow="" below.="" you="" could="" do="" this="" a="" couple="" of="" ways,="" for="" example,="" pass="" in="" the="" coordinates="" of="" the="" upper="" left="" and="" lower="" right="" corner,="" or="" pass="" in="" the="" coordinate="" of="" the="" upper="" left="" corner="" plus="" the="" width="" and="" height="" of="" the="" area.="" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9="" 0="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" 1="" x="" x="" 2="" x="" x="" 3="" x="" x="" 4="" x="" x="" 5="" x="" x="" 6="" x="" x="" 7="" x="" x="" 8="" x="" x="" 9="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" if="" the="" width="" of="" the="" yellow="" area="" is=""><=2 cells="" or="" the="" height="" of="" the="" yellow="" area="" is=""><=2 cells then the function should return, doing nothing. this is the base case that terminates recursion. if the height of the yellow area is greater than or equal to the width of the yellow area, then the yellow area is either square or taller than it is wide. in this case, the idea is to draw a horizontal wall somewhere in the green area: 0 1 2 3 4 5 6 7 8 9 0 x x x x x x x x x x 1 x x 2 x x 3 x x 4 x x 5 x x 6 x x 7 x x 8 x x 9 x x x x x x x x x x by avoiding the top and bottom row of the yellow area, we prevent ourselves from drawing a wall that might box ourselves in by covering up a passageway. in the green area, randomly select a vertical position (in this case from y=2 to y=7) and draw a horizontal wall all the way across the green. in this example, i randomly selected y=3: 0 1 2 3 4 5 6 7 8 9 0 x x x x x x x x x x 1 x x 2 x x 3 x x x x x x x x x x 4 x x 5 x x 6 x x 7 x x 8 x x 9 x x x x x x x x x x next, check if the ends of the line we just drew are next to a blank. if so, make the end wall a blank. this is to allow passage through the blank instead of blocking it. in this example, check if (0,3) is a blank. if it is, then make (1,3) a blank. also check if (9,3) is a blank. if it is then make (8,3) a blank. there is no blank to add in this case. next, randomly select one of the cells in the wall that was added and turn it into a blank. this adds a hole to allow passage between the two halves of the maze separated by the new wall. in this example, i randomly cells="" then="" the="" function="" should="" return,="" doing="" nothing.="" this="" is="" the="" base="" case="" that="" terminates="" recursion.="" if="" the="" height="" of="" the="" yellow="" area="" is="" greater="" than="" or="" equal="" to="" the="" width="" of="" the="" yellow="" area,="" then="" the="" yellow="" area="" is="" either="" square="" or="" taller="" than="" it="" is="" wide.="" in="" this="" case,="" the="" idea="" is="" to="" draw="" a="" horizontal="" wall="" somewhere="" in="" the="" green="" area:="" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9="" 0="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" 1="" x="" x="" 2="" x="" x="" 3="" x="" x="" 4="" x="" x="" 5="" x="" x="" 6="" x="" x="" 7="" x="" x="" 8="" x="" x="" 9="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" by="" avoiding="" the="" top="" and="" bottom="" row="" of="" the="" yellow="" area,="" we="" prevent="" ourselves="" from="" drawing="" a="" wall="" that="" might="" box="" ourselves="" in="" by="" covering="" up="" a="" passageway.="" in="" the="" green="" area,="" randomly="" select="" a="" vertical="" position="" (in="" this="" case="" from="" y="2" to="" y="7)" and="" draw="" a="" horizontal="" wall="" all="" the="" way="" across="" the="" green.="" in="" this="" example,="" i="" randomly="" selected="" y="3:" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9="" 0="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" 1="" x="" x="" 2="" x="" x="" 3="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" 4="" x="" x="" 5="" x="" x="" 6="" x="" x="" 7="" x="" x="" 8="" x="" x="" 9="" x="" x="" x="" x="" x="" x="" x="" x="" x="" x="" next,="" check="" if="" the="" ends="" of="" the="" line="" we="" just="" drew="" are="" next="" to="" a="" blank.="" if="" so,="" make="" the="" end="" wall="" a="" blank.="" this="" is="" to="" allow="" passage="" through="" the="" blank="" instead="" of="" blocking="" it.="" in="" this="" example,="" check="" if="" (0,3)="" is="" a="" blank.="" if="" it="" is,="" then="" make="" (1,3)="" a="" blank.="" also="" check="" if="" (9,3)="" is="" a="" blank.="" if="" it="" is="" then="" make="" (8,3)="" a="" blank.="" there="" is="" no="" blank="" to="" add="" in="" this="" case.="" next,="" randomly="" select="" one="" of="" the="" cells="" in="" the="" wall="" that="" was="" added="" and="" turn="" it="" into="" a="" blank.="" this="" adds="" a="" hole="" to="" allow="" passage="" between="" the="" two="" halves="" of="" the="" maze="" separated="" by="" the="" new="" wall.="" in="" this="" example,="" i="">
Answered Same DayOct 19, 2021

Answer To: Microsoft Word - 211_Assignment_2.docx Assignment #2 Due October 18th 60 points You can write your...

Aditi answered on Oct 20 2021
145 Votes
problem3.cpp
#include
#include
#include
#include
using n
amespace std;
const int WIDTH = 40;
const int HEIGHT = 40;
void initialize(char maze[][WIDTH]);
void printMaze(char maze[][WIDTH]);
void mazeGenarator (char maze[][WIDTH], int x1, int y1, int x2, int y2);
void initialize(char maze[HEIGHT][WIDTH])
{
    for(int i=0; i        maze[0][i] = 'X';
        maze[HEIGHT-1][i] = 'X';
    }
    for(int i=1; i        maze[i][0] = 'X';
        for(int j=1; j            maze[i][j] = ' ';
        }
        maze[i][WIDTH-1] = 'X';
    }
}
void printMaze(char maze[][WIDTH])
{
    /*cout<    for(int i=0; i < WIDTH; i++){
        cout<    }*/
    cout< for (int i = 0; i < HEIGHT; i++)
    {
        //cout<        for (int j = 0; j < WIDTH; j++)
        {
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here