ImageVerifierCode 换一换
格式:DOCX , 页数:34 ,大小:74.44KB ,
资源ID:5578500      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5578500.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(简单计算器可视化程序编程.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

简单计算器可视化程序编程.docx

1、简单计算器可视化程序编程简单计算器一、基本功能描述二进制、八进制、十进制及十六进制数的加、减、乘、除、乘方、取模等简单计算科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行以角度、弧度两种方式实现上述部分函数具备历史计算的记忆功能对不正确的表达式能指出其错误原因二、流程图图1输入数据子函数流程图图2三、设计步骤打开MicrosoftVisualC+6.0,在文件中点击新建,在弹出框内选择MFCAppWizardexe工程,输入工程名Calculter及其所在位置,点击确定,如图3所示。图3新建MFCAppWizardexe工程将弹出MFCAppWizard-

2、step1对话框,选择基本对话框,点击完成,如图4所示。图4基本对话框这样,MFCAppWizard就建立了一个基于对话窗口的程序框架,如图5所示。图5新建的对话框四、界面设计1、创建控件在图5所示的ResoureView选项卡中打开Dialog资源组,双击IDD_CALCULATOR_DIALOG,在右边的窗口中显示出待编辑的对话框。开始摆放控件,包括编辑框和按钮的创建。按钮的创建以“1”为例进行介绍,其他按钮的创建可参照此进行操作。1)在图5中Controls的“编辑框”按钮上单击鼠标左键,在对话框编辑窗口上合适的位置按下鼠标左键并拖动鼠标画出一个大小合适的编辑框。在编辑框上单击鼠标右键,

3、在弹出的快捷莱单中选择属性选项,此时弹出Edit属性对话框,如图6所示,在该对话框中输入ID属性。图6Edit属性对话框2)在图3中Controls的“Button”按钮上单击鼠标左键,在对话框上的合适的位置上按下鼠标左键并拖动鼠标画出一个大小合适的下压式按钮。在按钮上单击鼠标右键,在弹出的快捷菜单中选择属性选项,此时也弹出PushButton属性对话框,如图7所示,在该对话框中输入控件的ID值和标题属性。图7PushButton属性按照上面的操作过程编辑其他按钮和编辑框等对象的属性。表1各按钮和编辑框等对象的属性对象ID标题或说明编辑框IDC_DC_EDIT_INPUT结果显示按钮IDC_B

4、UTTON11按钮IDC_BUTTON22按钮IDC_BUTTON33按钮IDC_BUTTON44按钮IDC_BUTTON55按钮IDC_BUTTON66按钮IDC_BUTTON77按钮IDC_BUTTON88按钮IDC_BUTTON99按钮IDC_BUTTON100按钮IDC_BUTTON11.按钮IDC_BUTTON12空格按钮IDC_BUTTON23-按钮IDC_BUTTON26*按钮IDC_BUTTON27/按钮IDC_BUTTON38sqrt按钮IDC_BUTTON30%按钮IDC_BUTTON25按钮IDC_BUTTON31sin按钮IDC_BUTTON32cos按钮IDC_BUT

5、TON33tan按钮IDC_BUTTON34cot按钮IDC_BUTTON40sin1按钮IDC_BUTTON41cos1按钮IDC_BUTTON35log按钮IDC_BUTTON36ln按钮IDC_BUTTON14a按钮IDC_BUTTON15b按钮IDC_BUTTON16c按钮IDC_BUTTON17d按钮IDC_BUTTON18e按钮IDC_BUTTON19f按钮IDC_BUTTON13退格按钮IDC_BUTTON37e按钮IDC_BUTTON22清空按钮IDOK计算按钮IDC_RADIO_DEGREE角度按钮IDC_RADIO_RADIAN弧度按钮IDC_STATIC计算结果按钮IDC

6、_BTN_HISTREXP历史表达式按钮IDCANCEL退出按钮IDC_BTN_CONVERT进制完成后界面如图8所示。图8计算器界面五、计算器源程序代码/Calculation.cpp:implementationoftheCCalculationclass./MadebyGamsnin/#includestdafx.h#includeCalculator.h#includeCalculation.h#includemath.h#ifdef_DEBUG#undefTHIS_FILEstaticcharTHIS_FILE=_FILE_;#definenewDEBUG_NEW#endif#def

7、ineFUNCNUM15/函数个数#defineCONSTNUM11/常数个数#defineE#definePI3.14159/Construction/Destruction/CCalculation:CCalculation() /初始化函数和常数 m_bDegree=0; m_nOutputFlag=0; opt0=e; opt1=ch; opt2=sqr; opt3=sh; opt4=log; opt5=cos; opt6=sin; opt7=tan; opt8=ln; opt9=abs; opt10=at; opt11=as; opt12=ac; opt13=th; opt14=co

8、t; opt20=; opt21=/; opt22=*; opt23=%; opt24=+; opt25=-; m_strConValue1=9.80665; m_strConName1=GG; m_strConValue2=(8.988*109); m_strConName2=EF; m_strConValue3=0.02241383; m_strConName3=VM; m_strConValue4=(1.380662*10(-23); m_strConName4=BC; m_strConValue5=8.3144; m_strConName5=MG; m_strConValue6=(6.

9、6720*10(-11); m_strConName6=GR; m_strConValue7=(6.022045*1023); m_strConName7=NA;CCalculation:CCalculation()boolCCalculation:IsDigital(CStringstr) while(str.GetAt(0)=-)str.Delete(0); for(inti=0;iFUNCNUM;i+)if(str.Find(opti)!=-1)return0; for(i=0;i=0&decimal16) for(inti=str.GetLength();idecimal;i+)str

10、+=0; str+=.0; else for(inti=0;i-decimal;i+) str.Insert(0,0); str.Insert(0,.); if(sign=1)str.Insert(0,-); returnstr;doubleCCalculation:StoN(CStringstr) char*stopstring; doublex;x=strtod(str.GetBuffer(0),&stopstring); m_strTmp=stopstring; returnx;CStringCCalculation:TwoE(CStringstrExp) doublex2,y,x1=S

11、toN(strExp); strExp=m_strTmp; charop=strExp.GetAt(0); strExp.Delete(0); x2=StoN(strExp); if(m_strTmp!=)returnERROR_+m_strTmp+未知符号_; if(op=+)y=x1+x2; elseif(op=*)y=x1*x2; elseif(op=-)y=x1-x2; elseif(op=)y=pow(x1,x2); elseif(op=/)y=x1/x2; elseif(op=%)y=fmod(x1,x2); elsereturnERROR_+m_strTmp+未知运算符_; re

12、turnNtoS(y);CStringCCalculation:SingleE(CStringop,doubledx) if(op=ln) returnNtoS(log(dx); elseif(op=log) returnNtoS(log10(dx); elseif(op=sqr) returnNtoS(sqrt(dx); elseif(op=e) returnNtoS(exp(dx); elseif(op=abs) returnNtoS(fabs(dx); elseif(op=ac) returnNtoS(acos(dx); elseif(op=as) returnNtoS(asin(dx)

13、; elseif(op=at) returnNtoS(atan(dx); if(m_bDegree)dx=dx*PI/180; if(op=tan) returnNtoS(tan(dx); elseif(op=sin) returnNtoS(sin(dx); elseif(op=cos) returnNtoS(cos(dx); elseif(op=cot) returnNtoS(1/tan(dx); elseif(op=sh) returnNtoS(sinh(dx); elseif(op=ch) returnNtoS(cosh(dx); elseif(op=th) returnNtoS(sin

14、h(dx)/cosh(dx); elseif(op=exp) returnNtoS(pow(10,dx); returnERROR+op+_未知函数_;intCCalculation:LocateLBra(CStringstrExp) intlen=strExp.GetLength(); intpos=-1; for(inti=0;i=0&strExp.GetAt(i)=)break; if(strExp.GetAt(i)=() pos=i; returnpos;voidCCalculation:DelBracket(CString*strExp) intpos=LocateLBra(*str

15、Exp); inti,len=strExp-GetLength(); if(pos=-1)*strExp=ERROR_无效表达式_;return; for(i=pos;iGetAt(i)=)break; CStringstr; str=strExp-Mid(pos+1,i-pos-1); MultiE(&str); strExp-Delete(pos,i-pos+1); strExp-Insert(pos,str);voidCCalculation:MultiE(CString*strExp) if(strExp-IsEmpty()*strExp=ERROR_函数表达式为空_; if(IsDi

16、gital(*strExp)return; while(1)/*处理所有的一元运算*/ for(inti=0;iFind(opti); if(pos!=-1) CStringstr=strExp-Right(strExp-GetLength()-pos-opti.GetLength(); doubledx=StoN(str); if(m_strTmp=str)*strExp=ERROR+str+_无法识别的函数_;return; strExp-Delete(pos,strExp-GetLength()-pos); *strExp+=SingleE(opti,dx)+m_strTmp; Minu

17、sMinus(strExp); if(pos=1) charch=strExp-GetAt(pos-1); if(ch=48&chFind(); if(pos=-1)break; elseCalcu(strExp,pos); while(1) pos=strExp-Find(/); if(pos=-1)break; elseCalcu(strExp,pos); while(1) pos=strExp-Find(*); if(pos=-1)break; elseCalcu(strExp,pos); while(1) pos=strExp-Find(%); if(pos=-1)break; els

18、eCalcu(strExp,pos); pos=0; if(strExp-GetAt(0)=-|strExp-GetAt(0)=+)strExp-Insert(0,0); while(1) inttmpos=strExp-Right(strExp-GetLength()-pos).Find(-); if(tmpos=-1)break; elsepos+=tmpos; if(pos=0&strExp-GetAt(pos+1)=-|pos0) if(strExp-GetAt(pos+1)=+) strExp-Delete(pos+1); pos=0; continue; /*处理连减(如:-1)的

19、情况*/ intnCount=0; while(1) if(+pos0) if(strExp-GetAt(pos)!=-)break; elsenCount+; elsebreak; if(nCount0) strExp-Delete(pos-nCount-1,nCount+1); if(nCount%2=0)strExp-Insert(pos-nCount-1,-); elseif(pos-nCount-10)strExp-Insert(pos-nCount-1,+); pos=0; continue; elsepos-; /*/ if(pos0&strExp-GetAt(pos-1)=+)

20、 pos+; continue; Calcu(strExp,pos); elsepos+; pos=0; while(1) pos=strExp-Find(+);/ inttmpos=strExp-Right(strExp-GetLength()-pos).Find(+); if(pos=-1)break;/ elsepos+=tmpos; if(pos=0&strExp-GetAt(pos+1)=+|pos0) /*处理连加(如:+1)的情况*/ intnCount=0; while(1) if(+pos0) if(strExp-GetAt(pos)!=+)break; elsenCount

21、+; elsebreak; if(nCount0) strExp-Delete(pos-nCount-1,nCount+1); strExp-Insert(pos-nCount-1,+); pos=0; continue; elsepos-; /*/ Calcu(strExp,pos); elsepos+; voidCCalculation:Calcu(CString*strExp,intpos) charch; for(intj=pos-1;j=0;j-) ch=strExp-GetAt(j); if(ch=+|ch=-|ch=*|ch=/|ch=%|ch=) if(j=0&ch!=-)*s

22、trExp=ERROR_缺少参数_;return; if(j=0&ch=-)j=-1;/防止把负号误判为减号 elseif(j0&ch=-&!IsDigital(strExp-Mid(j-1,1)j-; break; for(intk=pos+1;kGetLength();k+) ch=strExp-GetAt(k); if(ch=+|ch=-|ch=*|ch=/|ch=%|ch=) if(ch=-&kpos+1)break; if(ch=-&k0&IsDigital(strExp-Mid(k+1,1)k+; elsebreak; CStringstrExp2=strExp-Mid(j+1,k

23、-j-1); *strExp=strExp-Left(j+1)+TwoE(strExp2)+strExp-Right(strExp-GetLength()-k); if(strExp-Find(#IN)!=-1)*strExp=ERROR_结果有溢出或值域越界_;return; if(!SynRes(strExp)*strExp=ERROR_缺少运算符_;return; MinusMinus(strExp);CStringCCalculation:MainPro(CStringstrExp) if(strExp.IsEmpty()return表达式不能为空; Macro(&strExp); strExp.MakeLower();/表达式全部小写 /*给表达式加上保护括号*/ strExp.Insert(0,(); strExp+=); /*/ intpos=strExp.Find(); intn

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1