首页 > 编程知识 正文

手机计算器怎么加括号,计算器上的中括号在哪

时间:2023-05-04 05:31:11 阅读:43145 作者:406

一、实验任务(实验主题、目的)。

制作图形化括号的计算机

二.任务分析

假设已经有计算器,实现按等号的计算算法学习qt设置各按钮槽函数将算法缝合在qt内设计实现负数。 小数优化代码计算步骤添加Debug计算器图标ico csdn和GitHub三、实验设计(计划发送实验环境、算法、步骤、核心代码等)。

环境: QT5使用QT CREATOR编程(内置快速查询,非常方便) )

核心代码如下(等号按钮) ) )。

//等号核心代码从input框中检索要运算的字符串运算,并将其输出到output。 其中,input是运算对象的骑马订式void main window :3360 on _ push button _ op _ equal _ clicked ({ QS trining ) } q堆栈q char op; q堆栈qstring后期模板; //QQ; int numIdxStart=-1; //计算将骑马订转换为后缀的公式for (inti=0; i input.length (; I ) ) /数字为下标if(priority(input[I] )==1numIdxStart==-1 ) { numIdxStart=i; } else if (优先级(input )==1) (/数字) else )//其中input ) )是运算符(/。 以前是数字推式后缀堆栈,此if防止出现连续运算符导致bugif(numidxstart )=-1 ) qstringn=input.mid(numidxstart,i-numIdxStart ) posttemp.push(n; } numIdxStart=-1; if(op.isempty () ) op.push ) input[I]; } else if (优先级(input [ I ]==1) ) op.push (input [ I ] ); }elseif(input[I]==' () ) op.push ) input[I]; } else if (优先级(input[I]优先级(op.top ) ) op.push (input [ I ] ); }elseif(input[I]==' () ) /遇到右括号时弹堆栈运算符,直到遇到右括号while(op.top ) )!=' ' ' ) posttemp.push(op.pop ); op.pop (; } else if (优先级(input [ I ] )优先级(op.top ) )//如果当前运算符的优先级小于堆栈,则弹奏当前运算符直到该运算符达到堆栈中的元素//或以上,然后将当前运算符添加到while op.isempty (优先级(input [ I ] )=优先级(op.top ) ) ) post temp.push (op.pop ) ); op.push (输入[ I ]; }else{printlog('else ); } } } //end for //堆栈最后一个数字if(numidxstart!=-1 ) posttemp.push(input.mid ) numidxstart ); 推送//OP堆栈中剩馀的运算符,将while (! op.isEmpty () ) posttemp.push ).pop ) ); } QVectorQString post; while (! postTemp.isEmpty () ({//p=postTemp.top ) ) p; post.append(posttemp.pop ) ); (///post为后缀的表达式vector )不是字符串是因为尽管有多位运算字符串,但数字位数////post没有括号,每个元素都是一个运算符(数字或运算符)/printlog ) ' p:'p q堆叠双ans; for(intI=post.Length ) (-1; i=0; -I ) (打印) (for: ) qstring 33603360 number (I ) ) post[I]: ) post[I],1000 ); if(isdigits(post[I] ) ans.push (post [ I ].to double ) ); 继续; } double a=ans.pop (; double b=ans.pop (; 双精度c=66666; if(post[I]==' ' ) { c=b a; }elseif(post[I]=='-' ) { c=b - a; }elseif(post[I]=='* ' ) { c=b * a; }elseif(post[I]=='/' ) { c=b/a; }else{printlog('shit ' ); (ans.push ) c; //printlog('sleep ',100000 ); //将结果输出到output文本框ui-textedit _ output-settext (qstring 33603360 number (ans.pop ) ) ); 四.实验结果

左边是我的计算器,右边是windows10附带的计算器

完整的代码和项目文件可以在我的github上用star下载。 用qt5打开就可以直接跑了

https://github.com/gongfpp

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。