\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>#include<\/span> <iostream><\/span>\n<\/tt>using namespace std;\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nDefining the Node Class<\/h2>\nFor the node<\/b> class we need 5 private variables: type<\/i><\/b>, value<\/i><\/b>, node1<\/i><\/b>, node2<\/i><\/b>, next<\/i><\/b>, a constructor<\/b>, 5 member functions<\/b>, and a friend class<\/b>.<\/p>\n Because most of the functions only return a single variable it would be a waste to have the functions outside the class so I put them all inside the class.<\/p>\n So here is what your class should look like:<\/p>\n \n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt>25<\/strong>\n<\/tt>26\n<\/tt>27\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>class node\n<\/tt>{\n<\/tt> protected:<\/span>\n<\/tt> int<\/span> type; \/\/ type of component<\/span>\n<\/tt> double<\/span> value; \/\/ value of the component<\/span>\n<\/tt> int<\/span> node1; \/\/ first node of the component<\/span>\n<\/tt> int<\/span> node2; \/\/ second node of the component<\/span>\n<\/tt> node *next; \/\/ pointer to the next node in list<\/span>\n<\/tt> public:<\/span>\n<\/tt> node(int<\/span> a, double<\/span> b, int<\/span> c, int<\/span> d)\n<\/tt> {\n<\/tt> type = a;\n<\/tt> value = b;\n<\/tt> node1 = c;\n<\/tt> node2 = d;\n<\/tt> }\n<\/tt>\n<\/tt> int<\/span> getType() { return<\/span> type; }\n<\/tt> double<\/span> getValue() { return<\/span> value; }\n<\/tt> int<\/span> getNode1() { return<\/span> node1; }\n<\/tt> int<\/span> getNode2() { return<\/span> node2; }\n<\/tt> node *getNext() { return<\/span> next; }\n<\/tt>\n<\/tt> friend class circuit;\n<\/tt>};\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nDefining the Circuit Class<\/h2>\nFor the circuit<\/b> class we need 2 private variables: first<\/i><\/b> and last<\/i><\/b>, a constructor<\/b>, a copy constructor<\/b>, 6 member functions<\/b>, and a friend function<\/b>.<\/p>\n For these I will put most of the functions on the outside of the class.<\/p>\n So here is what your class should look like:<\/p>\n \n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>class circuit\n<\/tt>{\n<\/tt> protected:<\/span>\n<\/tt> node *first; \/\/ pointer to first node in list<\/span>\n<\/tt> node *last; \/\/ pointer to last node in list<\/span>\n<\/tt> node *getNode(int<\/span> & , double<\/span> & , int<\/span> & , int<\/span> & );\n<\/tt> public:<\/span>\n<\/tt> circuit();\n<\/tt> circuit(const<\/span> circuit & );\n<\/tt> ~circuit();\n<\/tt>\n<\/tt> void<\/span> insert(int<\/span> , double<\/span> , int<\/span> , int<\/span> );\n<\/tt> void<\/span> insertInFront(node * );\n<\/tt> void<\/span> insertInBack(node * , node * );\n<\/tt> void<\/span> insertInMiddle(node * , node * , node * );\n<\/tt> bool<\/span> remove(int<\/span> , int<\/span> );\n<\/tt> bool<\/span> isEmpty();\n<\/tt>\n<\/tt> friend ostream & operator << (ostream & , circuit );\n<\/tt>};\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nWriting the Actual Functions for the Circuit Class<\/h2>\nFirst, we have the private function getNode<\/b>. This function creates a new member of the node<\/b> class and returns the address to it.<\/p>\n\n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>node* circuit::getNode(int<\/span> &t, double<\/span> &v, int<\/span> &n1, int<\/span> &n2)\n<\/tt>{\n<\/tt> node *temp = new node(t, v, n1, n2);\n<\/tt> assert( temp != 0<\/span> );\n<\/tt> return<\/span> temp;\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nSecond, we have the a constructor<\/b>, a copy constructor<\/b>, and a class destructor<\/b>:<\/p>\n\n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt>25<\/strong>\n<\/tt>26\n<\/tt>27\n<\/tt>28\n<\/tt>29\n<\/tt>30<\/strong>\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>circuit::circuit()\n<\/tt>{\n<\/tt> first = last = 0<\/span>;\n<\/tt>}\n<\/tt>circuit::circuit(const<\/span> circuit &c)\n<\/tt>{\n<\/tt> first = last = | | | | | | | | | |