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)); }
查看全文
相关阅读:
C#使用Selenium实现QQ空间数据抓取 说说抓取
C#使用Selenium实现QQ空间数据抓取 登录QQ空间
[bug系列]Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory
【原创】CA证书申请+IIS配置HTTPS+默认访问https路径
【原创】MVC项目中使用JQuery的upladify图片上传插件相关问题的解决方案
Jquery中$.ajax()方法参数详解
开发IOS应用真的一定要买苹果电脑设备吗?
vim全选内容命令
配置jdk环境变量
mysql联查中使用if和group by会让你的结果不是你想要的
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
python设计模式
Redis集群搭建
深入理解Redis
Python实现常用查找与排序算法
MySQL的安装与配置——详细教程
Vue
如何从零开发一个低代码平台,有哪些成熟技术组件可用?
浅谈java中的对象、类、与方法的重载
详解Http请求中Content-Type讲解以及在Spring MVC中的应用
JSP request.setAttribute()详解及实例
热门文章
解决百度Echarts图表坐标轴越界的方法
手把手教你写一个微信小程序(推荐)
vue+echarts实现动态绘制图表及异步加载数据的方法
react 应用多入口配置及实践总结
Vue绑定内联样式问题
.NetCore2.0项目之ABP+Vue(IView框架)单页应用之路,启动
C# NetCore使用AngleSharp爬取周公解梦数据
C# NetCore使用AngleSharp爬取周公解梦数据 起因和页面数据拆解
关于个人用户如何选择购买自己的服务器?阿里云?腾讯云?小鸟云?【云平台如有活动,长期更新】
NetCore使用Jwtbearer给WebAPI添加访问控制
Copyright © 2011-2022 走看看