第一篇:c++24點(diǎn)游戲
c++24點(diǎn)游戲
#include “iostream” #include “string” using namespace std;
//定義Stack類
const maxsize=20;
enum Error_code { success, overflow, underflow };
template
bool empty()const;bool full()const;int size()const;void clear();
Error_code top(T &item)const;Error_code pop();
Error_code push(const T &item);private: int count;T entry[maxsize];};
template
template
bool Stack
template
bool Stack
template
template
template
Error_code Stack
template
Error_code Stack
template
Error_code Stack
Stack
int set;
// 判斷程序中的異常,以便適時(shí)退出?//
void process(char c)
//計(jì)算兩個(gè)數(shù)的 +-* / 運(yùn)算// { int k=0;double a,b;sign.pop();
if(num.top(b)==success){
num.pop();
if(num.top(a)==success){ num.pop();k=1;} } if(k){ switch(c){
case '+': num.push(a+b);break;case '-': num.push(a-b);break;case '*': num.push(a*b);break;case '/': if(b==0){ set=4;num.push(-1);} else
num.push(a/b);break;} }
else {set=1;num.push(-1);} }
void get_command(string &str){
cout<<“n請(qǐng)輸入要進(jìn)行運(yùn)算的表達(dá)式,包括” +,-,*,/,=,(,)“和數(shù)字,”< <<“注意: 以數(shù)字開頭,等號(hào)結(jié)尾,中間括號(hào)要匹配.”< double do_command(const string &str){ string s=“"; double outcome=-1;char c; for(int i=0;str[i]!='