課程設(shè)計常用功能計算器軟件設(shè)計_第1頁
課程設(shè)計常用功能計算器軟件設(shè)計_第2頁
課程設(shè)計常用功能計算器軟件設(shè)計_第3頁
課程設(shè)計常用功能計算器軟件設(shè)計_第4頁
課程設(shè)計常用功能計算器軟件設(shè)計_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、計算機(jī)課程設(shè)計論文 題 目:常用功能計算器軟件設(shè)計學(xué) 院:測試與光電工程學(xué)院 專業(yè)名稱:電子科學(xué)與技術(shù)班級學(xué)號:10083129 學(xué)生姓名:周煒專 指導(dǎo)教師:黎芳芳 2013年 6月 常用功能計算器軟件設(shè)計摘要:計算器是我們?nèi)粘I钪谐S玫墓ぞ咧?,計算器使用方法簡單,操作方便,便于攜帶,適用于簡單快捷的計算。本設(shè)計使用Visual C+語言編寫具備常用功能的計算器軟件,用Microsoft Visual C+6.0環(huán)境編譯調(diào)試,制作了簡潔的應(yīng)用界面,使用模塊化設(shè)計和自頂向下的功能實(shí)現(xiàn)。本軟件可以進(jìn)行小數(shù)量級下的加減乘除計算以及開根號、求比例等計算功能,還可以使用存儲器進(jìn)行多數(shù)據(jù)求和,還可以用

2、退位、清零的方式修正操作失誤,在進(jìn)行不符合數(shù)學(xué)規(guī)則的非法計算時會報出錯誤提示。關(guān)鍵詞: 計算器 Visual C+ Microsoft Visual C+ 6.0 目錄1、 引言(1)2、C+語言簡介(1)3、Microsoft Visual C+開發(fā)環(huán)境簡介(1) 4、開發(fā),調(diào)試及運(yùn)行硬件和軟件環(huán)境(1)5、軟件整體設(shè)計思路(1)6、 軟件運(yùn)行效果(2)7、 源代碼(3)8、 致謝(23)9、 參考文獻(xiàn)(23)1、引言計算器是我們?nèi)粘I钪谐S玫囊环N工具,隨著電子科學(xué)的發(fā)展,計算器的功能越來越多樣化、復(fù)雜化,外觀也越來越多樣化、輕量化,我們可以用很低的價格在市場上買到很實(shí)用很漂亮的計算器。為

3、了鞏固和加深對計算機(jī)軟件設(shè)計課程的掌握,本課程設(shè)計使用高級語言在Windows環(huán)境下實(shí)現(xiàn)了具備常用功能的計算器軟件的設(shè)計。 2、C+語言簡介C+是一種使用非常廣泛的計算機(jī)編程語言。C+是一種靜態(tài)數(shù)據(jù)類型檢查的、支持多重編程范式的通用程序設(shè)計語言。它支持過程化程序設(shè)計、數(shù)據(jù)抽象、面向?qū)ο蟪绦蛟O(shè)計、泛型程序設(shè)計等多種程序設(shè)計風(fēng)格。3、Microsoft Visual C+開發(fā)環(huán)境簡介 Microsoft Visual C+是Microsoft公司推出的開發(fā)Win32環(huán)境程序,面向?qū)ο蟮目梢暬删幊滔到y(tǒng)。它不但具有程序框架自動生成、靈活方便的類管理、代碼編寫和界面設(shè)計集成交互操作、可開發(fā)多種程序等

4、優(yōu)點(diǎn),而且通過簡單的設(shè)置就可使其生成的程序框架支持?jǐn)?shù)據(jù)庫接口、OLE2,WinSock網(wǎng)絡(luò)、3D控制界面。 它以擁有“語法高亮”,IntelliSense(自動完成功能)以及高級除錯功能而著稱。比如,它允許用戶進(jìn)行遠(yuǎn)程調(diào)試,單步執(zhí)行等。還有允許用戶在調(diào)試期間重新編譯被修改的代碼,而不必重新啟動正在調(diào)試的程序。其編譯及建置系統(tǒng)以預(yù)編譯頭文件、最小重建功能及累加連結(jié)著稱。這些特征明顯縮短程式編輯、編譯及連結(jié)花費(fèi)的時間,在大型軟件計劃上尤其顯著。4、開發(fā),調(diào)試及運(yùn)行硬件和軟件環(huán)境 處理器: Intel Pentium® Dual-Core CPU T4200 2.00GHz BIOS: L

5、enovo 內(nèi)存 : 2GB (金士頓 1066mhz) 顯卡: Intel Mobile 4 Series Express Chipest Family (256MB) 操作系統(tǒng): 32-bit Windows XP 編程語言: Visual C+ 編譯環(huán)境: Microsoft Visual C+ 6.05、軟件整體設(shè)計思路 經(jīng)調(diào)查,非科學(xué)計算器常用功能主要有以下三個部分: 、運(yùn)算功能 常用的運(yùn)算功能有加法計算、減法計算、乘法計算、除法計算、根式計算、比率計算;、存儲功能 常用的存儲功能有:清除存儲器中的數(shù)值(MC)、將存于存儲器中的數(shù)顯示在計算器的顯示框上(MR)、將顯示框的數(shù)值存于存儲

6、器中(MS)、將顯示框的數(shù)與存儲器中的數(shù)相加并進(jìn)行存儲(M+)。如果存儲器中有數(shù)值將會顯示M標(biāo)志;、清除功能 常用的清除功能有清除輸入(CE)、清除鍵(C)、退格鍵(BACK)。由于visual c+ 6.0自帶了許多強(qiáng)大的數(shù)學(xué)計算庫文件,這為軟件的開發(fā)省去了不少的工作量,而visual c+6.0優(yōu)秀的對話框繪制模塊也使得這個小軟件美觀不少,為了方便計算器的使用,開發(fā)者特意加入了許多非法計算的錯誤提示,例如“Can not divide by zero”等。6、軟件運(yùn)行效果 、運(yùn)用計算器計算:78*80 圖一、運(yùn)用計算器計算:78 *80 圖二、在計算器上輸入:78* 圖三、在計算器上輸入:

7、80 圖四、輸出結(jié)果:6240、在計算器中輸入2/0圖五、非法操作,屏幕會顯示錯誤提示7、源代碼aboutdialog.cpp#include <afxwin.h>#include "aboutdialog.h"#include <mmsystem.h>#include "resource.h"aboutdialog:aboutdialog( ) : CDialog ( IDD_DIALOG1 )int aboutdialog:OnInitDialog( ):PlaySound ( "music.wav", N

8、ULL, SND_FILENAME | SND_ASYNC | SND_LOOP ) ;return 1 ;void aboutdialog:OnOK( ) :PlaySound ( NULL, NULL, NULL ) ;CDialog:OnOK( ) ;void aboutdialog:OnCancel( ) :PlaySound ( NULL, NULL, NULL ) ;CDialog:OnCancel( ) ;l aboutdialog.h class aboutdialog : public CDialogpublic :aboutdialog( ) ;int OnInitDial

9、og( ) ;void OnOK( ) ;void OnCancel( ) ;myapp.cpp#include <afxwin.h>#include "myapp.h"#include "myedit.h"#include "myframe.h"myapp a ;int myapp:InitInstance( )myframe *p ;p = new myframe ;p -> ShowWindow ( 1 ) ;m_pMainWnd = p ;return 1 ;myapp.hclass myapp : publ

10、ic CWinApppublic :int InitInstance( ) ; ;myedit.cpp#include <afxwin.h>#include "myedit.h"BEGIN_MESSAGE_MAP ( myedit, CEdit )ON_WM_CREATE( )ON_WM_LBUTTONDOWN( )ON_WM_MOUSEMOVE( )END_MESSAGE_MAP( )int myedit:OnCreate ( LPCREATESTRUCT l ) CEdit:OnCreate ( l ) ;m_cur = AfxGetApp( ) ->

11、 LoadStandardCursor ( IDC_ARROW ) ;return 0 ;void myedit:OnLButtonDown ( UINT flags, CPoint pt )void myedit:OnMouseMove ( UINT flags, CPoint pt )SetCursor ( m_cur ) ; myedit.hclass myedit : public CEdit private :HCURSOR m_cur ;public :int OnCreate ( LPCREATESTRUCT l ) ;void OnLButtonDown ( UINT flag

12、s, CPoint pt ) ;void OnMouseMove ( UINT flags, CPoint pt ) ;DECLARE_MESSAGE_MAP( ) ;myframe.cpp#include <afxwin.h>#include "myedit.h"#include "myframe.h"#include "aboutdialog.h"#include <math.h>#include "resource.h"BEGIN_MESSAGE_MAP ( myframe, CFra

13、meWnd )ON_WM_CREATE( )ON_COMMAND ( 1001, myabout )ON_COMMAND_RANGE ( 1, 10, numbers0to9 ) ON_COMMAND ( 101, back )ON_COMMAND ( 102, ce ) ON_COMMAND ( 103, c ) ON_COMMAND ( 106, memorycancel ) ON_COMMAND ( 107, divide )ON_COMMAND ( 108, squareroot ) ON_COMMAND ( 109, memoryrecall ) ON_COMMAND ( 110,

14、multiply ) ON_COMMAND ( 111, percentage ) ON_COMMAND ( 112, memorystore ) ON_COMMAND ( 113, minus )ON_COMMAND ( 114, onebyx ) ON_COMMAND ( 115, memoryplus ) ON_COMMAND ( 117, plusminus ) ON_COMMAND ( 118, point ) ON_COMMAND ( 119, plus ) ON_COMMAND ( 120, equalto ) ON_WM_PARENTNOTIFY( )ON_WM_KEYDOWN

15、( )END_MESSAGE_MAP()CString myframe:m_helpstrings = "No help topic is associated with this item.", "Delete the last digit of the displayed number.","Clears the displayed number.","Clears the current calculation.","","","Clears any numb

16、er stored in memory.","Puts this number in the calculator display.","Puts this number in the calculator display.","Puts this number in the calculator display.","Divdes.","Calculates the square root of the displayed number.","Recalls the num

17、ber stored in memory. The number remains in the memory.","Puts this number in the calculator display.","Puts this number in the calculator display.","Puts this number in the calculator display.","Multiplies.","Displays the result of the multiplicatio

18、n as percentage.","Stores the displayed number in the memory.","Puts this number in the calculator display.","Puts this number in the calculator display.","Puts this number in the calculator display.","Subracts.","Calculates the reciprocal

19、of the displayed number.","Adds the displayed number to any number already in memory.","Puts this number in the calculator display.","Changes the sign of the displayed number.","Inserts a decimal point.","Adds.","Performs any operation on t

20、he previous two numbers. To repeat he last operation click again." ;myframe:myframe( )CString mywindowclass ;CBrush mybrush ;mybrush.CreateStockObject ( LTGRAY_BRUSH ) ;mywindowclass = AfxRegisterWndClass ( CS_HREDRAW | CS_VREDRAW,AfxGetApp( ) -> LoadStandardCursor ( IDC_ARROW ),mybrush, Afx

21、GetApp( ) -> LoadIcon ( IDI_ICON1 ) ) ;Create ( mywindowclass, "Calculator", WS_SYSMENU | WS_MINIMIZEBOX, CRect ( 100, 100, 400, 400 ), 0, MAKEINTRESOURCE ( IDR_MENU1 ) ) ;BOOL myframe:PreCreateWindow ( CREATESTRUCT& cs ) CFrameWnd:PreCreateWindow ( cs ) ;cs.dwExStyle &= WS_EX_C

22、LIENTEDGE ;return TRUE ;int myframe:OnCreate ( LPCREATESTRUCT l )CFrameWnd:OnCreate ( l ) ;struct buttoninfochar m_str5 ;int id ; ;buttoninfo m30 = "", 100,"Back", 101,"CE", 102,"C", 103,"", 104,"", 105,"MC", 106,"7", 8,

23、"8", 9,"9", 10,"/", 107,"Sqrt", 108, "MR", 109,"4", 5,"5", 6,"6", 7,"*", 110,"%", 111,"MS", 112,"1", 2,"2", 3,"3", 4,"-", 113,"1/x", 114,&qu

24、ot;M+", 115,"0", 1,"+/-", 117,".", 118,"+", 119,"=", 120 ;m_editrect = CRect ( 10, 10, 275, 35 ) ;m_e.CreateEx ( WS_EX_CLIENTEDGE, "EDIT", "0.", WS_VISIBLE | WS_CHILD | ES_RIGHT | ES_MULTILINE, m_editrect, this, 30 ) ;int x1

25、= 10, y1 = 50, x2, y2 ;for ( int i = 0 ; i <= 29 ; i+ )x2 = x1 + 40 ;y2 = y1 + 30 ;m_buttonrecti = CRect ( x1, y1, x2, y2 ) ;if ( i != 0 && i != 4 && i != 5 )m_bi.Create ( mi.m_str, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, m_buttonrecti, this, mi.id ) ;if ( i = 0 )m_st.CreateEx ( WS

26、_EX_CLIENTEDGE, "STATIC", "", WS_VISIBLE | WS_CHILD | SS_NOTIFY, m_buttonrecti, this, mi.id ) ;x1 += 45 ;if ( ( i + 1 ) % 6 = 0 ) x1 = 10 ;y1 = y1 + 40 ;m_oper = ' ' ;m_over = true;m_decipoint = false ;m_mem = 0 ;return 0 ;void myframe:myabout( )aboutdialog d ;d.DoModal(

27、) ;void myframe:back()CString lf, rt ;m_e.GetWindowText ( m_str ) ;lf = m_str.Left ( m_str.GetLength( ) - 1 ) ;rt = m_str.Right ( 1 ) ;if ( rt = "." )m_decipoint = false ;if ( m_str = "0." )m_over = true ;elsem_str = lf ;elseif ( lf.Right ( 1 ) = "." )m_decipoint = fals

28、e ;if ( lf = "0." )m_str = "0." ;m_over = true ;elsem_str = lf.Left ( lf.GetLength( ) - 1 ) ;elseif ( lf = "" )m_str = "0." ;m_over = true ;elsem_str = lf ;m_e.SetWindowText ( m_str ) ;void myframe:c( )m_num1 = m_num2 = 0 ;m_over = true ;m_decipoint = false ;m

29、_str = "0." ;m_e. SetWindowText(m_str) ;void myframe:ce( )if ( m_oper = ' ' )m_num1 = 0 ;elsem_num2 = 0 ;m_str= "0." ;m_e. SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:numbers0to9 ( int id )CString temp ;temp.Format ( "%d", id - 1 )

30、;if ( m_over = false )m_e.GetWindowText ( m_str ) ;if ( m_str = "0." )return ;if ( m_str.GetLength( ) = 13 ):MessageBeep ( 1 ) ;elsem_str = m_str + temp ;m_e.SetWindowText ( m_str ) ;elsem_e.SetWindowText ( temp ) ;m_over = false ;void myframe:plusminus( )m_e.GetWindowText ( m_str ) ;m_num

31、 = atof ( m_str ) ;if ( m_num != 0 )m_num = m_num * -1 ;m_str.Format ( "%.8g", m_num ) ;m_e. SetWindowText ( m_str ) ;m_over = true ;void myframe:onebyx( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ;if ( m_num != 0 )m_num = 1 / m_num ;m_str.Format ( "%.8g", m_num ) ;m_e.

32、SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:squareroot( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ;if ( m_num != 0 )m_num = sqrt ( m_num ) ;m_str.Format( "%.8g", m_num ) ;m_e.SetWindowText(m_str) ;m_over = true ;m_decipoint = false ;void myframe:per

33、centage()double num3 ;if ( m_oper != ' ' )m_e.GetWindowText ( m_str ) ;m_num2 = atof ( m_str ) ;num3 = m_num2 * m_num1 ;num3 = num3 / 100 ;m_str.Format( "%.8g", num3 ) ;m_e.SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;m_oper = ' ' ;void myframe:point( )if (

34、m_decipoint = false )if ( m_over = true ) m_e.SetWindowText ( "0." ) ;m_over = false ;elsem_e.GetWindowText ( m_str ) ;if ( m_str = "0." )return ;elsem_str = m_str + "." ;m_e. SetWindowText ( m_str ) ;m_decipoint = true ;else:MessageBeep ( 1 ) ;void myframe:plus( )if (

35、m_oper != ' ' )equalto( ) ;m_oper = '+' ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:minus( )if ( m_oper != ' ' )equalto( ) ;m_oper = '-' ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m

36、_decipoint = false ;void myframe:multiply( )if ( m_oper != ' ' )equalto( ) ;m_oper = '*' ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:divide( )if ( m_oper != ' ' )equalto( ) ;m_oper = '/' ;m_e.GetWindowText (

37、m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:equalto( )if ( m_oper = ' ' )return ;double num3 ;m_e.GetWindowText ( m_str ) ;m_num2 = atof ( m_str ) ;switch ( m_oper )case '+' :num3 = m_num1 + m_num2 ;break ;case '-' :num3 = m_num1 - m_num

38、2 ;break ;case '*' :num3 = m_num1 * m_num2 ;break ;case '/' :if ( m_num2 = 0 )m_over = true ;m_decipoint = false ;m_e.SetWindowText ( "Cannot divide by zero." ) ;return ;elsenum3 = m_num1 / m_num2 ;m_str.Format ( "%.8g", num3 ) ;if ( m_str = "0" )m_str =

39、 "0." ;m_over = true ;m_decipoint = false ;m_oper = ' ' ;m_e.SetWindowText ( m_str ) ;void myframe:memorystore( )m_e.GetWindowText ( m_str ) ;m_mem = atof ( m_str ) ;m_st.SetWindowText ( "M" ) ;m_over = true ;m_decipoint = false ;m_oper = ' ' ;void myframe:memoryr

40、ecall( )m_str.Format( "%.8g", m_mem ) ;m_e.SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;m_oper = ' ' ;void myframe:memorycancel( )m_mem = 0 ;m_st.SetWindowText ( "" ) ;void myframe:memoryplus( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ; m_mem =

41、m_mem + m_num ; m_st.SetWindowText ( "M" ) ;m_over = true ;m_decipoint = false ;m_oper = ' ' ;void myframe:OnParentNotify ( long int m, unsigned long int p )int mousebutton = LOWORD ( m ) ;if ( mousebutton = WM_RBUTTONDOWN )int x = LOWORD ( p ) ;int y = HIWORD ( p ) ;CPoint pt ( x,

42、 y ) ;if ( m_editrect.PtInRect ( pt ) )MessageBox ( "Shows the result.", "Help.", MB_OK | MB_ICONQUESTION ) ;for ( int i = 0 ; i <= 29 ; i+ )if ( m_buttonrecti.PtInRect ( pt ) )MessageBox ( m_helpstringsi, "Help.", MB_OK | MB_ICONQUESTION ) ;void myframe:OnKeyDown (

43、UINT ch, UINT rep, UINT flag )switch ( ch )case VK_BACK :back( );break ;case VK_NUMPAD7 :case '7' :m_b7.SetState ( 1 ) ;numbers0to9 ( 8 ) ;Sleep ( 20 ) ;m_b7.SetState ( 0 ) ;break ;case VK_NUMPAD8 :case '8' :m_b8.SetState ( 1 ) ;numbers0to9 ( 9 ) ;Sleep ( 20 ) ;m_b8.SetState ( 0 ) ;b

44、reak ;case VK_NUMPAD9 :case '9' :m_b9.SetState ( 1 ) ;numbers0to9 ( 10 ) ;Sleep ( 20 ) ;m_b9.SetState ( 0 ) ;break ;case VK_DIVIDE :m_b10.SetState ( 1 ) ;divide( );Sleep ( 20 ) ;m_b10.SetState ( 0 ) ;break ;case VK_NUMPAD4 :case '4' :m_b13.SetState ( 1 ) ;numbers0to9 ( 5 ) ;Sleep ( 2

45、0 ) ;m_b13.SetState ( 0 ) ;break ;case VK_NUMPAD5 :case '5' :m_b14.SetState ( 1 ) ;numbers0to9 ( 6 ) ;Sleep ( 20 ) ;m_b14.SetState ( 0 ) ;break ;case VK_NUMPAD6 :case '6' :m_b15.SetState ( 1 ) ;numbers0to9 ( 7 ) ;Sleep ( 20 ) ;m_b15.SetState ( 0 ) ;break ;case VK_MULTIPLY :m_b16.SetS

46、tate ( 1 ) ;multiply( ) ;Sleep ( 20 ) ;m_b16.SetState ( 0 ) ;break ;case VK_NUMPAD1 :case '1' :m_b19.SetState ( 1 ) ;numbers0to9 ( 2 ) ;Sleep ( 20 ) ;m_b19.SetState ( 0 ) ;break ;case VK_NUMPAD2 :case '2' :m_b20.SetState ( 1 ) ;numbers0to9 ( 3 ) ;Sleep ( 20 ) ;m_b20.SetState ( 0 ) ;b

47、reak ;case VK_NUMPAD3 :case '3' :m_b21.SetState ( 1 ) ;numbers0to9 ( 4 ) ;Sleep ( 20 ) ;m_b21.SetState ( 0 ) ;break ;case VK_SUBTRACT :m_b22.SetState ( 1 ) ;minus( );Sleep ( 20 ) ;m_b22.SetState ( 0 ) ;break ;case VK_NUMPAD0 :case '0' :m_b25.SetState ( 1 ) ;numbers0to9 ( 1 ) ;Sleep (

48、 20 ) ;m_b25.SetState ( 0 ) ;break ;case VK_DECIMAL :m_b27.SetState ( 1 ) ;point( ) ;Sleep ( 20 ) ;m_b27.SetState ( 0 ) ;break ;case VK_ADD :m_b28.SetState ( 1 ) ;plus( ) ;Sleep ( 20 ) ;m_b28.SetState ( 0 ) ;break ;case VK_RETURN :m_b29.SetState ( 1 ) ;equalto( ) ;Sleep ( 20 ) ;m_b29.SetState ( 0 ) ;break ;myframe.hclass myframe :

溫馨提示

  • 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論