實(shí)用計(jì)算器之程序設(shè)計(jì)
[摘 要]多用計(jì)算器的構(gòu)思及設(shè)計(jì)代碼
[關(guān)鍵詞]多用計(jì)算器;設(shè)計(jì)
數(shù)值計(jì)算可以說(shuō)是日常最頻繁的工作了,WIN98提供了“計(jì)算器”軟件供用戶(hù)使用,該軟件可以處理一般的一步四則運(yùn)算,例如:3+2、5/3等等,但在日常中用戶(hù)經(jīng)常遇到多步四則運(yùn)算問(wèn)題,例如:3+4*5-4/2,45*34/2+18*7等等,那么該個(gè)計(jì)算器就無(wú)法勝任了,作者制作了一個(gè)實(shí)用的計(jì)算器,該計(jì)算器新增不少功能:(程序界面如圖)
1.可以實(shí)現(xiàn)連續(xù)的四則運(yùn)算
2.可以實(shí)現(xiàn)輸入式子的顯示
3.可以方便計(jì)算個(gè)人所得稅
4.鼠標(biāo)、鍵盤(pán)均可輸入數(shù)據(jù)
5.操作界面友好
6.擊鍵可發(fā)聲
構(gòu)建該個(gè)計(jì)算器所需研究及解決的核心問(wèn)題有如下幾個(gè):1、連乘求值?2、字符顯示 3、鍵盤(pán)輸入?4、擊鍵發(fā)聲?5、個(gè)人所得稅法規(guī),為了使大家對(duì)程序有更一步認(rèn)識(shí),現(xiàn)將代碼提供給讀者參考:
*定義數(shù)組及窗體變量
Dim number2(0 To 50) As Double
Dim number(0 To 50) As Double
Dim z As Integer
Dim k As Integer, r As Integer
Dim j As Integer
Dim str As String
*調(diào)用名為“playsound”的API函數(shù)
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME = &H20000?
Private Const SND_ASYNC = &H1?
Private Const SND_SYNC = &H0
*判斷通用過(guò)程
Sub pianduan(p As String)
r = 0
Dim i As Integer, l As Integer, h As Integer
h = 0
i = 1
If InStr(Trim$(p), "*")0 Then
k = k + 1
End If
If InStr(Trim$(p), "/")0 Then
r = r + 1
End If
End Sub
*連乘通用過(guò)程(略)
*各按鈕事件過(guò)程
Private sub Command1_Click(Index As Integer)
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text1.Text = Text1.Text + Command1(Index).Caption
Text2.Text = Text2.Text + Command1(Index).Caption
Text1.SetFocus
End Sub
rivate sub Command10_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
str = Text3.Text
End Sub
Private sub Command11_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text3.Text = str
End Sub
rivate sub Command2_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "+"
z = z + 1
Text1.SetFocus
End Sub
rivate sub Command3_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "-"
Text1.Text = Text1.Text & "-"
z = z + 1
Text1.SetFocus
End Sub
Private sub Command4_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text2.Text = Text2.Text + "*"
Text1.Text = Text1.Text + "*"
Text1.SetFocus
End Sub
rivate sub Command5_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text2.Text = Text2 + "/"
Text1.Text = Text1 + "/"
Text1.SetFocus
End Sub
Private sub Command6_Click()
PlaySound App.Path & "\sound.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
z = z + 1
Dim dengyu As Double
Dim v As Integer
For v = 0 To 50
dengyu = dengyu + number2(v)
Next v
If dengyu < 0 Then
Text3.ForeColor = &HFF&
Else
Text3.ForeColor = &HFF0000
End If
Text3.Text = dengyu
Text1.SetFocus
If Len(Text3.Text) >= 14 Then
calcresult.Show
End If
End Sub
rivate sub Command7_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
z = 0: k = 0: r = 0: j = 0
Dim i As Integer
For i = 0 To 50
number(i) = 0
number2(i) = 0
Next i
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub
rivate sub Command8_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
If Val(Text3.Text) = 0 Then
MsgBox "除數(shù)不能為0!"
Exit Sub
End If
Text3.Text = 1 / Val(Text3.Text)
End Sub
Private sub Command9_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text3.ForeColor = &HFF0000
Text3.Text = Val(Text3.Text) * Val(Text3.Text)
End Sub
rivate sub muninternet_Click()
Dim i
i = Shell("C:\Program Files\InternetExplorer\iexplore.exe", vbMaximizedFocus)
End Sub
rivate sub munmp3_Click()
Dim i
i = Shell("C:\Program Files\Windows Media Player\mplayer2", vbNormalNoFocus)
End Sub
Private sub munsm_Click()
Dialog.Show
End Sub
rivate sub muntax_Click()
tax.Show
End Sub
rivate sub munver_Click()
ver.Show
End Sub
rivate sub notepad_Click()
Dim i
i = Shell("c:\windows\notepad", vbNormalFocus)
End Sub
Private sub Text1_KeyPress(KeyAscii As Integer)
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Dim num As Integer
num = Val(KeyAscii)
If num > 47 And num < 58 Then
Text1.Text = Text1.Text + CStr(num - 48)
Text2.Text = Text2.Text + CStr(num - 48)
End If
If num = 46 Then
Text1.Text = Text1.Text + "."
Text2.Text = Text2.Text + "."
End If
If KeyAscii = 43 Then
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "+"
z = z + 1
End If
If KeyAscii = 45 Then
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "-"
Text1.Text = Text1.Text & "-"
z = z + 1
End If
If KeyAscii = 42 Then
Text2.Text = Text2.Text + "*"
Text1.Text = Text1.Text + "*"
End If
If KeyAscii = 47 Then
Text2.Text = Text2.Text + "/"
Text1.Text = Text1.Text + "/"
End If
If KeyAscii = vbKeyReturn Then
PlaySound App.Path & "\sound.wav", 0, SND_SYNC
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
z = z + 1
Dim dengyu As Double
Dim v As Integer
For v = 0 To 50
dengyu = dengyu + number2(v)
Next v
If dengyu < 0 Then
Text3.ForeColor = &HFF&
Else
Text3.ForeColor = &HFF0000
End If
Text3.Text = dengyu
End If
If KeyAscii = vbKeyEscape Then
z = 0: k = 0: r = 0: j = 0
Dim i As Integer
For i = 0 To 50
number(i) = 0
number2(i) = 0
Next i
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End If
If Len(Text3.Text) >= 14 Then
calcresult.Show
End If
End Sub
rivate sub Text3_Change()
tax2.Text1 = Text3.Text
End Sub
c語(yǔ)言計(jì)算器程序設(shè)計(jì)包含加減乘除簡(jiǎn)單的函數(shù)運(yùn)算
c語(yǔ)言計(jì)算器程序設(shè)計(jì)包含加減乘除簡(jiǎn)單的函數(shù)運(yùn)算
其他人氣:685 ℃時(shí)間:2020-03-28 13:19:41
優(yōu)質(zhì)解答
我來(lái)回答
類(lèi)似推薦
- 用C語(yǔ)言編寫(xiě)一個(gè)簡(jiǎn)單的可以進(jìn)行加減乘除運(yùn)算混合運(yùn)算的計(jì)算器
- 用C語(yǔ)言設(shè)計(jì)一個(gè)簡(jiǎn)單計(jì)算器程序,能根據(jù)鍵盤(pán)輸入的運(yùn)算指令和數(shù)據(jù),做簡(jiǎn)單的加減乘除運(yùn)算.
- 碳酸鹽與鹽酸反應(yīng)放出的氣體,所以與鹽酸反應(yīng)放出氣體的物質(zhì)一定是碳酸鹽.
- 2又84/23減去1又60/49怎么算?
- what is the freezing point of platinum?
- 翻譯句子 這有幾罐可樂(lè).英文哦 急急急··········
- 一直關(guān)于x的方程a(x^2)+2x+1=0至少有一個(gè)負(fù)實(shí)數(shù)根,則實(shí)屬a的取值范圍 Aa
- 來(lái)幫我理解下這句話(huà)的意思
- 1加1加2分之1加1加2加3分之1加.加1加2加3加.加2000分之1 等于多少
- Each Branch
- 為什么二氧化碳與氫氧化鈉反應(yīng)不加水,而與碳酸鈉反應(yīng)需要加水
- 如何求y=(1/2)arcsin(1-2x)的反函數(shù)
猜你喜歡
- 1tell the truth 和 tell a lie的區(qū)別
- 2背英語(yǔ)單詞customs(海關(guān)) passport(護(hù)照) tourist(旅游者) employee(雇員) sales reps(推銷(xiāo)員)的秘訣
- 3什么叫圓的面積和周長(zhǎng)?
- 4每天運(yùn)320噸,需要15天才能運(yùn)完.如果運(yùn)的天數(shù)減少到原來(lái)的80%,每天比原來(lái)多運(yùn)多少?lài)?
- 5小貓抓老鼠,翻譯成英語(yǔ)是怎么樣的呢?
- 6在物理實(shí)驗(yàn)操作考查中,小雨抽測(cè)的實(shí)驗(yàn)題目是“探究浮力的大小”.他的實(shí)驗(yàn)操作步驟如圖所示,實(shí)驗(yàn)過(guò)程如下
- 7當(dāng)我看到某人在下雨的時(shí)候沒(méi)有雨傘,我會(huì)和他一起用我的雨傘 英語(yǔ)翻譯
- 8在直角坐標(biāo)系xoy中,反比例函數(shù)y=m/x的圖像與一次函數(shù)y=kx+b的圖像交于點(diǎn)A(m,2)和C(-2,-3)
- 9get rid of的意思和throw away 更近還是和set free 更近?或give up(好像差很遠(yuǎn))
- 103pint?pints?oficecream
- 11We had ( )exam ,It was( )English exam
- 12如圖,一根繩子在圓柱體上從一端到另一端繞了5整圈,圓柱底面周長(zhǎng)是6米,長(zhǎng)為40米,則繩子長(zhǎng)多少米?