資源簡(jiǎn)介
順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算
輸入格式:一行一個(gè)算術(shù)表達(dá)式,可以輸入若干行
輸出格式:一行一個(gè)輸出結(jié)果
樣例:
輸入樣例:
2*(3 + 4)
6+ 2 * 8 /4
輸出樣例
14
10
【基本要求】運(yùn)算對(duì)象均為整數(shù)
【選作內(nèi)容】運(yùn)算對(duì)象擴(kuò)充為可以是帶小數(shù)位的浮點(diǎn)數(shù)
代碼片段和文件信息
#include
#include
#include
#include
#include?“Calculator.h“
using?namespace?std;
Calculator::Calculator(int?length)???//構(gòu)造函數(shù),設(shè)置默認(rèn)長(zhǎng)度?
{
maxSize=length;
top=-1;
element=new?char[maxSize];
for(int?i=0;i ???element[i]=0;
assert(element!=NULL);
}
void?Calculator::overflowProcess()??????//溢出處理?
{
char?*newArray=new?char[maxSize+20];
if(newArray==NULL)
{
cerr<<“存儲(chǔ)分配失敗!\n“;
exit(1);
}
for(int?i=0;i<=top;i++)
????newArray[i]=element[i];
maxSize+=20;
delete?[]element;
element=newArray;
}
void?Calculator::Push(const?char?&ch)???????//新元素入棧
{
if(IsFull()==true)???overflowProcess();
element[++top]=ch;
?}
?
void?Calculator::Pop(char?&ch)???????//退棧
{
if(IsEmpty()==true)???return;
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????5452??2017-12-16?01:20??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\Calculator.cpp
?????文件???????1171??2017-12-15?15:23??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\Calculator.h
?????文件??????89805??2017-12-16?01:20??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\Calculator.o
?????文件????????935??2017-12-16?01:11??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\main.cpp
?????文件??????63628??2017-12-16?01:11??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\main.o
?????文件???????1363??2017-12-16?01:27??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\Makefile.win
?????文件???????1196??2017-12-15?17:26??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算【浮點(diǎn)數(shù)】.dev
?????文件????????224??2017-12-15?17:26??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼\順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算【浮點(diǎn)數(shù)】.layout
?????文件????2075968??2017-12-16?01:20??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算【浮點(diǎn)數(shù)】.exe
?????目錄??????????0??2017-12-25?14:29??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算\實(shí)現(xiàn)代碼
?????目錄??????????0??2017-12-25?14:29??實(shí)驗(yàn)三:順序棧實(shí)現(xiàn)算術(shù)表達(dá)式的計(jì)算
-----------?---------??----------?-----??----
??????????????2239742????????????????????11
評(píng)論
共有 條評(píng)論