本文整理汇总了C++中Input::Number方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::Number方法的具体用法?C++ Input::Number怎么用?C++ Input::Number使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input::Number方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
bool Calculator::Execute (Input const & input)
{
int token = input.Token();
bool status = false;
if (token == tokError) {
std::cout << "Unknown token\n";
}
else if (token == tokNumber) {
if (_stack.IsFull()) {
std::cout << "Stack is full \n";
}
else {
_stack.Push(input.Number());
status = true;
}
}
else { //operator
assert(token == '+' || token == '-' || token == '*' || token == '/');
if(_stack.IsEmpty()) {
std::cout << "Stack is empty\n";
}
else {
int num2 = _stack.Pop();
int num1;
if(_stack.IsEmpty()) //2 operator will be same once there is only 1 data left in stack
num1 = num2;
else
num1 = _stack.Pop();
_stack.Push(Calculate(num1, num2, token));
status = true;
}
}
return status;
}
示例2: Execute
bool Calculator::Execute( Input& input )
{
int token = input.Token();
bool status = false;
if(token == Input::tokError ){
cout <<"Unknown token " << endl;
}
else if(token == Input::tokNumber){
if(_stack.IsFull()){
cout <<"Stack is full " << endl;
}
else{
_stack.Push(input.Number());
status = true;
}
}
else if (token == Input::tokBool){
if (_stack.IsFull()){
cout << "Stack is full " << endl;
}
else{
_stack.Push(input.Bool());
status = true;
}
}
else if (token == 'x'){
status = true;
}
else if (token == 'r'){
_stack.Reset();
status = true;
}
else if(token == 'q'){
status = false;
}
else{
assert(token == '+' ||token == '-' ||token == '*' ||token == '/' || token == '&' || token =='|' || token == '^'
|| token == '!');
if(_stack.IsEmpty()){
cout <<"Stack is empty " << endl;
}
else{
int num2 = _stack.Pop();
int num1 =0;
if(_stack.IsEmpty())
num1 = num2;
else
num1 = _stack.Pop();
if (_type == NUMBER_CALC)
_stack.Push(Calculate(num1, num2, token));
else
_stack.Push(Calculate((bool)num1, (bool)num2, token));
status = true;
}
}
return status;
}