![C++面向对象程序设计简单计算器的设计_第1页](http://file2.renrendoc.com/fileroot_temp3/2021-8/30/7e748089-3927-4532-b0e8-a138218e9d29/7e748089-3927-4532-b0e8-a138218e9d291.gif)
![C++面向对象程序设计简单计算器的设计_第2页](http://file2.renrendoc.com/fileroot_temp3/2021-8/30/7e748089-3927-4532-b0e8-a138218e9d29/7e748089-3927-4532-b0e8-a138218e9d292.gif)
![C++面向对象程序设计简单计算器的设计_第3页](http://file2.renrendoc.com/fileroot_temp3/2021-8/30/7e748089-3927-4532-b0e8-a138218e9d29/7e748089-3927-4532-b0e8-a138218e9d293.gif)
![C++面向对象程序设计简单计算器的设计_第4页](http://file2.renrendoc.com/fileroot_temp3/2021-8/30/7e748089-3927-4532-b0e8-a138218e9d29/7e748089-3927-4532-b0e8-a138218e9d294.gif)
![C++面向对象程序设计简单计算器的设计_第5页](http://file2.renrendoc.com/fileroot_temp3/2021-8/30/7e748089-3927-4532-b0e8-a138218e9d29/7e748089-3927-4532-b0e8-a138218e9d295.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 面向对象程序设计 -简单计算器的设计一、问题描述简单计算器的基本功能如下:1. 四则运算,例如加减乘除等;2. 除了整数的运算也可实现小数的各类运算;3. 判断非法操作,例如判定1/0为非法操作;4. 其他特性;这个简易计算器只实现以上所述功能,即实现简单计算。二、设计思路计算器起始运行在归零状态,此时只接受数字输入,当按下一个数字按钮时,计算器只显示用户输入第一个操作数,用户在该状态下可以继续输入数字。1当第一个数字输入完成后,可以接受第二个操作数。2在数字输入结束进行运算后,按下=按钮可以根据前面按下的操作符计算结果显示,表示计算完成。3在上述计算过程中都可以接受双击等号回到清零状态。三
2、、功能函数设计:1数字按钮这个是通过最基本的onbutton()将09十个数字按钮的单击消息处理函数用类向导全部关联到此,适文本框应该只是显示当前单击的数字;2小数点按钮函数ondecimal这个函数主要是实现小数点在计算器的相关功能3列表在算法的函数onselchangeoperatorlist()这一类按钮包括“+”“-”“*”“/”,它们的单击消息在同一个处理函数中进行处理,以同样的方法把这四个按钮的单击操作关联到此函数中,使四则运算法则在列表中通过选择去实现。4“=”符号函数onenquall()实现计算器中等号的功能,双击时也可使编辑框的数字归零。四、编码实现:int calcula
3、tor_type_i;double count=10,value=0;double input_data_int=0,input_data_dec=0;double inputdata1=0,inputdata2=0;char datatostr_buffer10;bool decimal=false;以上代码是添加的全局变量,为正确获取键盘输入供所有按钮函数使用。/ todo: add extra initialization herem_operatorbox.addstring(-);m_operatorbox.addstring(*);m_operatorbox.addstring(/
4、);m_operatorbox.addstring(+);以上代码是初始化列表框,并使其在程序运行时具有“加”“减”“乘”“除”可选择功能。void cmycalculatordlg:on1button() if(decimal)input_data_dec=input_data_dec+1/count;count=10*count;else input_data_int=10*input_data_int+1; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lp
5、ctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on2button() if(decimal)input_data_dec=input_data_dec+2/count;count=10*count;else input_data_int=10*input_data_int+2; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buf
6、fer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on3button() if(decimal)input_data_dec=input_data_dec+3/count;count=10*count;else input_data_int=10*input_data_int+3; value=input_data_int+input_data_dec; _g
7、cvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on4button() if(decimal)input_data_dec=input_data_dec+4/count;count=10*count;else input_data_int=10*input_data_int+4; value=input_d
8、ata_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on5button() if(decimal)input_data_dec=input_data_dec+5/count;count=10*count;else input_data_int=10*input
9、_data_int+5; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on6button() if(decimal)input_data_dec=input_data_dec+6/count;count=10*count;el
10、se input_data_int=10*input_data_int+6; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on7button() if(decimal)input_data_dec=input_data_dec
11、+7/count;count=10*count;else input_data_int=10*input_data_int+7; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:on8button() if(decimal)inp
12、ut_data_dec=input_data_dec+8/count;count=10*count;else input_data_int=10*input_data_int+8; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(false);void cmycalculatordlg:
13、on9button() if(decimal)input_data_dec=input_data_dec+9/count;count=10*count;else input_data_int=10*input_data_int+9; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handler code hereupdatedata(fal
14、se);void cmycalculatordlg:on0button() if(decimal)input_data_dec=input_data_dec+0/count;count=10*count;else input_data_int=10*input_data_int+0; value=input_data_int+input_data_dec; _gcvt(value,10,datatostr_buffer); m_showresultedit=(lpctstr)datatostr_buffer;/ todo: add your control notification handl
15、er code hereupdatedata(false);void cmycalculatordlg:ondecimalbutton() decimal=true;/ todo: add your control notification handler code herevoid cmycalculatordlg:onequalbutton() inputdata2=input_data_int+input_data_dec;decimal=false;input_data_int=0;input_data_dec=0;count=10;switch(calculator_type_i)c
16、ase 0: value=inputdata1-inputdata2; break; case 1: value=inputdata1*inputdata2; break; case 2: if(inputdata2=0) messagebox(除数不能为0!); break; else value=inputdata1/inputdata2; break; case 3: value=inputdata1+inputdata2; break;_gcvt(value,10,datatostr_buffer);m_showresultedit=(lpctstr)datatostr_buffer;
17、updatedata(false); void cmycalculatordlg:onchangeshowresultedit() / todo: if this is a richedit control, the control will not/ send this notification unless you override the cdialog:oninitdialog()/ function and call cricheditctrl().seteventmask()/ with the enm_change flag ored into the mask./ todo:
18、add your control notification handler code herevoid cmycalculatordlg:onerrspaceshowresultedit() / todo: add your control notification handler code herevoid cmycalculatordlg:onselchangeoperatorlist() inputdata1=input_data_int+input_data_dec; decimal=false; input_data_int=0; input_data_dec=0; count=10; calculator_type_i=m_operatorbox.g
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 社会小学生实践活动心得体会6篇
- 原创贴纸出售合同范本
- 芯代加工合同范本
- 睡眠班会主题教案6篇
- 楼房电力改造合同范本
- 西瓜地租赁合同范本
- 快艇过户合同范本
- 【正版授权】 ISO/IEC 23360-5:2006 EN Linux Standard Base (LSB) core specification 3.1 - Part 5: Specification for PPC32 architecture
- 枯树处理合同范本
- 合作分红退股合同范本
- 山东省临沂市罗庄区2023-2024学年八年级下学期期末数学试题
- 广东省珠海市2022-2023学年三年级下学期语文期末考试试卷(含答案)
- 科学(浙江卷)2024年中考考前押题密卷(全解全析)
- 人生悟理-透过物理看人生智慧树知到期末考试答案章节答案2024年兰州大学
- 2024年巴黎奥运会课件
- 手术室标本丢失应急预案
- 枣庄市专业技术人员继续教育公需科目2021年度补考题库及卫生专科课题库
- 提高呼吸科患者呼吸功能锻炼掌握率品管圈成果汇报模板课件
- 2020 ACLS-PC-SA课前自我测试试题及答案
- (完整版)最新-英语国际音标表(48个)版-绝对准确(最新整理)
- 部编人教版小学一至六年级必背古诗
评论
0/150
提交评论