科學計算器講解_第1頁
科學計算器講解_第2頁
科學計算器講解_第3頁
科學計算器講解_第4頁
科學計算器講解_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、科學計算器1、基本功能的設計實現(xiàn)了一個功能強大的科學計算器不僅實現(xiàn)了標準的加減乘除運算,而其還可以進行三角函數、對數、邏輯等復雜運算。使用者 可以通過按鈕和菜單轉換計算器的類型。本例的計算器具有如下功能。 科學計算器中, BackSpance、CE、C 和運算符號 +、-、* 、/、.、-/+、=以及標準型計算器的設計。 科學型角度弧度的設計。 科學計算器中, x2,x3,xy,1/x,n !,Log,In 按鍵,及各進制轉之間的相互轉換的設計。 科學計算器中, sin, cos,tan,dms,F-E,Exp、pi、Dat、s、Sum 等按 鈕以 sin/cos/tan 計算時角度和弧度的轉

2、換的設計。 科學行計算器中, Mod,Not ,And,Xor ,Int,Or,lsh,exit 按鈕。 標準型菜單部分(查看菜單標準型、科學型。幫助菜單中包含關于(about)及標準型和科學型的數字鍵和科學型的各進制轉換的設計。2、編成流程3、詳細設計( 1)Animal1 窗體Animal1 窗體是標準的計算器操作界面Dim dflag As IntegerDim i As IntegerDim opnre As IntegerDim prev As DoubleDim oflag As IntegerDim ind As IntegerPrivate Sub Command1_Click

3、(Index As Integer)If ind = 4 Thenprev = 0Text1.Caption = ind = 0End If opnre = 0 If oflag = 0 ThenText1.Caption = End If oflag = 1 If Command1(Index).Caption . ThenIf Text1.Caption 0 ThenText1.Caption = Text1.Caption & Command1(Index).Caption ElseText1.Caption = & Command1(Index).Caption End IfElseI

4、f dflag = 0 ThenText1.Caption = Text1.Caption & . dflag = 1ElseMsgBox (ILLEGAL SAIRAM) End IfEnd IfEnd SubPrivate Sub Command2_Click(Index As Integer) If opnre = 0 Or Index = 4 ThenIf ind = 0 Thenprev = prev + Val(Text1.Caption) ElseIf ind = 1 Thenprev = prev - Val(Text1.Caption) ElseIf ind = 2 Then

5、If Val(Text1.Caption) = 0 Then MsgBox (SORRY DIVIDE ZERO) Exit SubElseprev = prev / Val(Text1.Caption) End IfElseIf ind = 3 Then prev = prev * Val(Text1.Caption)End IfText1.Caption = Str(prev) oflag = 0 End If opnre = 1 ind = Index dflag = 0End SubPrivate Sub Command3_Click() Text1.Caption = 0End Su

6、bPrivate Sub Command4_Click() dflag = 0 prev = 0 oflag = 0 ind = 0 opnre = 0Text1.Caption = 0End SubPrivate Sub Command5_Click() Unload Me scientific.ShowEnd SubPrivate Sub ecopy_Click() Clipboard.Clear Clipboard.SetText Text1.CaptionEnd SubPrivate Sub ecut_Click()Clipboard.ClearClipboard.SetText Te

7、xt1.CaptionText1.Caption = End SubPrivate Sub eexit_Click()Unload MeEnd SubPrivate Sub epaste_Click()Text1.Caption = Text1.Caption = Clipboard.GetText() End SubPrivate Sub eselectall_Click()Clipboard.ClearClipboard.SetText Text1.CaptionEnd SubPrivate Sub Form_KeyPress(KeyAscii As Integer)If KeyAscii

8、 = Asc(.) Theni = 10Command1_Click (i)BeepElseIf KeyAscii = Asc(0) Theni = 0Command1_Click (i)BeepElseIf KeyAscii = Asc(1) Theni = 1Command1_Click (i)BeepElseIf KeyAscii = Asc(2) Theni = 2Command1_Click (i)BeepElseIf KeyAscii = Asc(3) Theni = 3Command1_Click (i)BeepElseIf KeyAscii = Asc(4) Theni = 4

9、 Command1_Click (i)BeepElseIf KeyAscii = Asc(5) Then i = 5Command1_Click (i) BeepElseIf KeyAscii = Asc(6) Then i = 6Command1_Click (i) BeepElseIf KeyAscii = Asc(7) Then i = 7Command1_Click (i) BeepElseIf KeyAscii = Asc(8) Then i = 8Command1_Click (i) BeepElseIf KeyAscii = Asc(9) Then i = 9Command1_C

10、lick (i) BeepElseIf KeyAscii = Asc(0) Then i = 0Command1_Click (i) BeepElseIf KeyAscii = Asc(+) Then i = 0Command2_Click (i) BeepElseIf KeyAscii = Asc(+) Then i = 0Command2_Click (i) BeepElseIf KeyAscii = Asc(-) Then i = 1Command2_Click (i) BeepElseIf KeyAscii = Asc(/) Then i = 2Command2_Click (i) B

11、eepElseIf KeyAscii = Asc(*) Then i = 3Command2_Click (i) BeepElseIf KeyAscii = Asc(=) Then i = 4Command2_Click (i) BeepElseIf KeyAscii = Asc(c) Or KeyAscii = Asc(C) Then dflag = 0 prev = 0 oflag = 0 ind = 0 opnre = 0Text1.Caption = 0BeepBeepElseIf KeyAscii = Asc(d) Or KeyAscii = Asc(D) Then Text1.Ca

12、ption = 0BeepEnd IfEnd SubPrivate Sub Form_Load() standard.Height = 4090 standard.Width = 3430 dflag = 0 prev = 0 oflag = 0 ind = 0 opnre = 0 Clipboard.ClearEnd SubPrivate Sub habout_Click() nachelp.ShowEnd SubPrivate Sub hcontents_Click() nachelp.ShowEnd SubPrivate Sub Option1_Click() scientific.Sh

13、ow standard.Option1.Value = False standard.HideEnd SubPrivate Sub tscientific_Click() scientific.Show standard.HideEnd SubPrivate Sub tstandard_Click() standard.Show scientific.HideEnd Sub2)Anima2 窗體Anima2 窗體是科學計算器的操作界面Dim que(25) As Double Public qt As Integer Public qh As Integer Public qv As Inte

14、ger Public ang As DoublePublic memo As Double Dim dflag As Integer Dim i As Integer Dim opnre As Integer Dim prev As Double Dim oflag As Integer Dim ind As IntegerPrivate Sub Command1_Click(Index As Integer) If ind = 4 Thenprev = 0 Text1.Text = ind = 0End Ifopnre = 0 conform operandIf oflag = 0 Then

15、 if previous operator clear text Text1.Text = End Ifoflag = 1 If Command1(Index).Caption . ThenIf Text1.Text 0 ThenText1.Text = Text1.Text & Command1(Index).Caption ElseText1.Text = & Command1(Index).Caption End IfElseIf dflag = 0 Then Text1.Text = Text1.Text & . dflag = 1Else MsgBox (ILLEGAL SAIRAM

16、)End IfEnd IfEnd SubPrivate Sub Command10_Click(Index As Integer)If Index = 2 ThenIf Val(Text1.Text) 0 ThenText1.Text = Str(Log(Val(Text1.Text) ElseMsgBox ( ILLEGAL. LOG NON POSITIVE ) End IfElseIf Index = 1 ThenIf Val(Text1.Text) 0 ThenText1.Text = Str(Log(Val(Text1.Text) / Log(10) ElseMsgBox ( ILL

17、EGAL. LOG NON POSITIVE ) End IfEnd IfEnd SubPrivate Sub Command11_Click()If (Text1.Text ) Then9Text1.Text = Mid(Text1.Text, 1, Len(Text1.Text) - 1) End IfEnd SubPrivate Sub Command13_Click()Unload MeEnd SubPrivate Sub Command14_Click()Text1.Text = Str(Val(Text1.Text) * -1)End Sub Function qnext(p As

18、 Integer) As IntegerOn Error Resume Next qnext = (p + 1) Mod qtEnd FunctionFunction power(x As Double, Y As Long) As Double Dim i As Double i = 1If (Y 0) Then While Y 0Y = Y - 1i = i * x Wend power = i ElseIf (Y = 0) Then power = 1 ElseMsgBox (ILLEGAL. POWER LESTHAN 0.) End IfEnd FunctionFunction fa

19、ct(num As Long) As LongIf (num 12) ThenMsgBox (VALUE TOO LARGE) fact = numElsere = 1 While (num 0) re = re * num num = num - 110Wend fact = re End IfEnd IfEnd Function Private Sub Command2_Click(Index As Integer)Dim n As LongDim r As LongIf opnre = 0 Or Index = 4 ThenIf ind = 0 Thenprev = prev + Val

20、(Text1.Text) ElseIf ind = 1 Thenprev = prev - Val(Text1.Text) ElseIf ind = 6 Then prev = prev Mod Val(Text1.Text)ElseIf ind = 7 Then r = Fix(Val(Text1.Text) n = Fix(Val(prev) If (n r Or n = r) And n 0 And (r 0 Or r = 0) Then prev = fact(n) / (fact(n - r)ElseMsgBox (ILLEGAL ENTRIES of N ,R ) End IfEl

21、seIf ind = 5 Then r = Fix(Val(Text1.Text) n = Fix(Val(prev) If (n r Or n = r) And n 0 And (r 0 Or r = 0) Then prev = fact(n) / (fact(n - r) * fact(r) ElseMsgBox (ILLEGAL ENTRIES of N ,R ) End IfElseIf ind = 8 ThenIf (Text1.Text = Or prev = 0) ThenMsgBox (ILLEGAL. INV ALIED ENTRIES) Else prev = (powe

22、r(prev, Fix(Val(Text1.Text)End IfElseIf ind = 2 ThenIf Val(Text1.Text) 0 Then prev = prev / Val(Text1.Text)11ElseMsgBox ( ILLEGAL DIVIDE 0 ) End IfElseIf ind = 3 Then prev = prev * Val(Text1.Text)End IfText1.Text = Str(prev) oflag = 0 operator or operandEnd Ifopnre = 1 multiple operators flagind = I

23、ndexdflag = 0End SubPrivate Sub Command3_Click(Index As Integer) Text1.Text = 0End SubPrivate Sub Command4_Click(Index As Integer) memo = 0 dflag = 0 prev = 0 oflag = 0 ind = 0 opnre = 0 qh = 0 qt = 0Clipboard.ClearText1.Text = 0End SubPrivate Sub Command5_Click(Index As Integer) Select Case IndexCa

24、se 0Text1.Text = Str(Sin(ang * Val(Text1.Text)Case 1Text1.Text = Str(Cos(ang * Val(Text1.Text)Case 2If (Cos(Val(Text1.Text) 0 Then Text1.Text = Str(Sin(ang * Val(Text1.Text) / Cos(ang * Val(Text1.Text)ElseMsgBox (ILLEGAL. DIVIDE BY ZERO ) End If12Case 5Text1.Text = Str(Atn(Val(Text1.Text) / ang)End

25、SelectEnd SubPrivate Sub Command6_Click(Index As Integer)Dim re As LongDim temp As Longtemp = Val(scientific.Text1.Text)Select Case IndexCase 2 temp = Val(Text1.Text)If temp 0 Or temp = 0 Then scientific.Text1.Text = Str(Sqr(Val(Text1.Text)ElseMsgBox ( ILLEGAL ATTEMPTING NEGETIVE ROOT)End IfCase 0te

26、mp = Val(Text1.Text)If temp 0 Then scientific.Text1.Text = Str(1 / temp)ElseMsgBox ( ILLEGAL DIVIDE 0 )End IfCase 1If Abs(Val(Text1.Text) 46300 Then scientific.Text1.Text = Str(temp * temp)ElseMsgBox ( ILLEGAL DIVIDE 0 )End IfCase 8If Abs(Val(Text1.Text) 1290 Then scientific.Text1.Text = Str(temp *

27、temp * temp)ElseMsgBox (OVERFLOW. V ALUE TOO LARGE )End IfCase 4Text1.Text = Str(fact(Val(Text1.Text)End Select13End SubPrivate Sub Command7_Click(Index As Integer)Select Case IndexCase 0memo = memo + Val(Text1.Text)Case 1memo = memo - Val(Text1.Text)Case 2memo = memo * Val(Text1.Text)Case 3If Val(T

28、ext1.Text) 0 Then memo = memo / Val(Text1.Text)ElseMsgBox (ILLEGAL. DIVIDE 0 ERROR )End IfCase 4Text1.Text = Str(memo)prev = Val(Text1.Text)Case 5memo = 0End SelectEnd SubPrivate Sub Command8_Click(Index As Integer) Select Case IndexCase 0 que(qt) = Val(Text1.Text) qt = qt + 1Case 1qv = qnext(qv) La

29、bel1.Caption = Str(que(qv) qv = qnext(qv)Case 2On Error GoTo anil que(qv) = que(qt - 1) Label1.Caption = Str(que(qv) qt = qt - 1Case 3Text1.Text = Label1.CaptionEnd Select14anil:End SubPrivate Sub Command9_Click(Index As Integer) Select Case IndexCase 0Text1.Text = Str(Rnd)Case 1 Text1.Text = 3.1415

30、92654Case 2 Text1.Text = 2.718281828Case 3 Text1.Text = 9.86Case 4Text1.Text = 6.625End Selectopnre = 0 If oflag = 0 Then Text1.Text = End Ifoflag = 1 End Sub Private Sub Command4_Click()dflag = 0prev = 0 oflag = 0 ind = 0opnre = 0 Text1.Text = 0End SubPrivate Sub Command5_Click() Unload Me EndEnd S

31、ubPrivate Sub ecopy_Click() Clipboard.Clear Clipboard.SetText Text1.SelText15End SubPrivate Sub ecut_Click()Clipboard.ClearClipboard.SetText Text1.SelTextText1.SelText = End SubPrivate Sub eexit_Click()Unload MeEnd SubPrivate Sub epaste_Click()Text1.Text = Text1.SelText = Clipboard.GetText()End SubP

32、rivate Sub eselectall_Click()Clipboard.ClearClipboard.SetText Text1.TextEnd SubPrivate Sub Form_KeyPress(KeyAscii As Integer)If KeyAscii = Asc(.) Theni = 10Command1_Click (i)BeepElseIf KeyAscii = Asc(0) Theni = 0Command1_Click (i)BeepElseIf KeyAscii = Asc(1) Theni = 1Command1_Click (i)BeepElseIf Key

33、Ascii = Asc(2) Theni = 2Command1_Click (i)BeepElseIf KeyAscii = Asc(3) Theni = 316Command1_Click (i) BeepElseIf KeyAscii = Asc(4) Then i = 4Command1_Click (i) BeepElseIf KeyAscii = Asc(5) Then i = 5Command1_Click (i) BeepElseIf KeyAscii = Asc(6) Then i = 6Command1_Click (i) BeepElseIf KeyAscii = Asc

34、(7) Then i = 7Command1_Click (i) BeepElseIf KeyAscii = Asc(8) Then i = 8Command1_Click (i) BeepElseIf KeyAscii = Asc(9) Then i = 9Command1_Click (i) BeepElseIf KeyAscii = Asc(0) Then i = 0Command1_Click (i) BeepElseIf KeyAscii = Asc(+) Then i = 0Command2_Click (i) BeepElseIf KeyAscii = Asc(+) Then i = 0Command2_Click (i) BeepElseIf KeyAscii = Asc(-) Then i = 1Comma

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論