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;