




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、面向?qū)ο蟪绦蛟O(shè)計 -簡單計算器的設(shè)計一、問題描述簡單計算器的基本功能如下:1. 四則運算,例如加減乘除等;2. 除了整數(shù)的運算也可實現(xiàn)小數(shù)的各類運算;3. 判斷非法操作,例如判定1/0為非法操作;4. 其他特性;這個簡易計算器只實現(xiàn)以上所述功能,即實現(xiàn)簡單計算。二、設(shè)計思路計算器起始運行在歸零狀態(tài),此時只接受數(shù)字輸入,當(dāng)按下一個數(shù)字按鈕時,計算器只顯示用戶輸入第一個操作數(shù),用戶在該狀態(tài)下可以繼續(xù)輸入數(shù)字。1當(dāng)?shù)谝粋€數(shù)字輸入完成后,可以接受第二個操作數(shù)。2在數(shù)字輸入結(jié)束進行運算后,按下=按鈕可以根據(jù)前面按下的操作符計算結(jié)果顯示,表示計算完成。3在上述計算過程中都可以接受雙擊等號回到清零狀態(tài)。三、
2、功能函數(shù)設(shè)計:1數(shù)字按鈕這個是通過最基本的onbutton()將09十個數(shù)字按鈕的單擊消息處理函數(shù)用類向?qū)筷P(guān)聯(lián)到此,適文本框應(yīng)該只是顯示當(dāng)前單擊的數(shù)字;2小數(shù)點按鈕函數(shù)ondecimal這個函數(shù)主要是實現(xiàn)小數(shù)點在計算器的相關(guān)功能3列表在算法的函數(shù)onselchangeoperatorlist()這一類按鈕包括“+”“-”“*”“/”,它們的單擊消息在同一個處理函數(shù)中進行處理,以同樣的方法把這四個按鈕的單擊操作關(guān)聯(lián)到此函數(shù)中,使四則運算法則在列表中通過選擇去實現(xiàn)。4“=”符號函數(shù)onenquall()實現(xiàn)計算器中等號的功能,雙擊時也可使編輯框的數(shù)字歸零。四、編碼實現(xiàn):int calculat
3、or_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;以上代碼是添加的全局變量,為正確獲取鍵盤輸入供所有按鈕函數(shù)使用。/ 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=(lpc
5、tstr)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_buff
6、er); 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; _gc
7、vt(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_da
8、ta_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;els
10、e 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)inpu
12、t_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:o
13、n9button() 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(fals
14、e);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 handle
15、r 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)ca
16、se 0: value=inputdata1-inputdata2; break; case 1: value=inputdata1*inputdata2; break; case 2: if(inputdata2=0) messagebox(除數(shù)不能為0!); break; else value=inputdata1/inputdata2; break; case 3: value=inputdata1+inputdata2; break;_gcvt(value,10,datatostr_buffer);m_showresultedit=(lpctstr)datatostr_buffer;u
17、pdatedata(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: a
18、dd 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.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 清潔服務(wù)外包協(xié)議
- 建筑行業(yè)臨時用工勞動合同
- 國際油氣貿(mào)易合同文檔
- 環(huán)保產(chǎn)業(yè)投資協(xié)議書
- 出借咨詢與服務(wù)協(xié)議
- 在線醫(yī)療咨詢平臺推廣合作協(xié)議
- 銷售承包的合同
- 太陽能光伏發(fā)電投資合同
- 汽車租賃行業(yè)車輛保險責(zé)任免責(zé)協(xié)議書
- 2025年激光隧道斷面測量系統(tǒng)項目合作計劃書
- 春節(jié)習(xí)俗中的傳統(tǒng)節(jié)日服飾與裝扮
- 兒童編程課件
- (完整word版)英語四級單詞大全
- 腺樣體護理查房
- 備考期末-六選五-專項練習(xí)-2022-2023學(xué)年人教版英語八年級上冊
- 產(chǎn)品設(shè)計思維 課件 第1章 產(chǎn)品設(shè)計思維概述
- 兒童和青少年高尿酸血癥的預(yù)防和管理
- 中國移動企業(yè)文化理念體系
- 酒店服務(wù)禮儀(中職酒店服務(wù)與管理專業(yè))PPT完整全套教學(xué)課件
- 混合動力汽車構(gòu)造與檢修(高職新能源汽車專業(yè))PPT完整全套教學(xué)課件
- 佛教寺院修繕方案
評論
0/150
提交評論