棧的應用 乙個簡單的整數計算器

2021-05-22 17:24:26 字數 897 閱讀 4219

實現乙個簡單的整數計算器,能夠進行加、減、乘、除和乘方運算。使用時算式採用字尾輸入法,每個運算元、操作符之間都以空白符分隔。乘方運算用「^」表示。每次運算在前次結果基礎上進行,若要將前次執行結果清除,可鍵入「c」。當鍵入「q」時程式結束。

//stack.h

#include

#include

#include

#include

using namespace std;

enum boolean ;

const int maxstacksize=50; //棧的大小,即棧中元素的最大個數

template

class stack

;template

stack::stack(void):top(-1)  //建構函式,棧頂初始化為-1

{}template

void stack::push(const t& item) //將元素item壓入棧

template

int stack::stackfull(void) const  //測試棧是否滿

template

void stack::clearstack(void)

//calculator.h

class calculator   //計算器類

;void calculator::enter(int num)

boolean calculator::gettwooperands(int& opnd1,int& opnd2)

}  

void calculator::clear(void)

//主函式

#include"stack.h"

#include"calculator.h"

int main()

乙個簡單的計算器

乙個非常簡單的計算器 來自sololearn 只能進行單一計算 while true print 設定 print enter 增加 to 增加 two numbers print enter 減去 to 減去 two numbers print enter 相乘 to 相乘 two numbers...

製作乙個簡單的計算器

coding utf 8 time 2020 2 5 author wowilliam210 file calculator.py software pycharm import win32com.client class acalculator object def check num zsq f...

乙個極簡單的計算器

網上看到的計算器程式,再加上一些對於 號的處理,就完美了,例如輸入 3 6 8敲回車,立刻就列印出51,如果輸入3 6 8 則出錯,這兒需處理一下.import os while true dynamic input 輸入計算表示式 if dynamic cls try result eval dy...