zoukankan
html css js c++ java
后缀运算器(已补全)
#include "mystack.h" #include <iostream> using namespace std; char get_command() { char command; bool waiting = true; cout << "Select command and press <ENTER> : "; while (waiting){ cin >> command; if (command == '?' || command == '=' || command == '+' || command == '-' || command == '*' || command == '/' || command == 'q') waiting = false; else{ cout << "Please enter a valid command:"<< endl << "[?]push to stack [=]print top" << endl << "[+][-][*][/]" << endl << "[q]exit." << endl; } } return command; } bool do_command(char command, Stack &numbers) { double p,q; switch (command){ case '?': cout << "Enter a real number." <<flush; cin >> p; if (numbers.push(p) == overflow) cout << "Waring :stack full,lost numbers" <<endl; break; case '=' : if(numbers.top(p) == underflow) cout << "Stack empty" <<endl; else cout << p <<endl; break; case '+': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ numbers.pop(); if (numbers.push(p+q) == overfloww) cout << "Warring : stack full,lost result" << endl; } } break; case '-': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ numbers.pop(); if (numbers.push(p-q) == overfloww) cout << "Warring : stack full,lost result" << endl; } } break; case '*': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ numbers.pop(); if (numbers.push(p*q) == overfloww) cout << "Warring : stack full,lost result" << endl; } } break; case '/': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ if (q == 0) cout << "againt / precept!" <<endl; else numbers.pop(); if (numbers.push(p/q) == overfloww) out << "Warring : stack full,lost result" << endl; } } case 'q'; cout << "calculation finished.\n"; return false; } return true; } void main() { Stack numbers; while (do_command(get_command(),stored_numbers)); }
查看全文
相关阅读:
ios学习Day3xiawu
ios学习Day3
linux系统设置回收站
Linux sort命令的注意点
markdown文件管理
PG创建只读用户
PG游标引用实例
小狼毫输入法配置双拼输入
日期相关
PG数组使用
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
机器学习笔记(一)线性回归
c++多线程(《深入理解计算机……》)
(转载)两篇很牛的vim使用技巧
(转载)技术人员,请注意那些被你忽略的重要事情
cf369E 树状数组解决区间包含区间(好题)
hdu 3016(线段树 + DP)
HDU 4123(两种方法-RMQ,单调队列)
HDU 4125 2011福州现场赛E题 (KMP+找规律建树+手工栈模拟)
(转载)poj 3468 树状数组解法
(转载) 树状数组区间求和三种模型
热门文章
FreeRTOS 中断优先级嵌套错误引发HardFault异常解决
学习使用Free RTOS ,移植最新的STM32 v3.5固件库
Spring——jar包详解
1.2UISwitch 1.3 自定义UIswitch 1.4pickerView
关于iOS8上本地通知接收不到的问题
ios7高级
微博项目01 创建架构
新浪微博 2.4sdk 一闪而过
实现控制器和视图1.0----1简介
Object-c中@private、@protected、@public解析
Copyright © 2011-2022 走看看