版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、科学计算器1、基本功能的设计实现了一个功能强大的科学计算器不仅实现了标准的加减乘除运算,而其还可以进行三角函数、对数、逻辑等复杂运算。使用者 可以通过按钮和菜单转换计算器的类型。本例的计算器具有如下功能。 科学计算器中, 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025新款房屋租赁合同范本「官方版」
- 2025二手车买卖租赁合同范本
- 高考试题及答案不得公布
- 分光计考试题及答案
- 防火灾培训考试题及答案
- 动画色彩考试题目及答案
- 中国工业洗瓶剂项目创业投资方案
- 电网营销岗考试题及答案
- 固废处理可行性研究报告
- 电工考试题目大全及答案
- 2025年下半年四川广元青川县招聘事业单位工作人员18人重点基础提升(共500题)附带答案详解
- 人教版五年级数学上学期第三单元 小数除法综合提优卷(A)(含答案)
- 大庆市2025黑龙江大庆市机关事务服务中心所属事业单位选调工作人员10人笔试历年参考题库附带答案详解
- GB/T 4744-2013纺织品防水性能的检测和评价静水压法
- C语言期末题库(八套试卷)及答案
- 印刷包装企业风险分级管控告知牌
- 等差数列的前n项和 完整版PPT
- JJF 1318-2011 影像测量仪校准规范-(高清现行)
- 小学信息技术五年级全册教案(全面完整版)
- 卫生部心血管疾病介入诊疗技术培训教材(共206页)
- 优才内经复习指导
评论
0/150
提交评论