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)); }
查看全文
相关阅读:
JQuery-文档处理&选择器
JQuery-事件(部分)
JS中构造函数与函数
JS中的String.Math.Date
JS中的_proto_(2)
JS中的_proto_
JS中的constructor
mysql 安装问题
【转】SpringMVC中DispatcherServlet配置中url-pattern 配置/*和/的区别
【转】MySql中的函数
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
mescroll插件实现上拉刷新下拉滚动
npm操作
通过gulp+gulp-livereload实现页面热更新
长屏插件使用
js辨别对象的类型
js typeof 的深入了解
vue渲染过程的{{xxx}}显示
hadoop集群命令
accenstoken 手动关联
centos6安装python2.7.8
热门文章
liunx下svn 客户端安装
设置临时环境变量
IO测试
安装tensorflow
Centos6安装Rstudio
pgsql问题记录
mysql开启远程访问
JQuery-Ajax
JQuery-属性
JQuery-筛选
Copyright © 2011-2022 走看看