Wherever values are stored or used in calculations, change the type int to bool. In particular, rewrite IStack (call it BStack) to store bool values. Here’s the relevant fragment of Calculator::Execute:
bool b2 = _stack.Pop ();
if (token == '!')
{
_stack.Push (!b2);
status = true;
}
else
{
bool b1;
// Special case, when only one number on the stack:
// use this number for both operands.
if (_stack.IsEmpty ())
b1 = b2;
else
b1 = _stack.Pop ();
_stack.Push (Calculate (b1, b2, token));
status = true;
}
This is the Calculate method:
bool Calculator::Calculate (bool b1, bool b2, int token) const
{
bool result;
if (token == '&')
result = b1 && b2;
else if (token == '|')
result = b1 || b2;
return result;
}