VB科学计算器课程设计.doc_第1页
VB科学计算器课程设计.doc_第2页
VB科学计算器课程设计.doc_第3页
VB科学计算器课程设计.doc_第4页
VB科学计算器课程设计.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

湖南医药学院 VB计算器 课程设计题目: VB科学计算器 院(系)别 临床医学院 专 业 临床医学 班 级 本临一班 学 号 2015101010121 姓 名 夏铭锴 指导教师 李跃强 二一六 年 四 月目 录一、设计内容及要求2、 设计原始资料三、设计完成后提交的文件和图表设计四、进程安排五、主要参考资料摘 要用VB制作这个程序的简单计算器,它包括一个标准的计算器和一个科学计算器。它可以实现简单的加减乘除四则运算,数字的平方、平方根,正弦、余弦、正切,倒数、指数函数、对数函数,角度、弧度、梯度的转换,以及各进制的相互转换。而且它的功能还有退格,清除当前数据,清除所有数据,复制数据,粘贴数据。在这个计算器的程序中,我用到了单行选择语句IfThenElse,块语句ifthenendif,If语句的嵌套,多条件选择语句SelectCase,而且还用到了按钮、文本框、框架、单选按钮控件,菜单的设计。在此报告中我重点叙述了计算机的各个功能及用法。特别是进制间的转换和数字与运算符之间的联系。虽然描述的不太完整,但我会尽力使用系统结构图,划分多个模块,让大家明白我设计的运算器的功能的。关键词 VisualBasic;计算器;对象;代码1一、设计内容及要求本程序的目标是建立一套可以计算数的平方,平方根,倒数,正弦,余弦,正切,指数函数,对数函数的计算器系统。1.2、基本功能1)能够完成基本的四则运算。2)能够进行如下函数的求值运算,包括sin,cos,tan,exp,log,sqr,1/x,及和圆周率。3) 能够实现角度、弧度、梯度的相互转换。 4)能够实现的进制的相互转换。5)输出时的格式:结果为整数时不显示小数点,结果为1以下小数时要显示前导0。6)分门别类采用控件数组,以减少事件处理的复杂程度,使程序简洁高效。7)能够实现退格键、清除、清空功能。8)出错处理:操作数如果不符合数学上的定义,应该给出错误信息。二、设计原始资料 VB计算器四则运算(见附页)三、设计完成后提交的文件和图表设计(要求2000字以上)1. 设计方案实现这个实用计算器,要考虑的主要是以下两个方面的内容:一、设置每个控件按钮的属性。二、每组控件组都有自己的VB代码,由VB语言实现各个控件按钮的功能。于是本设计就是以这两个个部分为核心内容展开。根据设计要求该实用计算器能实现四则运算和部分科学计算法等按钮的控制,根据各组控件按钮源代码的不同,来实现按下不同的按键实现不同的计算过程或结果功能。本设计大体由窗体、CommandButton、Textbox、Timer四个模块构成。其中Commandbutton作为按钮模块,Textbox作为显示模块,Timer作为显示或隐藏部分按键的模块。Commandbutton按钮实现数字键和其他算法按键的功能;Textbox实现计算过程和结果的数字显示;Timerbox实现当计算器只用到四则的简单运算时,窗体只显示四种运算的基本按键,当用到科学计算时,再在窗体中显示科学计算的控件按钮。 2 流程图、图纸 计算器如图此计算器可以计算简单的加减乘除计算,还包括三角函数、乘方、阶乘、开方、对数等等的计算。加有退出键,说明按钮等控件。 总体设计框架4、 进程安排(1) 创建应用程序的界面。 (2) 设置属性。 (3) 编写代码。 (4) 调试运行。 (5) 保存工程及生成可执行文件。五、主要参考资料1.Visual Basic 6.0程序设计教程(第四版) 人民邮电出版社附页:设计原始资料Private Sub Command1_Click() 删除数字的最后一位 If Label3.Caption Then Label3.Caption = Left(Label3.Caption, Len(Label3.Caption) - 1) Else c = MsgBox(内容已为空!不可删除一位!, 49, 注意!) End IfEnd SubPrivate Sub Command10_Click() 输入数字6 Label3.Caption = Label3.Caption + Command10.CaptionEnd SubPrivate Sub Command11_Click() If Label3.Caption Then 输入符号* Label1.Caption = Label3.Caption Label2.Caption = Command11.Caption Label3.Caption = Else c = MsgBox(请输入数据后输入符号!, 49, 注意!) End IfEnd SubPrivate Sub Command12_Click() 输入数字1 Label3.Caption = Label3.Caption + Command12.CaptionEnd SubPrivate Sub Command13_Click() 输入数字2 Label3.Caption = Label3.Caption + Command13.CaptionEnd SubPrivate Sub Command14_Click() 输入数字3 Label3.Caption = Label3.Caption + Command14.CaptionEnd SubPrivate Sub Command15_Click() 输入符号 If Label2 Then Label3.Caption = -Val(Label3.Caption) Else Label1.Caption = Label3.Caption Label2.Caption = Command15.Caption Label3.Caption = End IfEnd SubPrivate Sub Command16_Click() 输入数字0 Label3.Caption = Label3.Caption + Command16.CaptionEnd SubPrivate Sub Command17_Click() 输入小数点 Label3.Caption = Label3.Caption + Command17.CaptionEnd SubPrivate Sub Command18_Click() “=”按钮 If Label1.Caption Then If Label2.Caption = * Then 计算乘法 Label3.Caption = Label1.Caption & * & Label3.Caption & = & Val(Label1.Caption) * Val(Label3.Caption) ElseIf Label2.Caption = / Then 计算除法 If Val(Label3.Caption) 0 Then Label3.Caption = Label1.Caption & / & Label3.Caption & = & Val(Label1.Caption) / Val(Label3.Caption) Else c = MsgBox(除数不能为0!请重新输入!, 49, 注意!) End If ElseIf Label2.Caption = - Then 计算减法 Label3.Caption = Label1.Caption & - & Label3.Caption & = & Val(Label1.Caption) - Val(Label3.Caption) ElseIf Label2.Caption = + Then 计算加法 Label3.Caption = Label1.Caption & + & Label3.Caption & = & Val(Label1.Caption) + Val(Label3.Caption) ElseIf Label2.Caption = mod Then 进行取余运算 If Label3.Caption = 0 Then c = MsgBox(除数不能为0! + Chr(13) + Chr(10) + 请重新输入!, 49, 提示!) Else Label3.Caption = Label1.Caption & mod & Label3.Caption & = & Val(Label1.Caption) Mod Val(Label3.Caption) End If ElseIf Label2.Caption = xy Then 计算xy Label3.Caption = Label1.Caption & & Label3.Caption & = & Val(Label1.Caption) Val(Label3.Caption) End If Else If Label2.Caption = - Then 如果输入数字前输入“-”则按负数处理 Label3.Caption = -Val(Label3.Caption) End If End If Label1.Caption = Label2.Caption = Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command19_Click() 输入符号+ If Label3.Caption Then Label1.Caption = Label3.Caption Label2.Caption = Command19.Caption Label3.Caption = Else c = MsgBox(请输入数据后输入符号!, 49, 注意!) End IfEnd SubPrivate Sub Command2_Click() Label3.Caption = 清空 Label2.Caption = Label1.Caption = End SubPrivate Sub Command20_Click() s = 1 求阶乘n! For i = 1 To Val(Label3.Caption) s = s * i Next Label3.Caption = Label3.Caption + ! = & s Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command21_Click() 取整运算fix Label3.Caption = Fix( & Label3.Caption & )= & Fix(Val(Label3.Caption) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command22_Click() 取倒数 If Val(Label3.Caption) 0 Then Label3.Caption = 1/ & Label3.Caption & = & 1 / Val(Label3.Caption) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1 Else c = MsgBox(除数不能为0! + Chr(13) + Chr(10) + 请重新输入!, 49, 注意!) End IfEnd SubPrivate Sub Command23_Click() 输入符号mod Label1.Caption = Label3.Caption Label2.Caption = Command23.Caption Label3.Caption = End SubPrivate Sub Command24_Click() 计算正切值tan Label3.Caption = tan( & Label3.Caption & )= & Tan(Val(Label3.Caption) / 57.2958) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command25_Click() If Val(Label3.Caption) 0 Then 计算对数ln Label3.Caption = ln( & Label3.Caption & )= & Log(Val(Label3.Caption) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1 Else c = MsgBox(对数值应大于0,! + Chr(13) + Chr(10) + 请重新输入!, 49, 注意!) End IfEnd SubPrivate Sub Command26_Click() 计算余弦值tan Label3.Caption = cos( & Label3.Caption & )= & Cos(Val(Label3.Caption) / 57.2958) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command27_Click() 计算e 的x 次方 Label3.Caption = Exp( & Label3.Caption & )= & 2.71818 Val(Label3.Caption) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command28_Click() 计算正弦值 Label3.Caption = sin( & Label3.Caption & )= & Sin(Val(Label3.Caption) / 57.2958) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command29_Click() 计算不大于X的最大整数 Label3.Caption = Int( & Label3.Caption & )= & Int(Val(Label3.Caption) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command3_Click() End OFF按钮End SubPrivate Sub Command30_Click() If Val(Label3.Caption) = 0 Then 开平方 Label3.Caption = sqr( & Label3.Caption & )= & Sqr(Val(Label3.Caption) Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1 Else c = MsgBox(被开方数不能为负数! + Chr(13) + Chr(10) + 请重新输入!, 49, 注意!) End IfEnd SubPrivate Sub Command31_Click() 输入XY Label1.Caption = Label3.Caption Label2.Caption = Command31.Caption Label3.Caption = End SubPrivate Sub Command32_Click() 求反正切值 Label3.Caption = tan-1( & Label3.Caption & )= & Atn(Val(Label3.Caption) * 57.2958 Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1End SubPrivate Sub Command33_Click() a = Val(Label3.Caption) 求反余弦值 If a -1 And a 1 Then For i = 0 To 360 Step 0.01 If Abs(Cos(i / 57) - a) = -1 And a = 1 Then For i = 0 To 360 Step 0.01 If Abs(Sin(i / 57) - a) = 0.001 Then d = i Label3.Caption = sin-1( & Label3.Caption & )= & d Exit For End If Next Open App.Path & 记录 For Append As #1 保存记录 Print #1, 科学型计算器 & ; Date & ; Time() Print #1, Label3.Caption Print #1, Close #1 Else c = MsgBox(正弦值范围为(-1,1), + Chr(13) + Chr(10) + 请重新输入!, 49, 注意!) End If End SubPrivate Sub Command35_Click() 说明 c = MsgBox(1.若需输入负号,如果是第一个数,请按“-”后按数字再按“=”,如果是第二个数,请按数字后按“-”。 + Chr(13) + Chr(10) + 2.若计算只需一个数据,则输入数据后,按下相应计算符号即可。 + Chr(13) + Chr(10) + 3.如需查询计算过的数据结果,请打开计算器目录下的“记录”文件。, 49, 说明)End SubPrivate Sub Command4_Click() 输入数字7 Label3.Caption = Label3.Caption + Command4.CaptionEnd SubPrivate Sub Command5_Click() 输入数字8 Label3.Caption = Label3.Caption + Command5.CaptionEnd SubPrivate Sub Command6_Click() 输入数字9 Label3.Caption = Label3.Caption + Command6.CaptionEnd SubPrivate Sub Command7_Click() If Label3.Caption Then 输入符号/ Label1.Caption = Label3.Caption Label2.Caption = Command7.Caption Label3.Caption = Else c = MsgBox(请输入数据后输入符号!, 49, 注意!) End IfEnd SubPrivate Sub Command8_Click() 输入数字4 Label3.Caption = Label3.Caption + Command8.CaptionEnd SubPrivate Sub Command9_Click() 输入数字5 Label3.Caption = Label3.Caption + Command9.CaptionEnd SubPrivate Sub Label3_Change() 未输入数字前除数字键其他均不可用If Label3.Caption = Then Command29.Enabled = False Command28.Enabled = False Command34.Enabled = False Command

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论