Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I do not know my C++ code does not want to debug. The code is good but does not want to compile in visual

Hi, I do not know my C++ code does not want to debug. The code is good but does not want to compile in visual studio 2015. Nobody could give me the fix. Please show a picture of the visual studio working correctly. I tried a lot of things and asked and I could not resolve the problem.

#include

#include

#include

#include

#include

#include

using namespace std;

void addEdge(vector > adj[], int u,

int v, int wt)

{

adj[u].push_back(make_pair(v, wt));

adj[v].push_back(make_pair(u, wt));

}

// Print adjacency list representaion ot graph

void printGraph(vector > adj[], int V)

{

int v, w;

for (int u = 0; u

{

cout

for (auto it = adj[u].begin(); it != adj[u].end(); it++)

{

v = it->first;

w = it->second;

cout

}

cout

}

}

// This function mainly does BFS and prints the

// shortest path from src to dest. It is assumed

// that weight of every edge is 1

void findShortestPath(vector > adj[],int src, int dest, int V, int &total)

{

// Mark all the vertices as not visited

bool *visited = new bool[2 * V];

int *parent = new int[2 * V];

// Initialize parent[] and visited[]

for (int i = 0; i

{

visited[i] = false;

parent[i] = -1;

}

// Mark the current node as visited and enqueue it

visited[src] = true;

int v, w, smallest = INT_MAX;;

for (int u = 0; u

{

smallest = INT_MAX;

for (int j = 0; j

{

if (adj[u][j].second

{

if (adj[u][j].second

smallest = adj[u][j].second;

visited[adj[u][j].first] = true;

}

}

else if (visited[adj[u][j + 1].first] == false)

{

if (adj[u][j + 1].second

smallest = adj[u][j + 1].second;

visited[adj[u][j + 1].first] = true;

}

}

if (adj[u][j].first == dest)

{

total += adj[u][j].second;

return;

}

else if (adj[u][j + 1].first == dest)

{

total += adj[u][j + 1].second;

return;

}

}

total += smallest;

}

}

// Driver code

int main()

{

vector > adj[6];

int V = 6;

string line;

ifstream myfile("file.txt");

vector vertex;

int count = 1;

if (myfile.is_open())

{

while (getline(myfile, line))

{

cout

while (line != "-1")

{

char *token = strtok(const_cast(line.c_str()), " ");

token = strtok(NULL, " ");

vertex.push_back(token);

getline(myfile, line);

cout

}

V = vertex.size();

getline(myfile, line);

cout

while (line != "-1")

{

char *token = strtok(const_cast(line.c_str()), " ");

int u = atoi(token);

int v = atoi(strtok(NULL, " "));

int w = atoi(strtok(NULL, " "));

addEdge(adj, u, v, w);

getline(myfile, line);

cout

}

}

myfile.close();

}

else cout

string start, end;

cout

cin >> start;

cout

cin >> end;

int s, e;

int i = 0;

for (auto it = vertex.begin(); it != vertex.end(); it++)

{

if (*it == start) s = i;

if (*it == end) e = i;

i++;

}

//printGraph(adj, V);

int total = 0;

findShortestPath(adj, s, e, V, total);

cout

//printGraph(adj, V);

system("pause");

return 0;

}

Picture:

image text in transcribed

AC4018 'signed/unsigned mismatch C4101:unreferenced local variable C4101 w unreferenced local variable C4996 strtok: This function or variable may be unsafe. Consider using strtok s instead. To disable deprecation, use C4996 strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use C4996 strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use C4996 'strtok': This function or variable may be unsafe. Consider using strtok s instead. To disable deprecation, use C4996 strtok: This function or variable may be unsafe. Consider using strtok s instead. To disable deprecation, use CRT_SECURE_NO_WARNINGS. See online help for details. _CRT SECURE_NO WARNINGS. See online help for details. CRT_SECURE NO WARNINGS. See onine help for details CRT SECURE_NO WARNINGS. See online help for details CRT SFCURF NO WARNINGS. See online heln for details

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago

Question

how would you have done things differently?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago