// // ------ Main (Driver) ------ int main() { BankAccount Account1("Peter Otool",22299); BankAccount Account2("Bob Dole", 33399, 300.00); std::cout << " Accounts Created as follows:" << std::endl; std::cout << "-----------------------------------" << std::endl; Account1.DisplayData(); Account2.DisplayData(); Account1.Deposit(100.00); Account2.Withdrawal(100.00); std::cout << std::endl; std::cout << " Accounts Updated to the following:" << std::endl; std::cout << "-----------------------------------" << std::endl; Account1.DisplayData(); Account2.DisplayData(); std::cout << std::endl; Account1.Deposit(-100.00); Account2.Withdrawal(-100.00); Account1.Withdrawal(300.00); std::cout << std::endl; std::cout << " Accounts Updated to the following:" << std::endl; std::cout << "-----------------------------------" << std::endl; Account1.DisplayData(); Account2.DisplayData(); }
int compute1(long double &a,string s,int angle=0)//算术综合运算 { if(!check_b(s)) return 0; Stack<long double> ss(20); Stack<char> sf(20); int i=0,j; string s1,s2; char c; long double b; while(IsUselessChar(s[i])) i++; if(s[i]=='-') { ss.PushStack(-1); sf.PushStack('*'); i++; } else if(s[i]=='+') i++; while(s[i]) { s2="\0"; if(IsUselessChar(s[i])) i++; else if(IsBracket(s[i])==1) { if(i>0&&!IsOperator1(s[i-1])) if(!sf.PushStack('*')) return 0; s2=GetBracketData(s,i); if(!compute1(a,s2,angle)||!ss.PushStack(a)) return 0; } else if(IsOperator1(s[i])) { if(s[i]=='!') { if(!ss.PopStack(b)||!factorial(a,(int)b)||!ss.PushStack(a)) return 0; i++; continue; } while(sf.GetTopData(c)) { if(PRI(s[i])>PRI(c)) break; if(!ss.PopStack(b)||!ss.PopStack(a)||!sf.PopStack(c)||!Account1(a,b,c)||!ss.PushStack(a)) return 0; } if(!sf.PushStack(s[i++])) return 0; } else if(IsData(s[i])==1) { while(IsData(s[i])==1) s2+=s[i++]; if(!ss.PushStack(string_double(s2))) return 0; } else if(s[i]=='S') { if(i>0&&!IsOperator1(s[i-1])) if(!sf.PushStack('*')) return 0; s2="\0"; for(j=0; j<4&&s[i]; j++,i++) s2+=s[i]; if(s2!="Sqrt"||IsBracket(s[i])!=1) return 0; s2=GetBracketData(s,i); s1="\0"; for(j=0; s2[j]; j++) { if(IsBracket(s2[j])==1) s1+="("+GetBracketData(s2,j)+")"; if(s2[j]==',') { j++; break; } else s1+=s2[j]; } if(!compute1(a,s1,angle)) return 0; s1="\0"; for(; s2[j]; j++) s1+=s2[j]; if(!compute1(b,s1,angle)||!Sqrt(a,b)||!ss.PushStack(a)) return 0; } else if(s[i]>='a'&&s[i]<='z'||s[i]=='L') { s1="\0"; if(i>0&&!IsOperator1(s[i-1])) if(!sf.PushStack('*')) return 0; while(s[i]>='a'&&s[i]<='z'||s[i]=='L'||s[i]=='^') { s1+=s[i++]; if(s[i-1]=='e'&&s[i]!='^') s1+='^'; } if(s[i-1]=='e') s2="1"; else if(IsBracket(s[i])==1) s2=GetBracketData(s,i); else if(IsData(s[i])==1) { while(s[i]) { if(IsData(s[i])==1) s2+=s[i++]; else break; } } else if(s[i]=='P'||s[i+1]=='i') s2="Pi"; else if(s[i]=='S') { for(j=0; j<4&&s[i]; j++,i++) s2+=s[i]; if(s2!="Sqrt"||IsBracket(s[i])!=1) return 0; s2+="("+GetBracketData(s,i)+")"; } else return 0; if(!compute1(a,s2,angle)||!compute3(b,s1,a,angle)||!ss.PushStack(b)) return 0; } else if(s[i]=='P') { if(i>0&&!IsOperator1(s[i-1])&&!sf.PushStack('*')||!ss.PushStack(P)) return 0; i+=2; } else return 0; } while(sf.PopStack(c)) if(!ss.PopStack(b)||!ss.PopStack(a)||!Account1(a,b,c)||!ss.PushStack(a)) return 0; if(!ss.PopStack(a)||ss.State()>=0) return 0; return 1; }