Im trying to write a C program using classes We have a class
I\'m trying to write a C++ program using classes. We have a class for Node and a class called Resistor. I\'m confused as to how I should assign the pointers so that the resistors can connect to the nodes. I am creating the arrays seperately in the main file but how would I access the different members of each class from the main?
2 Problem Statement Your task is to implement a program for storing resistors in a circuit. The circuit, or network, is defined by a number of nodes, each node being connected to one or more resistors. Each resistor has certain values associated with it, including: resistance value, text name, and the IDs of the two nodes (endpoints) it connects. The diagram below (Fig 1) illustrates an example. Here Rl connects nodes 1 and 2, R2 does the same, and R3 connects nodes 1 and 3. The nodes could be strips on a breadboard for example, with resistors plugged in to some nodes. The program you will write is similar to the \"input-and-store-the-network\" portion of real programs used to simulate electric circuits, and programs that control the robots that automatically insert resistors connecting the appropriate points (nodes) on circuit boards 2 R1 Node ! Resistor R3Solution
Answer:
Note: User asked main program.
#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>
#include \"Resistor.h\"
#include \"Node.h\"
using namespace std;
int main()
{
Node *nodeAry[3];
Resistor *ResistorAry[3];
//create 3 nodes
for(int kk=0;kk<3;kk++)
{
nodeAry[kk]=new Node;
}
//create end points
int endpoints1[2]={0,1};
int endpoints2[2]={0,1};
int endpoints3[2]={0,2};
//create 3 resistors
ResistorAry[0]=new Resistor(1, \"R1\",10,endpoints1);
ResistorAry[1]=new Resistor(2, \"R2\",5,endpoints2);
ResistorAry[2]=new Resistor(3, \"R3\",15,endpoints3);
//add resistors to node1
nodeAry[0]->addResistor(0); //Add resistor 1
nodeAry[0]->addResistor(1); //Add resistor 2
nodeAry[0]->addResistor(2); //Add resistor 3
//add resistors to node2
nodeAry[1]->addResistor(0); //Add resistor 1
nodeAry[1]->addResistor(1); //Add resistor 2
//add resistors to node3
nodeAry[2]->addResistor(2); //Add resistor 3
//Now print resistors details
for(int kk=0;kk<3;kk++)
{
ResistorAry[kk]->print();
}
//Print node details
for(int kk=0;kk<3;kk++)
{
nodeAry[kk]->print();
}
return 0;
}


