home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,185 of 2,978   
   Jim P to Bruce Roberts   
   Re: urgent help needed   
   02 Jun 06 14:11:46   
   
   XPost: comp.lang.c++, alt.comp.lang.borland-delphi   
   From: Jim_P@mad.scientist.com   
      
   Bruce Roberts wrote:   
   > "Gohar"  wrote in message   
   > news:1147001335.069654.302480@i39g2000cwa.googlegroups.com...   
   >   
   >>Any one please send me the C++ code for arithmatic calculator using   
   >>linked lists   
   >>Which performs addition ,subtraction,multiplication,division and   
   >>modulus(using operator overloading).   
   >>i need it badly,urgently before monday   
   >>please send it to my mail address   
   >>i shall be thankful ,   
   >   
   >   
   > I have no idea what such code might look like in C++ and my Delphi version   
   > doesn't support operator overloading. But the guts of what you ask for   
   > might look something like the following in D5.   
   >   
   >   
   > Type   
   > pStackRec = ^ tStackRec;   
   > tStackRec = record   
   >      rValue : double;   
   >      rLink  : pStackRec;   
   >      end;   
   > tCalcOp = (add, subtract, multiply, divide, modulo);   
   >   
   > var  CalcStack : pStackRec = nil;   
   >   
   > procedure PushStack (val : double);   
   >   
   > var  p    : pStackRec;   
   >   
   > begin   
   > New (p);   
   > p^.rLink := CalcStack;   
   > CalcStack := p;   
   > p^.rValue := val;   
   > end;   
   >   
   > function PopStack : double;   
   >   
   > var  p    : pStackRec;   
   >   
   > begin   
   > if CalcStack <> nil   
   > then result := CalcStack.rValue   
   > else raise Exception.Create ('Stack underflow');   
   > p := CalcStack;   
   > CalcStack := CalcStack^.rLink;   
   > Dispose (p);   
   > end;   
   >   
   > function StackCalc (op : tCalcOp) : double;   
   >   
   > var  p    : pStackRec;   
   >   
   > begin   
   > if CalcStack = nil   
   > then raise Exception.Create ('Emtpy Stack');   
   > p := CalcStack;   
   > result := 0.0;   
   > if op in [add .. modulo]   
   > then begin     // two operands required   
   >      CalcStack := CalcStack^.rLink;   
   >      if CalcStack = nil   
   >      then raise Exception.Create ('Missing operand');   
   >      case op of   
   >           add : result := CalcStack^.rValue + p^.rValue;   
   >           subtract : result := CalcStack^.rValue - p^.rValue;   
   >           multiply : result := CalcStack^.rValue * p^.rValue;   
   >           divide : result := CalcStack^.rValue / p^.rValue;   
   >           modulo : result := CalcStack^.rValue - ((CalcStack^.rValue /   
   > p^.rValue) * p^.rValue);   
   >           end;   
   >      Dispose (p);   
   >      CalcStack^.rValue := result;   
   >      end;   
   > end;   
   >   
   >   
   Why do this the hard way.   
      
   I showed a 10 year old kid how to do this in VB and then in Delphi.   
      
   Just put some edit boxes on the form.   
      
   and some buttons - - click a button does selected task. Cheap, Simply   
   and educational. The kid and friends played with it for hours - to the   
   mothers surprise. and the kid did the coding.   
      
   No stack or anything like that - - - but it worked and was a lesson for   
   the kid.   
      
   but then again this sounds like a home work assignment. - - -   
      
   Jim P   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca