C++语言编程计算器源代码
2023-06-04
来源:乌哈旅游
//计算器,函数#include
#include#include#include#include#include#include#includeusingnamespacestd;doublesimple(strings);//简单运算boolcheck(charc);//检查是否为数值doublecou(doublem,doublen,intc);//用于计算两个数的运算stringcut(stringstr);//括号截取doublesenior(stringstr,doublex);//高级函数计算doublecount(stringst);//括号运算boolbr_l(charc);boolbr_r(charc);stringal(stringst);//特殊值与符号处理stringabs_cut(stringst);//绝对值处理intnum;strings;vectorb;//存储高级符号内值intmain(){cout<<\"\\n\\本软件由松哥独家制造\\n\\n\";while(true){inti=0,j=0;num=0;strings1;b.clear();cout<<\"输入:\";cin>>s1;strings2(s1);if(s==\"#\")break;cout<<\"输出:\"<p;//存储读入的数字vectorq;//存储读入运算符while(st[i]!='\\0'&&st[i]!='='){doublesum=0;while(!check(st[i]))i++;while(check(st[i])){if(st[i]>64&&st[i]<91){sum=b[st[i]-65];i++;break;}if(st[i]!='.')sum=sum*10+(st[i++]-48);else{i++;doublesu=0,m=1;while(check(st[i])){m*=10.0;su=su*10+(st[i++]-48);}sum=sum+su/m;}}p.push_back(sum);}if(st[0]=='-')p[0]=-p[0];for(i=1;st[i]!='\\0';i++){switch(st[i]){case'=':break;case'^':q.push_back(1);break;case'/':q.push_back(-3);break;case'*':q.push_back(3);break;case'+':q.push_back(4);break;case'-':q.push_back(-4);break;default:if(!check(st[i])){cout<<\"含未知符号\"<='0'&&c<='9'||c=='.'||c>64&&c<85)returntrue;elsereturnfalse;}doublecou(doublem,doublen,intc){switch(c){case1:returnpow(m,n);case3:return(m*n);case-3:return(m/n);case4:return(m+n);case-4:return(m-n);default:cout<0&&isalpha(str[m-1]))for(intk=m-1;;k--)if(k<0||!isalpha(str[k])){k++;se=str.substr(k,m-k);intl=n-m+1;s=str.substr(m+1,l-2);b.push_back(senior(se,simple(s)));num++;l=n-k+1;str.replace(k,l,1,(char)(64+num));returnstr;}intl=n-m+1;s=str.substr(m+1,l-2);b.push_back(simple(s));num++;str.replace(m,l,1,(char)(64+num));returnstr;}doublecount(stringst){st=al(st);st=abs_cut(st);while(true){intr=0;st=cut(st);for(inti=0;i0){j--;if(st[j]=='.'){cout<<\"只能计算整数的阶乘!!!\\n\";return\"0\";}if(st[j]<48||st[j]>57){j++;break;}}for(intk=j;k1;m--)n*=m;num++;st.replace(j,i-j+1,1,(char)(64+num));b.push_back(n);}}i=st.find(\"π\");if(im;for(i=0;i