Question: IN C + + PLEASE I need help outputting the code correctly as seen in the image. The code should read two node IDs from
IN C PLEASE I need help outputting the code correctly as seen in the image. The code should read two node IDs from the console one per line Then, it must list the IDs of the resistors that are directly connected to the two nodes. For example, if the input is
N
N
then the output should be
R
If the nodes are not adjacent and therefore no resistors are connected to both nodes a message should be printed as in the following example. Input:
N
N
Output:
No resistors found.
My Code:
#include
#include
#include
using namespace std;
struct Resistor
string ID;
double resistance;
;
struct Node
string ID;
bool ground;
vector connections; Change vector type to Resistor
;
void findresistorsstring n string n vector& nodes
bool found false;
for const auto& node : nodes
if nodeID n node.ID n
for const auto& connection : node.connections
for const auto& othernode : nodes
if othernode.ID n othernode.ID n
if othernode.ID node.ID
for const auto& otherconnection : othernode.connections
if connection otherconnection
cout connectionID ;
found true;
if found
cout No resistors found.";
cout endl;
int main
string n n;
Read two node IDs from cin
cin n n;
Resistors
Resistor rR;
Resistor rR;
Resistor rR;
Resistor rR;
Resistor rR;
Resistor rR;
Nodes
vector nodes;
nodesID N;
nodesground true;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
nodesID N;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
nodesID N;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
nodesID N;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
nodesID N;
nodesconnections.pushback&r;
nodesconnections.pushback&r;
Call findresistors
findresistorsnn nodes;
return ;
TIngrad
II
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
