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)); }
查看全文
相关阅读:
Power Desginer系列00【转载】
Power Desginer系列02【转载】
【转】华为路由器、交换机设备模拟器
【图片教程】大学易站注册发布教程!
【转】使用BT3、BT4光盘系统、虚拟机vmware破解无线上网
【技术贴】设置 Eclipse 智能代码提示,大幅度减少 alt+/ 使用频率,打每个字都出现代码提
【技术贴】ASPNET登录失败。MSsql2005拒绝了对对象 ''xxx'' (数据库 ''xx
【技术贴】火狐的悬停激活标签扩展插件下载。Tab Focus
【技术贴】桌面图标变色了怎么办?桌面图标快捷方式失真、模糊的解决办法!
【转】【CN五一装机版】GhostXP_SP3电脑公司通用版v19.2装机版NTFS
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
nullnullsql 多条件查询
下载稻草人下来刷新+gallery
构造和析构异常
密码库 链接
des相关
Multiple dispatch
openssl 连接
编译原理笔记
qmake生成的Makefile分析
构造函数异常测试
热门文章
List of programming languages by category
D_REENTRANT 宏作用
Moss 2007 入门
PowerDesigner中设计物理模型
多表查询不同数据库服务器上的表【转载】
数据仓库经验小结【转载】
Power Desginer系列01
Powerdesigner数据库建模概念模型ER图
PowerDesigner教程系列(二)概念数据模型
Power Desginer系列03【转载】
Copyright © 2011-2022 走看看