科学计算器汇总.docx
- 文档编号:16960843
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:29
- 大小:88.94KB
科学计算器汇总.docx
《科学计算器汇总.docx》由会员分享,可在线阅读,更多相关《科学计算器汇总.docx(29页珍藏版)》请在冰点文库上搜索。
科学计算器汇总
科学计算器
1、基本功能的设计
实现了一个功能强大的科学计算器——不仅实现了标准的加减乘除运算,而其还可以进行三角函数、对数、逻辑等复杂运算。
使用者可以通过按钮和菜单转换计算器的类型。
本例的计算器具有如下功能。
①科学计算器中,BackSpance、CE、C和运算符号+、-、*、/、.、-/+、=以及标准型计算器的设计。
②科学型角度弧度的设计。
③科学计算器中,x^2,x^3,x^y,1/x,n!
Log,In按键,及各进制转之间的相互转换的设计。
④科学计算器中,sin,cos,tan,dms,F-E,Exp、pi、Dat、s、Sum等按钮以sin/cos/tan计算时角度和弧度的转换的设计。
⑤科学行计算器中,Mod,Not,And,Xor,Int,Or,lsh,exit按钮。
⑥标准型菜单部分(查看菜单标准型、科学型。
帮助菜单中包含关于(about)及标准型和科学型的数字键和科学型的各进制转换的设计。
2、编成流程
3、详细设计
(1)Animal1窗体
Animal1窗体是标准的计算器操作界面。
DimdflagAsInteger
DimiAsInteger
DimopnreAsInteger
DimprevAsDouble
DimoflagAsInteger
DimindAsInteger
PrivateSubCommand1_Click(IndexAsInteger)
Ifind=4Then
prev=0
Text1.Caption=""
ind=0
EndIf
opnre=0
Ifoflag=0Then
Text1.Caption=""
EndIf
oflag=1
IfCommand1(Index).Caption<>"."Then
IfText1.Caption<>"0"Then
Text1.Caption=Text1.Caption&Command1(Index).Caption
Else
Text1.Caption=""&Command1(Index).Caption
EndIf
Else
Ifdflag=0Then
Text1.Caption=Text1.Caption&"."
dflag=1
Else
MsgBox("ILLEGALSAIRAM")
EndIf
EndIf
EndSub
PrivateSubCommand2_Click(IndexAsInteger)
Ifopnre=0OrIndex=4Then
Ifind=0Then
prev=prev+Val(Text1.Caption)
ElseIfind=1Then
prev=prev-Val(Text1.Caption)
ElseIfind=2Then
IfVal(Text1.Caption)=0Then
MsgBox("SORRYDIVIDEZERO")
ExitSub
Else
prev=prev/Val(Text1.Caption)
EndIf
ElseIfind=3Then
prev=prev*Val(Text1.Caption)
EndIf
Text1.Caption=Str(prev)
oflag=0
EndIf
opnre=1
ind=Index
dflag=0
EndSub
PrivateSubCommand3_Click()
Text1.Caption="0"
EndSub
PrivateSubCommand4_Click()
dflag=0
prev=0
oflag=0
ind=0
opnre=0
Text1.Caption="0"
EndSub
PrivateSubCommand5_Click()
UnloadMe
scientific.Show
EndSub
PrivateSubecopy_Click()
Clipboard.Clear
Clipboard.SetTextText1.Caption
EndSub
PrivateSubecut_Click()
Clipboard.Clear
Clipboard.SetTextText1.Caption
Text1.Caption=""
EndSub
PrivateSubeexit_Click()
UnloadMe
EndSub
PrivateSubepaste_Click()
Text1.Caption=""
Text1.Caption=Clipboard.GetText()
EndSub
PrivateSubeselectall_Click()
Clipboard.Clear
Clipboard.SetTextText1.Caption
EndSub
PrivateSubForm_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=Asc(".")Then
i=10
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("0")Then
i=0
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("1")Then
i=1
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("2")Then
i=2
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("3")Then
i=3
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("4")Then
i=4
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("5")Then
i=5
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("6")Then
i=6
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("7")Then
i=7
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("8")Then
i=8
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("9")Then
i=9
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("0")Then
i=0
Command1_Click(i)
Beep
ElseIfKeyAscii=Asc("+")Then
i=0
Command2_Click(i)
Beep
ElseIfKeyAscii=Asc("+")Then
i=0
Command2_Click(i)
Beep
ElseIfKeyAscii=Asc("-")Then
i=1
Command2_Click(i)
Beep
ElseIfKeyAscii=Asc("/")Then
i=2
Command2_Click(i)
Beep
ElseIfKeyAscii=Asc("*")Then
i=3
Command2_Click(i)
Beep
ElseIfKeyAscii=Asc("=")Then
i=4
Command2_Click(i)
Beep
ElseIfKeyAscii=Asc("c")OrKeyAscii=Asc("C")Then
dflag=0
prev=0
oflag=0
ind=0
opnre=0
Text1.Caption="0"
Beep
Beep
ElseIfKeyAscii=Asc("d")OrKeyAscii=Asc("D")Then
Text1.Caption="0"
Beep
EndIf
EndSub
PrivateSubForm_Load()
'standard.Height=4090
'standard.Width=3430
dflag=0
prev=0
oflag=0
ind=0
opnre=0
Clipboard.Clear
EndSub
PrivateSubhabout_Click()
nachelp.Show
EndSub
PrivateSubhcontents_Click()
nachelp.Show
EndSub
PrivateSubOption1_Click()
scientific.Show
standard.Option1.Value=False
standard.Hide
EndSub
PrivateSubtscientific_Click()
scientific.Show
standard.Hide
EndSub
PrivateSubtstandard_Click()
standard.Show
scientific.Hide
EndSub
(2)Anima2窗体
Anima2窗体是科学计算器的操作界面。
Dimque(25)AsDouble
PublicqtAsInteger
PublicqhAsInteger
PublicqvAsInteger
PublicangAsDouble
PublicmemoAsDouble
DimdflagAsInteger
DimiAsInteger
DimopnreAsInteger
DimprevAsDouble
DimoflagAsInteger
DimindAsInteger
PrivateSubCommand1_Click(IndexAsInteger)
Ifind=4Then
prev=0
Text1.Text=""
ind=0
EndIf
opnre=0'conformoperand
Ifoflag=0Then'ifpreviousoperatorcleartext
Text1.Text=""
EndIf
oflag=1
IfCommand1(Index).Caption<>"."Then
IfText1.Text<>"0"Then
Text1.Text=Text1.Text&Command1(Index).Caption
Else
Text1.Text=""&Command1(Index).Caption
EndIf
Else
Ifdflag=0Then
Text1.Text=Text1.Text&"."
dflag=1
Else
MsgBox("ILLEGALSAIRAM")
EndIf
EndIf
EndSub
PrivateSubCommand10_Click(IndexAsInteger)
IfIndex=2Then
IfVal(Text1.Text)<700Then
Text1.Text=Str(Exp(Val(Text1.Text)))
Else
MsgBox("OVERFLOW.VALUETOOBIG")
EndIf
ElseIfIndex=0Then
IfVal(Text1.Text)>0Then
Text1.Text=Str(Log(Val(Text1.Text)))
Else
MsgBox("ILLEGAL.LOGNONPOSITIVE")
EndIf
ElseIfIndex=1Then
IfVal(Text1.Text)>0Then
Text1.Text=Str((Log(Val(Text1.Text))/Log(10)))
Else
MsgBox("ILLEGAL.LOGNONPOSITIVE")
EndIf
EndIf
EndSub
PrivateSubCommand11_Click()
If(Text1.Text<>"")Then
Text1.Text=Mid(Text1.Text,1,Len(Text1.Text)-1)
EndIf
EndSub
PrivateSubCommand13_Click()
UnloadMe
EndSub
PrivateSubCommand14_Click()
Text1.Text=Str(Val(Text1.Text)*-1)
EndSub
Functionqnext(pAsInteger)AsInteger
OnErrorResumeNext
qnext=(p+1)Modqt
EndFunction
Functionpower(xAsDouble,YAsLong)AsDouble
DimiAsDouble
i=1
If(Y>0)Then
WhileY>0
Y=Y-1
i=i*x
Wend
power=i
ElseIf(Y=0)Then
power=1
Else
MsgBox("ILLEGAL.POWERLESTHAN0.")
EndIf
EndFunction
Functionfact(numAsLong)AsLong
If(num<0Ornum=0)Then
MsgBox("ILLEGALNEAGETIVEFACTORIAL")
fact=num
Else
If(num>12)Then
MsgBox("VALUETOOLARGE")
fact=num
Else
re=1
While(num>0)
re=re*num
num=num-1
Wend
fact=re
EndIf
EndIf
EndFunction
PrivateSubCommand2_Click(IndexAsInteger)
DimnAsLong
DimrAsLong
Ifopnre=0OrIndex=4Then
Ifind=0Then
prev=prev+Val(Text1.Text)
ElseIfind=1Then
prev=prev-Val(Text1.Text)
ElseIfind=6Then
prev=prevModVal(Text1.Text)
ElseIfind=7Then
r=Fix(Val(Text1.Text))
n=Fix(Val(prev))
If((n>rOrn=r)Andn>0And(r>0Orr=0))Then
prev=fact(n)/(fact(n-r))
Else
MsgBox("ILLEGALENTRIESofN,R")
EndIf
ElseIfind=5Then
r=Fix(Val(Text1.Text))
n=Fix(Val(prev))
If((n>rOrn=r)Andn>0And(r>0Orr=0))Then
prev=fact(n)/(fact(n-r)*fact(r))
Else
MsgBox("ILLEGALENTRIESofN,R")
EndIf
ElseIfind=8Then
If(Text1.Text=""Orprev=0)Then
MsgBox("ILLEGAL.INVALIEDENTRIES")
Else
prev=(power(prev,Fix(Val(Text1.Text))))
EndIf
ElseIfind=2Then
IfVal(Text1.Text)<>0Then
prev=prev/Val(Text1.Text)
Else
MsgBox("ILLEGALDIVIDE0")
EndIf
ElseIfind=3Then
prev=prev*Val(Text1.Text)
EndIf
Text1.Text=Str(prev)
oflag=0'operatororoperand
EndIf
opnre=1'multipleoperatorsflag
ind=Index
dflag=0
EndSub
PrivateSubCommand3_Click(IndexAsInteger)
Text1.Text="0"
EndSub
PrivateSubCommand4_Click(IndexAsInteger)
memo=0
dflag=0
prev=0
oflag=0
ind=0
opnre=0
qh=0
qt=0
Clipboard.Clear
Text1.Text="0"
EndSub
PrivateSubCommand5_Click(IndexAsInteger)
SelectCaseIndex
Case0
Text1.Text=Str(Sin(ang*Val(Text1.Text)))
Case1
Text1.Text=Str(Cos(ang*Val(Text1.Text)))
Case2
If(Cos(Val(Text1.Text)))<>0Then
Text1.Text=Str(Sin(ang*Val(Text1.Text))/Cos(ang*Val(Text1.Text)))
Else
MsgBox("ILLEGAL.DIVIDEBYZERO")
EndIf
Case5
Text1.Text=Str((Atn(Val(Text1.Text)))/ang)
EndSelect
EndSub
PrivateSubCommand6_Click(IndexAsInteger)
DimreAsLong
DimtempAsLong
temp=Val(scientific.Text1.Text)
SelectCaseIndex
Case2
'temp=Val(Text1.Text)
Iftemp>0Ortemp=0Then
scientific.Text1.Text=Str(Sqr(Val(Text1.Text)))
Else
MsgBox("ILLEGALATTEMPTINGNEGETIVEROOT")
EndIf
Case0
temp=Val(Text1.Text)
Iftemp<>0Then
scientific.Text1.Text=Str(1/temp)
Else
MsgBox("ILLEGALDIVIDE0")
EndIf
Case1
IfAbs(Val(Text1.Text))<46300Then
scientific.Text1.Text=Str((temp*temp))
Else
MsgBox("ILLEGALDIVIDE0")
EndIf
Case8
IfAbs(Val(Text1.Text))<1290Then
scientific.Text1.Text=Str(temp*temp*temp)
Else
MsgBox("OVERFLOW.VALUETOOLARGE")
EndIf
Case4
Text1.Text=Str(fact(Val(Text1.Text)))
EndSelect
EndSub
PrivateSubCommand7_Click(IndexAsInteger)
SelectCaseIndex
Case0
memo=memo+Val(Text1.Text)
Case1
memo=memo-Val(Text1.Text)
Case2
memo=memo*Val(Text1.Text)
Case3
IfVal(Text1.Text)<>0Then
memo=memo/Val(Text1.Text)
Else
MsgBox("ILLEGAL.DIVIDE0ERROR")
EndIf
Case4
Text1.Text=Str(memo)
prev=Val(Text1.Text)
Case5
memo=0
EndSelect
EndSub
PrivateSubCommand8_Click(IndexAsInteger)
SelectCaseIndex
Case0
que(q
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 科学 计算器 汇总