Question: C + + program to draw a network as a two dimensional diagram giving bad output, please help. Code: #include #include #include #include #include using
C program to draw a network as a two dimensional diagram giving bad output, please help.
Code:
#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;
gridxminy y ;
Draw vertical edges
for char c A; c Z; c
if adjListcountc
int x c A;
int y ;
for char d A; d Z; d
if c d && adjList.atccountd
gridminx x y;
y ;
Print the grid
for int i ; i grid.size; i
for int j ; j grid.size; 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 endl;
continue;
cout "Edges: ;
cin n;
if n
cout "Invalid number of edges. Please enter a positive number." endl;
continue;
map adjList; Adjacency list to store the graph
cout "Edge values: ;
if parseEdgesn adjList
cout "Error parsing edges. Please try again." endl;
continue;
Drawing the network
cout
The network:
;
drawNetworkadjList;
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
