VB科学计算器的实现实验报告.doc
- 文档编号:232239
- 上传时间:2022-10-07
- 格式:DOC
- 页数:11
- 大小:119.50KB
VB科学计算器的实现实验报告.doc
《VB科学计算器的实现实验报告.doc》由会员分享,可在线阅读,更多相关《VB科学计算器的实现实验报告.doc(11页珍藏版)》请在冰豆网上搜索。
西安科技大学
可视化编程语言实验报告
题目:
复杂型科学计算器的设计与实现
班级:
通信工程0902班
学号:
0907020211
姓名:
李亚进
2010年11月
复杂型科学计算器的设计与实现
实验目的
1.通过本实验,进一步理解VisualBasic的编程方法。
2.提高运用VisualBasic编程的能力。
3.培养对所学知识的综合运用能力。
实验类型
综合型。
实验内容与步骤
一、分析问题,选择算法
科学计算器主要实现基本的加减乘除运算、正弦余弦、正切余切、正割余割、反正弦反余弦、双曲正弦、双曲余弦、对数和求绝对值等函数功能。
为实现上述功能,我的基本思路是在窗体上建立三个控件数组,第一个控件数组有十五个命令按钮,分别实现正弦余弦、正切余切、正割余割、反正弦反余弦、双曲正弦、双曲余弦、对数和求绝对值等函数功能;第二个控件数组作包括十二个命令按钮,用来进行计算器的数据输入;第三个控件数组为基本的运算符号,实现基本加减乘除和乘方运算。
退格、清除、等于、退出作为独立的命令按钮,另外设计一个功能切换按钮实现显示当前系统日期和时间。
二、建立用户界面
建立如下界面:
三、设置窗体和控件属性
对象名
属性
值
Command1(0)
Caption
“sin”
Index
0
Command1
(1)
Caption
“cos”
Index
0
Command1
(2)
Caption
“tg”
Index
2
Command1(3)
Caption
“sec”
Index
3
Command1(4)
Caption
“csc”
Index
4
Command1(5)
Caption
“ctg”
Index
5
Command1(6)
Caption
“arcsin”
Index
6
Command1(7)
Caption
“arcos”
Index
7
Command1(8)
Caption
“arctg”
Index
8
Command1(9)
Caption
“arcctg”
Index
9
Command1(10)
Caption
“log”
Index
10
Command1(11)
Caption
“ln”
Index
11
Command1(12)
Caption
“sh”
Index
12
Command1(13)
Caption
“ch”
Index
13
Command1(14)
Caption
“abs”
Index
14
Command2(0)
Caption
“0”
Index
0
Command2
(1)
Caption
“1”
Index
1
Command2
(2)
Caption
“2”
Index
2
Command2(3)
Caption
“3”
Index
3
Command2(4)
Caption
“4”
Index
4
Command2(5)
Caption
“5”
Index
5
Command2(6)
Caption
“6”
Index
6
Command2(7)
Caption
“7”
Index
7
Command2(8)
Caption
“8”
Index
8
Command2(9)
Caption
“9”
Index
9
Command2(10)
Caption
“.”
Index
10
Command2(11)
Caption
“-”
Index
11
Command3(0)
Caption
“+”
Index
0
Command3
(1)
Caption
“-”
Index
1
Command3
(2)
Caption
“*”
Index
2
Command3(3)
Caption
“/”
Index
3
Command3(4)
Caption
“(”
Index
4
Command3(5)
Caption
“)”
Index
5
Command3(6)
Caption
“^”
Index
6
Command4
Caption
“<--“
Command5
Caption
“CE”
Command6
Caption
“=”
Command7
Caption
“功能切换”
Command8
Caption
“退出”
Label1
Caption
清空
Text1
BackColor
&H00FFFFC0&
ForeColor
&H00FF0000&
MultiLine
true
Text
清空
Font
宋体常规三号
Enlabied
False
Form1
Caption
自制科学计算器
BackColor
&H00FFC0C0&
四、编写代码,进行调试
编写代码如下:
通用:
DimNum1,Num2AsSingle
DimnAsInteger'乘方变量
DimpiAsSingle
DimresultAsSingle
DimfuhaoAsInteger'判断是否有运算符号
DimsignAsInteger'储存运算符号
双击任意数组控件一按钮输入代码:
PrivateSubCommand1_Click(IndexAsInteger)
SelectCaseIndex
Case0To9
sign=10+Index
Case10
sign=20
fuhao=1'第一次输入的底数已放入Num1,标记已有符号,第二次输入时数据放入Num2
Case11To14
sign=10+Index
EndSelect
Text1.Text=""'清空文本框
EndSub
双击任意数组控件二按钮输入代码:
PrivateSubCommand2_Click(IndexAsInteger)'数字输入
SelectCaseIndex
Case0To9
Text1.Text=Text1.Text&Index
Case10
Text1.Text=Text1.Text&"."
Case11
Text1.Text="-"
EndSelect
Iffuhao=0Then'若无符号数据放入Num1,有符号数据放入Num2
Num1=Val(Text1.Text)
Else
Num2=Val(Text1.Text)
EndIf
EndSub
双击任意数组控件三按钮输入代码:
PrivateSubCommand3_Click(IndexAsInteger)'判断标记运算符号
SelectCaseIndex
Case0To6
sign=Index
EndSelect
Text1.Text=""
fuhao=1'标记已有运算符
EndSub
双击ß按钮输入代码:
PrivateSubCommand4_Click()'每次从右边删除一个数字
IfVal(Text1.Text)=0Then
Text1.Text=""
fuhao=0
Else
Text1.Text=Left$(Text1.Text,Len(Text1.Text)-1)
EndIf
EndSub双击CE按钮输入代码:
PrivateSubCommand5_Click()'清空文本框
Text1.Text=""
fuhao=0
EndSub
双击等号按钮输入代码:
PrivateSubCommand6_Click()
DimNumAsSingle'角度中间转换变量
pi=3.141592654
e=2.718282
SelectCasesign
Case0
Text1.Text=Num1&"+"&Num2&"="&Chr(13)&Chr(10)&Num1+Num2
Case1
Text1.Text=Num1&"-"&Num2&"="&Chr(13)&Chr(10)&Num1-Num2
Case2
Text1.Text=Num1&"*"&Num2&"="&Chr(13)&Chr(10)&Num1*Num2
Case3
Text1.Text=Num1&"/"&Num2&"="&Chr(13)&Chr(10)&Num1/Num2
Case4
Text1.Text="输入错误!
请重新输入:
"
Case5
Text1.Text="输入错误!
请重新输入:
"
Case6
result=Num1
Forn=1ToNum2-1
result=result*Num1
Nextn
Text1.Text=Num1&"^"&Num2&"="&Chr(13)&Chr(10)&result
Case10
Num=Num1/180*pi
Text1.Text="sin"&"("&Num1&")"&"="&Chr(13)&Chr(10)&Sin(Num)
Case11
Num=Num1/180*pi
Text1.Text="cos"&"("&Num1&"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 科学 计算器 实现 实验 报告