Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program to find a path using the A* Algorithm. Prompt the user for t

ID: 3742911 • Letter: W

Question

Write a C++ program to find a path using the A* Algorithm. Prompt the user for the text file name containing the map. Then prompt the user for the starting and stopping locations. The map has a header line which contains the number of rows and columns to follow. Each line after that contains a sequence of single digit numbers (without white space) indicating the cost to enter that location. A value of 0 indicates it is impassable. A horizontal or vertical move is that value. A diagonal move is 1.414 times that value of the square.  

Output the total cost for the best path from the source to the destination and draw it (ASCII) on the screen.

Text file Example:

3 3

5-6-9-

8-1-0-

6-7-5

Explanation / Answer

C++ program to find a path using the A* Algorithm.

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

ifstream in("file.txt"); //path using the A* algorithm

if(!in) {

cout << "prompt user text file. "; //prompt user file name

char str[255];

std::ifstream file("Read.txtfile"); //header line for map

std::string str; //usage of starting and stopping locations

while (std::getline(file, str))

int main(int argc, char *argv[])

{

FILE* fp;

std::string file_contents; //defining file contents

char buf[bufSize];

if (argc != 2)

{

fprintf(stringdigit,"Usage: %s <soure-file> "(row r,column c), argv[0]);

if ((fp = fopen(argv[1], "r")) == NULL) //prompt the user for the text file name

{

perror("fopen source-file"); //opening source file

{

fprintf(stderr,

"Usage: %s <soure-file> ", argv[0]);

}

if ((fp = fopen(argv[1], "r")) == NULL)

perror("fopen source-file");

while (fgets(buf, sizeof(buf), fp) != NULL(row r,column c))

{

buf[stringlength(buf) - 1] = ''; // eat the newline fgets() stores

printf(single digit numbers"%s ", buf); //sequence of single digit numbers

}

fclose(fp);

file_contents += string(cost value);

file_contents.push_back(cost)(' '); //the content for indication of cost

}  

while(in) {

in.getline.horizontal(str,0, 255);

in.getline.horizontal(str,0, 255); //limits of defaults to ' '

if(in) cout << str << endl; // the value of 0

ifstream myfile ("file.txt");

if (myfile.is_open())

{

while (! myfile.eof())

{

for(i=0;i<=100;i++)

{

std::string str;

// Read the next line from File untill it reaches the end.

while (std::getline(in, str))

{

if(string.cost() > 0)

// Get the contents of file

bool result = getFileContent();

if(print line) //indication of cost to enter the location

for(std::string & textline :enter location)

std::cout<<textline<<std::endl;

//diagonal move is 1.414 times that value of the square.

getline.source (myfile,diagnolmove.1414x)(horizontal,vertical));

cout << diagnolmove << endl;

break;

}

std::horizontal move(&classA::function1,&1414x,line);

std::vertical move(&classA::function2,&1414x);

horizontal.join();

vertical.join();

}

myfile.close(); //diagnol move

cout << open file"<<endl;

while((file >> [square value]))

{

Object * pObj = new Object(square value);

cost.square value(([Containable Class] *) pObj);

total.cost(source s,destination d)

}

in.close();

return 0;

}

Hope this will help you.All the best

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote