Question

using c++ (NO STL libraries) create a program that will ask the user to enter two...

using c++ (NO STL libraries) create a program that will ask the user to enter two values (percent of free squares in the maze and the side dimensions of the maze) that will build a maze according to what the user enters. Along with asking the user these questions also ask the user the location they want to place the character inside the maze as well as the exit of the maze. In the maze free cells are blank. cells with obstacles are #. (You dont have to solve the maze)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{

//declear all varible for maz dimenation, obstacles count and their position
int height,width;
int obsCount;
int x, y;
std::cout << "Please Enter height of maze " ;
cin>>height;
std::cout << "Please Enter width of maze " ;
cin>>width;
char **mat=new char*[width]; //declear maze
for( int i=0;i<height;i++){
mat[i]=new char[width]; //intialize maze
}
//intialize maze position at start with zero
for( int i=0;i<height;i++){
for(int j=0;j<width;j++){
mat[i][j]='0';
}
}
//ask user how many obstacles they want to put
std::cout << "At how many location you want to put obstacles " ;
cin>>obsCount;
if(obsCount>(width*height)){
cout<<"Too many position"; //if number of cells less than
return 0; //obstacles enteres exit
}
//take input for x,y position for each obstacles
for(int i=0;i<obsCount;i++){
std::cout << "Please enter x position of obstacles " ;
cin>>x;
if(x>height){
cout<<"x position is greater than width";
return 0;
}
std::cout << "Please enter y position of obstacles " ;
cin>>y;
if(y>width){
cout<<"y position is greater than width";
return 0;
}
mat[x-1][y-1]='#'; //put # at that position with one lower index
//as array index is zero based
}
int ex,ey;
cout<<"Please enter exit of the maze";
cin>>ex;
cin>>ey;
mat[ex-1][ey-1]='E';
//print maze
for( int i=0;i<height;i++){
for(int j=0;j<width;j++){
cout<<mat[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}

output

Please Enter height of maze 4
Please Enter width of maze 5
At how many location you want to put obstacles 3
Please enter x position of obstacles 1
Please enter y position of obstacles 3
Please enter x position of obstacles 3
Please enter y position of obstacles 2
Please enter x position of obstacles 4 2
Please enter y position of obstacles 4
Please enter exit of the maze4 5
0 0 # 0 0
0 0 0 # 0
0 # 0 0 0
0 0 0 0 E


Add a comment
Know the answer?
Add Answer to:
using c++ (NO STL libraries) create a program that will ask the user to enter two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 30. Create a program that will create a "number battle" between two users. Ask each user to enter three numbers that sum to a maximum of 30. Then the program will compare each users 1st, 2nd...

    30. Create a program that will create a "number battle" between two users. Ask each user to enter three numbers that sum to a maximum of 30. Then the program will compare each users 1st, 2nd and 3rd number and determine who won each battle. For instance if user A enters 18,11,1 and user B enters 6,17,7 then user B would win because they won 2 of 3 battles. Have a check to see if the sum to 30 rule...

  • Please help: For this project, you will create a shape drawing program using Turtle graphics. Your...

    Please help: For this project, you will create a shape drawing program using Turtle graphics. Your program will begin by asking the user how many points they would like to enter (# of vertices for the shape). Next, you will use a loop to input each X and Y coordinate and store these coordinates in lists. After inputting all of the coordinates, create a second loop that will draw and fill the shape using the coordinates that were entered. All...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have...

    C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have 2 Labels (each one of them assigned only to Celsius and Fahrenheit), 2 TextBoxes (each one of them assigned only to Celsius and Fahrenheit), only 1 Convert Button, 1 Clear Button, and 1 Exit Button. Also, 1 Error message label which will display the error messages. The application should only allow the user to enter the desired temperature just in one of the TextBoxes...

  • Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the...

    Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...

  • The goal is to create a code for implementing a Columns game using pygame Your program...

    The goal is to create a code for implementing a Columns game using pygame Your program will read its input via the Python shell (i.e., using the built-in input() function), printing no prompts to a user with no extraneous output other than precisely what is specified below. The intent here is not to write a user-friendly user interface; what you're actually doing is building a tool for testing your game mechanics, which we'll then be using to automatically test them....

  • Maze Solving with Stacks Problem Statement Consider a maze made up of rectangular array of squares,...

    Maze Solving with Stacks Problem Statement Consider a maze made up of rectangular array of squares, such as the following one: X X X X X X X X X X X X X           X            X X X X    X X X           X               X     X X X     X X    X    X     X     X X X         X          X             X X X     X X X X X                X X X X X X X X X X X X X Figure...

  • Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person...

    Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT