double Node::ConvertChar(char key[]) 
{ 
double value;
value=atof(key);
return value;
}

void Node::ConvertFormula(string formula,int resistor,vector <Resistor> &Res,vector <double> &OpArray){ 
int Operator=resistor-2;               
resistor=resistor-1;                    
int length=formula.length();
int j=length-4;
double resistance;
while(length>0)
{
    char temp[3]; int x=1;        
    for(int i=2;i>=0;i--)
    {
        temp[i]=formula[length-x];     
        x++;
    }
    resistance=ConvertChar(temp);          
    Res[resistor].SetResistance(resistance);
    resistor--;                          
    while(j>0)                        
    {                               
        if(formula[j]=='+')
        {                             
            OpArray[Operator]=-1.0;
        }else
        {
            OpArray[Operator]=-2.0;
        }
        Operator--;
        j=j-4;
    }
    length=length-4;
}
 }

Node* Node::StoreFormula(int Tcomponent,vector <Resistor> &Res,vector <double> &OpArray,int Operator) {
node* root=NULL; int x=Operator-1;
for(int i=Tcomponent;i>0;i--)
   {
 if(i%2==0)                             
 {
    double OperatorValue=OpArray[x];     
    root=insertNode(root,OperatorValue);
     x--;
 }else
 {
    root=insertNode(root,Res[Operator].getResistance());  
    Operator--;
 }
   }
   return root;
}

Node* Node::GenerateRandomCircuit(Node* root,vector <Resistor>&Res,vector <double>&OpArray,int& resistor,int& Operator) {    
 resistor=RandomResistor();
 Operator=resistor-1;
 Res.resize(resistor);
 OpArray.resize(Operator);
 SetRandomResistance(resistor,Res,Operator);
 SetOperator(OpArray,Operator);
 int Tcomponent=Operator+resistor;
 root=StoreFormula(Tcomponent,Res,OpArray,Operator);
 return root; 
 }

Node* Node::EnterFormula(Node* root,vector <Resistor>&Res,vector <double>&OpArray,int& resistor,int& Operator) { 
int length; string formula; int i; 
int Tcomponent;
cout<<"Enter circuit formula : ";
 cin>>formula;
 length=formula.length();
 Operator=0; i=length-4;
 while(i>0)
  {
 if(formula[i]=='+'||'/')
  {
     Operator++;
   }
   i=i-4;
}
resistor=(length-Operator)/3;
Tcomponent=Operator+resistor;
Res.resize(resistor);
OpArray.resize(Operator);
ConvertFormula(formula,resistor,Res,OpArray);
root=StoreFormula(Tcomponent,Res,OpArray,Operator);
return root; 
}

Can anyone explain the coding? Because i am having problem to understand it and by the way this program is about binary tree

I think you should have commented your code as you wrote it. Unless there is more story to be told such as "I found this code and I don't understand it."

Also this seems to be a follow on to https://www.daniweb.com/programming/computer-science/threads/522826/random-generation-of-circuit#post2261672 since I see mention of resistors in this code.

The assignment as told by you there does seem to give you an excellent out. Some may call that a cheat but hey, you'll learn something like:
"Live by the specifications, die by the specifications."

I think that the OP is saying they were presented with this code, either by their professor or they found it online, and they’re having a hard time following it. They want to learn so they’re asking can someone walk them through this code step by step. I guess by commenting it??

That’s my guess. I did a lot of that back when I used to tutor.

commented: Thanks Dani. Once in a while I get legacy apps to fix. Then I have to reverse engineer to see what the intent was. Here, the OP gets to explain more. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.