C++面向?qū)ο蟪绦蛟O(shè)計(jì)簡單計(jì)算器的設(shè)計(jì)_第1頁
C++面向?qū)ο蟪绦蛟O(shè)計(jì)簡單計(jì)算器的設(shè)計(jì)_第2頁
C++面向?qū)ο蟪绦蛟O(shè)計(jì)簡單計(jì)算器的設(shè)計(jì)_第3頁
C++面向?qū)ο蟪绦蛟O(shè)計(jì)簡單計(jì)算器的設(shè)計(jì)_第4頁
C++面向?qū)ο蟪绦蛟O(shè)計(jì)簡單計(jì)算器的設(shè)計(jì)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、面向?qū)ο蟪绦蛟O(shè)計(jì) -簡單計(jì)算器的設(shè)計(jì)一、問題描述簡單計(jì)算器的基本功能如下:1. 四則運(yùn)算,例如加減乘除等;2. 除了整數(shù)的運(yùn)算也可實(shí)現(xiàn)小數(shù)的各類運(yùn)算;3. 判斷非法操作,例如判定1/0為非法操作;4. 其他特性;這個(gè)簡易計(jì)算器只實(shí)現(xiàn)以上所述功能,即實(shí)現(xiàn)簡單計(jì)算。二、設(shè)計(jì)思路計(jì)算器起始運(yùn)行在歸零狀態(tài),此時(shí)只接受數(shù)字輸入,當(dāng)按下一個(gè)數(shù)字按鈕時(shí),計(jì)算器只顯示用戶輸入第一個(gè)操作數(shù),用戶在該狀態(tài)下可以繼續(xù)輸入數(shù)字。1當(dāng)?shù)谝粋€(gè)數(shù)字輸入完成后,可以接受第二個(gè)操作數(shù)。2在數(shù)字輸入結(jié)束進(jìn)行運(yùn)算后,按下=按鈕可以根據(jù)前面按下的操作符計(jì)算結(jié)果顯示,表示計(jì)算完成。3在上述計(jì)算過程中都可以接受雙擊等號回到清零狀態(tài)。三、

2、功能函數(shù)設(shè)計(jì):1數(shù)字按鈕這個(gè)是通過最基本的onbutton()將09十個(gè)數(shù)字按鈕的單擊消息處理函數(shù)用類向?qū)筷P(guān)聯(lián)到此,適文本框應(yīng)該只是顯示當(dāng)前單擊的數(shù)字;2小數(shù)點(diǎn)按鈕函數(shù)ondecimal這個(gè)函數(shù)主要是實(shí)現(xiàn)小數(shù)點(diǎn)在計(jì)算器的相關(guān)功能3列表在算法的函數(shù)onselchangeoperatorlist()這一類按鈕包括“+”“-”“*”“/”,它們的單擊消息在同一個(gè)處理函數(shù)中進(jìn)行處理,以同樣的方法把這四個(gè)按鈕的單擊操作關(guān)聯(lián)到此函數(shù)中,使四則運(yùn)算法則在列表中通過選擇去實(shí)現(xiàn)。4“=”符號函數(shù)onenquall()實(shí)現(xiàn)計(jì)算器中等號的功能,雙擊時(shí)也可使編輯框的數(shù)字歸零。四、編碼實(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(+);以上代碼是初始化列表框,并使其在程序運(yùn)行時(shí)具有“加”“減”“乘”“除”可選擇功能。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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論