已阅读5页,还剩42页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2011年小学期计算机实习报告姓名:肖霄 班级:2009211207 学号:09211047 班内序号:25一、实习目的通过完成任务,学习并熟悉相关软件。了解并熟悉设计过程,从初步设计到实现到不断完善,掌握设计流程。 二 、实习任务1、计算器程序制作一个计算器程序:支持2进制、10进制、16进制数的加减乘除运算支持2进制、10进制、16进制数的相互转化2、自制小闹钟制作一个小闹钟:可多次定时进行提示和多次事件提醒(声音提示并弹出对话框进行事件提醒)3、模拟信号发生器 制作一个模拟信号发生器:模拟信号和载波信号的频率、幅值可变 载波信号可以是正弦、方波、三角波,并且可加直流偏置调制信号频率、幅值可变 画出信号波形 对该信号采样,并作文件存入磁盘中 可以适用幅度、频率两种调制方式 三、设计流程及源代码 (一)计算器 1)功能实现:用软件vb6.0来编写程序,生成exe程序打开exe程序后,显示计算器界面,程序有以下功能: 点击“科学计算”,选择要计算的进制 点击“进制转换”,选择原始进制和目标进制进行换算 点击菜单栏中的“帮助”,弹出使用说明对话框 点击菜单栏中的“退出”,弹出对话框询问是否退出程序 2)设计流程 确定使用VB语言 明确实现功能:支持2进制、10进制、16进制数的加减乘除运算支持2进制、10进制、16进制数的相互转化帮助选项显示程序使用说明退出系统如若否则返回计算器界面,若确定结束程序。 安置控件:选择命令控件分别作为“科学计算”,“进制转换”命令;用命令控件做数值以及符号输入按钮;用文本框显示输入的数值; 设计程序:对各控件分别进行相应的命令的程序设计3)源程序部分关键代码:定义变量Dim Counter As Double Dim Reg As DoubleDim pi As DoubleDim CalcNumber As LongDim DisplayFromNew As BooleanDim AlreadyDecimalThere As BooleanDim LastClick As String科学计算界面显示情况Private Sub Command1_Click()47 Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True txtDisplay.Text = Frame3.Enabled = False Frame1.Enabled = False Frame2.Enabled = False Text1.Visible = False Text2.Visible = False Combo1.Enabled = False Combo2.Enabled = False Label1.Enabled = False txtDisplay.Visible = True txtDisplay.Enabled = TrueEnd Sub进制转换界面显示情况Private Sub Command2_Click() Command3.Enabled = False Command4.Enabled = False Command5.Enabled = False Command6.Enabled = False txtDisplay.Visible = False Frame3.Enabled = True Frame1.Enabled = True Frame2.Enabled = True Text1.Visible = True Text2.Visible = True Text1.Enabled = True Text2.Enabled = True Combo1.Enabled = True Combo2.Enabled = True Label1.Enabled = True Text1.Text = End Sub二进制选项界面现实情况Private Sub Binary_Click() Number(2).Enabled = False Number(3).Enabled = False Number(4).Enabled = False Number(5).Enabled = False Number(6).Enabled = False Number(7).Enabled = False Number(8).Enabled = False Number(9).Enabled = False Number1.Enabled = False Number2.Enabled = False Number3.Enabled = False Number4.Enabled = False Number5.Enabled = False Number6.Enabled = False Command3.Enabled = False Command4.Enabled = False Command5.Enabled = False Command6.Enabled = FalseEnd Sub清除最后一次数值命令Private Sub ClearEntry_Click() DisplayFromNew = True txtDisplay.Text = 0End Sub选择原始进制后界面显示情况Private Sub Combo1_Click()If Combo1.Text = 2进制 Then Number(2).Enabled = False Number(3).Enabled = False Number(4).Enabled = False Number(5).Enabled = False Number(6).Enabled = False Number(7).Enabled = False Number(8).Enabled = False Number(9).Enabled = False Number1.Enabled = False Number2.Enabled = False Number3.Enabled = False Number4.Enabled = False Number5.Enabled = False Number6.Enabled = False Text1.Text = Text2.Text = End IfIf Combo1.Text = 10进制 ThenNumber(2).Enabled = True Number(3).Enabled = True Number(4).Enabled = True Number(5).Enabled = True Number(6).Enabled = True Number(7).Enabled = True Number(8).Enabled = True Number(9).Enabled = True Number1.Enabled = False Number2.Enabled = False Number3.Enabled = False Number4.Enabled = False Number5.Enabled = False Number6.Enabled = False Text1.Text = Text2.Text = End IfIf Combo1.Text = 16进制 Then Number(2).Enabled = True Number(3).Enabled = True Number(4).Enabled = True Number(5).Enabled = True Number(6).Enabled = True Number(7).Enabled = True Number(8).Enabled = True Number(9).Enabled = True Number1.Enabled = True Number2.Enabled = True Number3.Enabled = True Number4.Enabled = True Number5.Enabled = True Number6.Enabled = True Text1.Text = Text2.Text = End IfIf Judge = 1 Then CalculateEnd IfEnd Sub选择目标进制后界面显示情况Private Sub Combo2_Click()If Judge = 1 Then CalculateEnd IfEnd Sub正负数命令Private Sub Command29_Click()Dim x$, y$x = txtDisplay.Textx = (-1) * xtxtDisplay.Text = xy = Text1.Texty = (-1) * yText1.Text = yEnd Subsin函数的计算Private Sub Command3_Click()If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Sin(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If DisplayFromNew = TrueIf CalcNumber 0 Then Counter = Sin(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter)End If AlreadyDecimalThere = False DisplayFromNew = True CalcNumber = 0End Subcos函数的计算Private Sub Command4_Click()If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Cos(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If DisplayFromNew = TrueIf CalcNumber 0 Then Counter = Cos(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter)End If AlreadyDecimalThere = False DisplayFromNew = True CalcNumber = 0End Subtan函数的计算Private Sub Command5_Click()If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Tan(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If DisplayFromNew = TrueIf CalcNumber 0 Then Counter = Tan(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter)End If AlreadyDecimalThere = False DisplayFromNew = True CalcNumber = 0End Subcot函数的计算Private Sub Command6_Click()If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Cos(CDbl(txtDisplay / 180 * pi) / Sin(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If DisplayFromNew = TrueIf CalcNumber 0 Then Counter = Cos(CDbl(txtDisplay / 180 * pi) / Sin(CDbl(txtDisplay / 180 * pi) txtDisplay.Text = CStr(Counter)End If AlreadyDecimalThere = False DisplayFromNew = True CalcNumber = 0End Sub十进制计算界面显示情况Private Sub DecimalSystem_Click() Number(2).Enabled = True Number(3).Enabled = True Number(4).Enabled = True Number(5).Enabled = True Number(6).Enabled = True Number(7).Enabled = True Number(8).Enabled = True Number(9).Enabled = True Number1.Enabled = False Number2.Enabled = False Number3.Enabled = False Number4.Enabled = False Number5.Enabled = False Number6.Enabled = False Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = TrueEnd Sub退出选项Private Sub Esc_Click()k = MsgBox(真的要退出计算器吗?, 4 + 32 + 0, 退出)If k = 6 Then 点击是,退出 End End IfEnd SubSub Form_Load()居中显示Top = Screen.Height / 2 - Height / 2Left = Screen.Width / 2 - Width / 2 pi = 3.1415926默认现实情况 txtDisplay.Enabled = False Frame3.Enabled = False Frame1.Enabled = False Frame2.Enabled = False Text1.Enabled = False Text2.Enabled = False Combo1.Enabled = False Combo2.Enabled = False Label1.Enabled = False AllClear_Click Text1.Text = Text2.Text = Combo1.AddItem 2进制 设置下拉选项内容 Combo1.AddItem 10进制 Combo1.AddItem 16进制 Combo2.AddItem 2进制 Combo2.AddItem 10进制 Combo2.AddItem 16进制 Combo1.Text = 10进制: Combo2.Text = 10进制End Sub进制转换的judge命令模块Private Function Judge() As Integern = Len(Text1.Text)Form1.Print nForm1.Print mj = 10 (n - m)Sum = 0If Combo1.Text = 2进制 Then For i = 1 To n Select Case Mid(Text1.Text, i, 1) Case 0, 1, . Case Else MsgBox 数据错误, vbCritical, 错误提示 Text1.SelStart = i: Text1.SetFocus: Judge = 0: Exit For: End Select Next iElseIf Combo1.Text = 10进制 Then For i = 1 To n Select Case Mid(Text1.Text, i, 1) Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, . Case Else MsgBox 数据错误, vbCritical, 错误提示 Text1.SelStart = i: Text1.SetFocus: Judge = 0: Exit For End Select Next iElseIf Combo1.Text = 16进制 Then For i = 1 To n Select Case Mid(Text1.Text, i, 1) Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, . Case Else MsgBox 数据错误, vbCritical, 错误提示 Text1.SelStart = i: Text1.SetFocus: Judge = 0: Exit For End Select Next iEnd IfJudge = 1End Function进制转换calculate模块Private Function Calculate() As DoubleDim n#, m#, S$, i!, n1!, m1!, x!, sum#Text2.Text = n1 = Len(Text1.Text) 输入数据的长度m1 = InStr(Text1.Text, .) 寻找小数点x = Val(Combo1.Text) 字符串转为数值sum = 0If m1 0 Then For i = 1 To m1 - 1 If Mid(Text1.Text, i, 1) = A Then k = Asc(Mid(Text1.Text, i, 1) - 65 + 10 Else k = Val(Mid(Text1.Text, i, 1) End If sum = sum + k * x (m1 - 1 - i) Next i S = Str(sum) sum值转为字符串 S = LTrim(S) 去掉S左边的空格 sum = 0 For i = m1 + 1 To n1 If Mid(Text1.Text, i, 1) = A Then k = Asc(Mid(Text1.Text, i, 1) - 65 + 10 Else k = Val(Mid(Text1.Text, i, 1) End If sum = sum + k / x (i - m1) Next i S = S & LTrim(Str(sum)Else For i = 1 To n1 If Mid(Text1.Text, i, 1) = A Then k = Asc(Mid(Text1.Text, i, 1) - 65 + 10 Else k = Val(Mid(Text1.Text, i, 1) End If sum = sum + k * x (n1 - i) Next i S = LTrim(Str(sum)End Ifn = Int(Val(S) 不大于Val(S)的最大整数m = Val(S) - n 余下的小数部分i = InStr(S, .) 查找S中的小数点位置x = Val(Combo2.Text)Do While (n 0) t = n Mod x If t = 10 Then Text2.Text = Chr(65 + t - 10) & Text2.Text Else: Text2.Text = t & Text2.Text End If n = n xLoopIf i 0 Then Text2.Text = Text2.Text & . Do While (m 0.000001) t = Fix(m * x) 截尾取整 If t = 10 Then Text2.Text = Text2.Text & Chr(65 + t - 10) Else: Text2.Text = Text2.Text & t End If m = m * x - t LoopEnd IfEnd Function全部清除命令Sub AllClear_Click() DisplayFromNew = True Counter = 0 txtDisplay.Text = 0 CalcNumber = 0 Reg = 0 AlreadyDecimalThere = FalseEnd Sub退位命令Sub Backspace_Click() txtDisplay.Text = Left(txtDisplay.Text, Len(txtDisplay.Text) - 1) If Text1.Text Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) End IfEnd Sub小数点的输入Private Sub Decimal_Click() If AlreadyDecimalThere = False Then AddDisplayDigit . AlreadyDecimalThere = True End If If InStr(Text1.Text, .) 0 Then Exit Sub Else Text1.Text = Text1.Text & . End IfEnd Sub除法运算模块Private Sub Divide_Click()If DecimalSystem.Value = True Then 10进制除法 If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Reg / CDbl(txtDisplay.Text) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If Reg = CDbl(txtDisplay.Text) DisplayFromNew = True LastClick = DivideElseIf Binary.Value = True Then 2进制除法 For i = 1 To Len(txtDisplay.Text) Dim DecimalNumber1 As Long DecimalNumber1 = DecimalNumber1 * 2 + Val(Mid(txtDisplay.Text, i, 1) Next i If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Reg / CDbl(DecimalNumber1) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If Reg = CDbl(DecimalNumber1) DisplayFromNew = True LastClick = DivideElseIf HexSystem.Value = True Then 十六进制除法 Dim k1 As Long Dim B1 As Long txtDisplay.Text = UCase(txtDisplay.Text) For k1 = 1 To Len(txtDisplay.Text) Select Case Mid(txtDisplay.Text, Len(txtDisplay.Text) - k1 + 1, 1) Case 0: B1 = B1 + 16 (k1 - 1) * 0 Case 1: B1 = B1 + 16 (k1 - 1) * 1 Case 2: B1 = B1 + 16 (k1 - 1) * 2 Case 3: B1 = B1 + 16 (k1 - 1) * 3 Case 4: B1 = B1 + 16 (k1 - 1) * 4 Case 5: B1 = B1 + 16 (k1 - 1) * 5 Case 6: B1 = B1 + 16 (k1 - 1) * 6 Case 7: B1 = B1 + 16 (k1 - 1) * 7 Case 8: B1 = B1 + 16 (k1 - 1) * 8 Case 9: B1 = B1 + 16 (k1 - 1) * 9 Case A: B1 = B1 + 16 (k1 - 1) * 10 Case B: B1 = B1 + 16 (k1 - 1) * 11 Case C: B1 = B1 + 16 (k1 - 1) * 12 Case D: B1 = B1 + 16 (k1 - 1) * 13 Case E: B1 = B1 + 16 (k1 - 1) * 14 Case F: B1 = B1 + 16 (k1 - 1) * 15 End Select Next k1 If CalcNumber = 0 Then CalcNumber = 1 Else Counter = Reg / CDbl(B1) txtDisplay.Text = CStr(Counter) AlreadyDecimalThere = False End If Reg = CDbl(B1) DisplayFromNew = True LastClick = DivideEnd IfEnd Sub等号命令Private Sub Equals_Click()If LastClick = Minus Then 减法 If Binary.Value = True Then 二进制 If CalcNumber 0 Then For i = 1 To Len(txtDisplay.Text) Dim DecimalNumber1 As Long DecimalNumber1 = DecimalNumber1 * 2 + Val(Mid(txtDisplay.Text, i, 1) Next i Counter = Reg - CDbl(DecimalNumber1) BinaryNumber = Do While Counter 0 BinaryNumber = Counter Mod 2 & BinaryNumber Counter = Counter 2 Loop DisplayFromNew = True txtDisplay.Text = CStr(BinaryNumber) End If ElseIf DecimalSystem.Value = True Then 十进制 If CalcNumber 0 Then Counter = Reg - CDbl(txtDisplay.Text) txtDisplay.Text = CStr(Counter) End If AlreadyDecimalThere = False DisplayFromNew = True CalcNumber = 0 ElseIf HexSystem.Value = True Then 十六进制 If CalcNumber 0 Then Dim k1 As Long Dim B1 As Long txtDisplay.Text = UCase(txtDisplay.Text) For k1 = 1 To Len(txtDisplay.Text) Select Case Mid(txtDisplay.Text, Len(txtDisplay.Text) - k1 + 1, 1) Case 0: B1 = B1 + 16 (k1 - 1) * 0 Case 1: B1 = B1 + 16 (k1 - 1) * 1 Case 2: B1 = B1 + 16 (k1 - 1) * 2 Case 3: B1 = B1 + 16 (k1 - 1) * 3 Case 4: B1 = B1 + 16 (k1 - 1) * 4 Case 5: B1 = B1 + 16 (k1 - 1) * 5 Case 6: B1 = B1 + 16 (k1 - 1) * 6 Case 7: B1 = B1 + 16 (k1 - 1) * 7 Case 8: B1 = B1 + 16 (k1 - 1) * 8 Case 9: B1 = B1 + 16 (k1 - 1) * 9 Case A: B1 = B1 + 16 (k1 - 1) * 10 Case B: B1 = B1 + 16 (k1 - 1) * 11 Case C: B1 = B1 + 16 (k1 - 1) * 12 Case D: B1 = B1 + 16 (k1 - 1) * 13 Case E: B1 = B1 + 16 (k1 - 1) * 14 Case F: B1 = B1 + 16 (k1 - 1) * 15 End Select Next k1 Counter = Reg - CDbl(B1) Dim a1 As String HexNumber = Do While Counter 0 a1 = CStr(Counter Mod 16) Select Case a1 Case 10: a1 = A Case 11: a1 = B Case 12: a1 = C Case 13: a1 = D Case 14: a1 = E Case 15: a1 = F End Select HexNumber = a1 & HexNumber Counter = Counter 16 Loop DisplayFromNew = True txtDisplay.Text = CStr(HexNumber) End If End If ElseIf LastClick = Addition Then 加法 If Binary.Value = True Then 二进制 If CalcNumber 0 Then For i = 1 To Len(txtDisplay.Text) Dim DecimalNumber As Long DecimalNumber = DecimalNumber * 2 + Val(Mid(txtDisplay.Text, i, 1) Next i Counter = Reg + CDbl(DecimalNumber) BinaryNumber = Do While Counter 0 BinaryNumber = Counter Mod 2 & BinaryNumber Counter = Counter 2 Loop DisplayFromNew = True txtDisplay.Text = CStr(BinaryNumber) End If ElseIf DecimalSystem.Value = True Then 十进制 If CalcNumber 0 Then Counter = Reg + CDbl(txtDisplay.Text) txtDisplay.Text = CStr(Counter) End If AlreadyDecimalThere = False DisplayFromNew = True CalcNumber = 0 ElseIf HexSystem.Value = True Then 十六进制 If CalcNumber 0 Then Dim k As Lon
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 城市绿化景观改造合同模板
- 影视制作定向合作协议
- 农业项目草场租赁合同
- 仓储物流中心建设模板
- 生态扶贫与保护政策与措施
- 商业综合体建造师聘用合同模板
- 燃气管道改造施工协议
- 质量保证协议书烟草分销商
- 大型码头码头地面压路机施工合同
- 糕点面包厂管理
- 苏州市2023-2024学年高一上学期期中考试化学试题 试卷及答案
- 新编2020实验室CNAS认可质量手册和程序文件全套转版
- 百货零售领域:翠微股份企业组织架构及部门职责
- 《过新年》教学设计
- 中学生心理辅导案例分析4篇
- 高中语文学科核心素养和语文教学课件
- 油气田腐蚀结垢与防垢技术课件
- 永遇乐元宵(落日熔金)课件
- 道路工程施工便道施工方案全
- 创新创业基础(理工科版)创新小白实操2.0学习通超星课后章节答案期末考试题库2023年
- 内部审计工作手册
评论
0/150
提交评论