runxinzhi.com
首页
百度搜索
后缀运算器(已补全)
#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)); }
相关阅读:
ThingJS,轻松切换3D场景!
ThingJS,以可视化的方式解决管线难题
可视化能成为物联网“最后一公里”么?
ThingJS 新手教程之初识在线开发(一)
threejs和ThingJS的区别,ThingJS收费么?
带你了解为什么许多公司都会选择使用ThingJS制作Demo进行投标!
物联网可视化平台有哪些?ThingJS怎么样?
ThingJS园区搭建工具模模搭介绍
ThingJS,物联网可视化方面的专家平台!
ajax的post的方法,不报错,就是不输出信息
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
页面属性、窗口属性、母版的使用
axure--中继器
第四节 mount /who / mkdir /rmdir /rm /cp /mv /touch /cat /tac/head /tail /more /less / chmod /chown /umask /chattr /lsattr /history /echo
第三节
第二节 安装CentOS
第一节
Linux第九讲随笔 -进程管理 、ps aux 、
Linux第八讲随笔 -tar / 系统启动流程
su和sudo命令的区别
课后习题-1
热门文章
tar --打包和压缩
练习题-4
练习题-3
练习题-2
练习题-1
单词记忆-4
Linux内置命令
20170310句
20170309词
迅速了解如何使用ThingJS!
Copyright © 2020-2023
润新知