Question: I am writing a c++ program that reads in a text file that looks like this: 9 14 1 2 4 1 8 8 2
I am writing a c++ program that reads in a text file that looks like this:
9 14 1 2 4 1 8 8 2 3 8 2 8 11 3 4 7 3 9 2 3 6 4 4 5 9 4 6 14 5 6 10 6 7 2 7 8 1 7 9 6 8 9 7
this file represents a directed graph. the first line indicates the number of vertices (9) and edges (14) , respectively. All lines below line one contain 3 integers that indicate information about an edge. There is an edge pointing from u to v with weight w (u v w).
The program reads in an edge weighted directed graph from file to build the adjacency lists.
I want to display the graph on the screen like this:

it displays information for each vertex, what other vertex it is connected to and the weight..
the program that i have written so far only prints 9 and 14...
int readFile () {
string line;
ifstream myfile ("GRAPH.txt");
if (myfile.is_open()) {
for (int lineno = 0; getline (myfile,line) && lineno
if (lineno == 0)
cout
myfile.close();
}
else cout
return 0;
}
How do I save 9 and 14 into variables numberofvertices and numberofedges? How do I print the rest of the graph in the sample format above? I would appreciate any help.The program should work for other text file examples not just the one above.
914 1:(88)(24) 2 : (811) (38) 3 : (64) (92) (47) 4 : (614) (59) 5 : (610) 6:(72) 7 : (96) (81) 8 : (97) 42 35 81411267 886667 9123456789
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
