Question: Edit the c + + code so that the output looks like this: Sample Run: Nodes [ 2 - 2 6 ] : 7 Edges:
Edit the c code so that the output looks like this:
Sample Run:
Nodes :
Edges:
Edge values: HC GH AB BF BC FG CD DA
The network:
ABF
DCHG
Run Again YN: n
#include
#include
#include
#include
#include
using namespace std;
Function to validate and parse the edge input
bool parseEdgesint n map& adjList
string edge;
for int i ; i n; i
cin edge;
if edgelength edge edge edgeA edgeZ edgeA edgeZ
cout "Invalid edge input: edge endl;
return false;
Assuming undirected graph, add edge in both directions
adjListedgeinsertedge;
adjListedgeinsertedge;
return true;
Function to draw the network based on the adjacency list
void drawNetworkconst map& adjList
vector gridZA vectorZA;
Draw horizontal edges
for auto& node : adjList
char currentNode node.first;
for char connectedNode : node.second
if currentNode connectedNode
int x currentNode A;
int y connectedNode A;
gridxy;
gridxy ;
Draw vertical edges
for auto& node : adjList
char currentNode node.first;
for char connectedNode : node.second
if currentNode connectedNode
int x currentNode A;
int y connectedNode A;
gridxy;
Add corner labels
gridA;
gridZAB;
gridZAZAC;
gridZAD;
gridZAE;
gridZAF;
gridZAZAG;
gridZAH;
Print the grid
for int i ; i grid.size; i
for int j ; j gridisize; j
cout gridij;
cout endl;
Main function
int main
char runAgain Y;
do
int m n;
cout "Nodes : ;
cin m;
if m m
cout "Invalid number of nodes. Please enter a value between and ;
continue;
cout "Edges: ;
cin n;
if n
cout "Invalid number of edges. Please enter a positive number.";
continue;
map adjList; Adjacency list to store the graph
cout "Edge values: ;
if parseEdgesn adjList
cout "Error parsing edges. Please try again.";
continue;
Drawing the network
cout
The network:
;
drawNetworkadjList;
Clear the input buffer
cin.ignorenumericlimits::max
;
Asking the user if they want to run the program again
cout "Run Again YN: ;
cin runAgain;
runAgain toupperrunAgain;
while runAgain Y;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
