




免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验6 编写计算器程序实验目的:1、 掌握控件数组的创建方法;2、 理解控件数组中控件名称组成特点;3、 掌握运用控件数组编程的方法。实验内容:1、 实验要求使用控件数组设计一个简易计算器,能实现算术运算和简单函数运算,并具有清除结果和退格键的功能。2、 分析设计用一文本框显示计算过程及结果,使用以命令按钮控件为元素的控件数组,并编写控件数组的Click事件。3、 窗体属性对象名属性名设置值Form1caption计算器Text1text-Command1(0-9)caption0-9Command1(10-13)caption+、-、*、Command1(14)caption.Command1(15)caption=Command1(16)caption退格Command1(17)captionCCommand1(18-24)caption平方、Sqrt、Sin、Cos、Tan、Atn、log4、 窗体设计5、 源代码Dim x As Single, y As SingleDim op As StringPrivate Sub Command1_Click(Index As Integer)Select Case Index Case 0 To 9 Text1.Text = Text1 & Command1(Index).Caption Case 14 If InStr(Text1, .) = 0 Then Text1.Text = Text1 & Command1(Index).Caption ElseIf Right(Text1, 1) = . Then Text1.Text = Text1 & End If Case 10 To 13 x = Val(Text1) If Index = 10 Then op = + If Index = 11 Then op = - If Index = 12 Then op = * If Index = 13 Then op = / Text1 = Case 15 y = Val(Text1) Text1 = If op = + Then Text1 = x + y If op = - Then Text1 = x - y If op = * Then Text1 = x * y If op = / Then If y 0 Then Text1 = x / y Else Text1 = 除数不能为零 End If End If Case 16 If Len(Text1) 0 Then Text1 = Left(Text1, Len(Text1) - 1) End If Case 17 Text1 = x = 0: y = 0 Case 18 x = Val(Text1) If x 0 Then Text1 = 负数的平方根无意义 Else Text1 = Sqr(x) End If Case 19 x = Val(Text1): Text1 = x * x Case 20 x = Val(Text1): Text1 = Sin(x * 3.1415926 / 180) Case 21 x = Val(Text1): Text1 = Cos(x * 3.1415926 / 180) Case 22 x = Val(Text1): Text1 = Tan(x * 3.1415926 / 180) Case 23 x = Val(Text1): Text1 = Atn(x) * 180 / 3.1415926 Case 24 x = Val(Text1) If x = 0 Then Text1 = 负数或零的对数无意义 Else Text1 = Log(x) End If End SelectEnd SubPrivate Sub Form_Load()Text1 = For i = 0 To 24 Command1(i).BackColor = &HC0FFFFNext iEnd Sub实验思考:本次实验只实现了计算器的部分功能,请试着完善计算器的其它功能。实验目的:4、 掌握控件数组的创建方法;5、 理解控件数组中控件名称组成特点;6、 掌握运用控件数组编程的方法。实验内容:6、 实验要求使用控件数组设计一个简易计算器,能实现算术运算和简单函数运算,并具有清除结果和退格键的功能。7、 分析设计用一文本框显示计算过程及结果,使用以命令按钮控件为元素的控件数组,并编写控件数组的Click事件。8、 窗体属性对象名属性名设置值Form1caption计算器Text1text-Command1(0-9)caption0-9Command1(10-13)caption+、-、*、Command1(14)caption.Command1(15)caption=Command1(16)caption退格Command1(17)captionCCommand1(18-24)caption平方、Sqrt、Sin、Cos、Tan、Atn、log9、 窗体设计10、 源代码Dim x As Single, y As SingleDim op As StringPrivate Sub Command1_Click(Index As Integer)Select Case Index Case 0 To 9 Text1.Text = Text1 & Command1(Index).Caption Case 14 If InStr(Text1, .) = 0 Then Text1.Text = Text1 & Command1(Index).Caption ElseIf Right(Text1, 1) = . Then Text1.Text = Text1 & End If Case 10 To 13 x = Val(Text1) If Index = 10 Then op = + If Index = 11 Then op = - If Index = 12 Then op = * If Index = 13 Then op = / Text1 = Case 15 y = Val(Text1) Text1 = If op = + Then Text1 = x + y If op = - Then Text1 = x - y If op = * Then Text1 = x * y If op = / Then If y 0 Then Text1 = x / y Else Text1 = 除数不能为零 End If End If Case 16 If Len(Text1) 0 Then Text1 = Left(Text1, Len(Text1) - 1) End If Case 17 Text1 = x = 0: y = 0 Case 18 x = Val(Text1) If x 0 Then Text1 = 负数的平方根无意义 Else Text1 = Sqr(x) End If Case 19 x = Val(Text1): Text1 = x * x Case 20 x = Val(Text1): Text1 = Sin(x * 3.1415926 / 180) Case 21 x = Val(Text1): Text1 = Cos(x * 3.1415926 / 180) Case 22 x = Val(Text1): Text1 = Tan(x * 3.1415926 / 180) Case 23 x = Val(Text1): Text1 = Atn(x) * 180 / 3.1415926 Case 24 x = Val(Text1) If x = 0 Then Text1 = 负数或零的对数无意义
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年事业单位教师招聘考试教育心理学真题模拟精练
- 2025年黑龙江省事业单位招聘考试教师招聘生物学科专业知识试卷真题模拟
- 武汉事业单位招聘考试综合类职业能力倾向测验真题模拟试卷
- 衡阳生地会考试卷及答案2024
- 新解读《GB-T 39315.3-2020军民通 用资源 数据模型 第3部分:器材类 航材》
- 网红影响者品牌塑造-洞察与解读
- 水泥基材料改性研究-洞察与解读
- 2025国考山西统计局申论易错点
- 2025国考保定市行政管理岗位行测高频考点及答案
- 2025国考福建税务局行测易错点
- 调试、试运行与移交管理方案
- GB/T 26655-2011蠕墨铸铁件
- 热镀锌钢管技术标准
- 周三多管理学第03章管理的基本原理
- 基础生态学第4章种群及其基本特征课件
- 虚拟现实与增强现实头戴显示关键技术及应用项目
- (完整)公共卫生基本知识考试题题库及答案
- 《电力工业企业档案分类规则0大类》(1992年修订版)
- GB∕T 26520-2021 工业氯化钙-行业标准
- 温州医科大学《儿科学》支气管肺炎
- 常见传染病预防知识ppt-共47页课件
评论
0/150
提交评论