【VB开源代码栏目提醒】:以下是网学会员为您推荐的VB开源代码-vb程序设计教程_第三版课后答案(全)_罗朝盛 - 大学课件,希望本篇文章对您学习有所帮助。
程序
设计教程_第三版课后答案
vb 程序设计教程 第三版课后答案 第 1 章 习题参考答案 一、思考题 略 二、选择题 1. C 2. B 第 2 章 习题参考答案 一、判断题 题号 1 2 3 4 5 6 7 8 9 10 11 答案 × × √ √ × √ × √ √ √ √ 二、填空题1. 窗体 font2. 不能在
代码中设置3. selstart4. Locked5. TabIndex 、 06. vbModal 或 17. Activate 、 Deactivate8. PictureBox 和 Frame- 三、选择题 题号 1 2 3 4 5 6 7 8 9 10 答案 D C D A D B B B A B 第 3 章 习题参考答案 一、思考题 1、double 2、 xyCabc, 15eyd, Is, END X8P 3、变量有 1 4 6 8, 常量有 2字符串型 3逻辑型 5字符串型 7字符串型 9日期型 10实型 4、 a c b e d f 5、 1 26 2 3.75 3 3 6、写出下列 Visual Basic 表达式的值: 1 False 2 True 3 True 4 False 5 True 6 True 7 False 8 False 7、将下列命题用 Visual Basic 布尔表达式表示: 1 zgtx and zgty 2 absaltabsb2 or a gt b2 3 p mod q0 4 xlt-5 or xgt-2 and xlt2 or xgt5 5 xltz and ygtz or xgtz and yltz 6 altb and a mod 20 8、写出下列函数的值: 1 -4 2 换行符 3 –3 4 -1 5 hello 6 ello 7 16 8 “-459.65” 9 5 二、填空题 1. 整型 、 长整型 、 双精度型 、 双精度型 2. X mod 1010X10 3. sin1/43.14sqrx2expy/absx-y 4. ab/cd-sqr1-a2 5. x mod 50 or x mod 90 6. False 7. -3 、 2 、 -2 、 2 8. CDEF 9. xgt0 and ygt0 or xlt0 and ylt0 或 xygt0 10. sgt”A” and slt”Z” or sgt”a” and slt”z” 三、选择题 题号 1 2 3 4 5 答案 C B B B D 四、编程题1、Private Sub Form_Click Dim x Ten hundred x ValText1.Text Ten x 10 Mod 10 hundred x 100 Print quot百位数是: quot amp hundred Print quot十位数是: quot amp TenEnd Sub2Private Sub Form_Click Dim char As String 1 Form1.CurrentX Rnd Form1.ScaleWidth Form1.CurrentY Rnd Form1.ScaleHeight char ChrIntRnd 16 65 Print charEnd Sub 第4章 习题参考答案一、判断题 题号 1 2 3 4 5 6 7 8 答案 × × × √ √ √ √ ×二、选择题 题号 1 2 3 4 5 答案 A D B B B三、程序阅读 写出下列各段程序执行后的输出结果。
1.78 5786 357864 13578642 2. w4、w13、w135、w31 3.此题有点错误,修改如下: 是将语句“If k lt AscquotAquot Then k k 26”改为: If k lt AscquotAquot Or k gt AscquotZquot And k lt Ascquotaquot Then k k 26 改后的答案: xyza12 uvwamp 4.A BBB CCCCC DDDDDDD EEEEEEEEE 5.此题的“IF KeyAsci13 Then”改为“IF KeyAscii13 Then” 答案是:129四、程序填空题1. 1 Sing-1 2 For i2 to 19 3 Sing-Sing2. 1 Lenoldsen 2 Midoldsen i1 3 Ucasechar 4 char3. 1 Lenstr1 2 Length-1 3 Midstr1i2 4 Sum04. 1 TrimStri 2 TrimStrii 3 Rightx2Lenx1x15.1 last_one last_two2 last_two this_one3 i i14 i-1五、编程题1. Private Sub Form_Click Dim R1 As Double R2 As Double R1,R2 表示两电阻值 Dim Rp As Double Rs As Double R1 ValInputBoxquot输入电阻 R1?quot R2 ValInputBoxquot输入电阻 R2?quot Rp R1 R2 / R1 R2 Rs R1 R2 Rp FixRp 1000 0.5 / 1000 保留小数点后 3 位 Rs FixRs 1000 0.5 / 1000 保留小数点后 3 位 MsgBox quot并联电阻是:quot amp Rp amp vbCrLf amp quot串联电阻是:quot amp Rs End Sub2. Private Sub Form_Click Dim N As Long N ValInputBoxquot请输入年份quot quot提示框quot If N Mod 400 0 Or N Mod 4 0 And N Mod 100 ltgt 0 Then 判断条件 Print N amp quot年是闰年quot Else Print N amp quot年不是闰年quot End If End Sub3. Private Sub Form_Click Dim a b c s x a ValInputBoxquotEnter Aquot b ValInputBoxquotEnter Bquot c ValInputBoxquotEnter Cquot If a b gt c And b c gt a And a c gt b Then 如果能构成三角形 x a b c / 2 s Sqrx x - a x - b x - c Print quotSquot s Else Print quot数据有错不能构成三角形quot End If End Sub4.此题不适合使用 Select 语句 Private Sub Command1_Click Dim x As Double fx As Double x ValInputBoxquot输入 xquot If x lt 0 And x ltgt -3 Then fx x x x - 6 ElseIf x gt 0 And x lt 10 And x ltgt 2 And x ltgt 3 Then fx x x - 5 x 6 Else fx x x - x - 1 End If Print quotx quot x quot fquot amp x amp quotquot fx End Sub5. Dim i As Integer Dim s As Long t As Long t1 For i 1 To 10 tti sst Next i Print quot Squot amp s6. Dim i s n t f i1 项数 s0 累加和 n1 阶乘 t1 通项 f1 系数 Do While t gt 0.000001 ssft ii1 nni t1/n f -f 表示符号 Loop Print quotSquot s7. 方法一 Private Sub Form_Click Dim i As Integer Dim Hundred As Integer Ten As Integer One As Integer 定义百位,十位,个位数 For i 100 To 999 Hundred i 100 求百位数 Ten i 10 - Hundred 10 求十位数 One i Mod 10 求个位数 If i Hundred 3 Ten 3 One 3 Then 判断是否为素数 Print i amp quot是水仙花数quot End If Next i End Sub 方法二 Private Sub Form_Click Dim i As Integer Dim Hundred As Integer Ten As Integer One As Integer 定义百位,十位,个位数 For Hundred 1 To 9 百位数 For Ten 0 To 9 十位数 For One 0 To 9 i Hundred 100 Ten 10 One If i Hundred 3 Ten 3 One 3 Then 判断是否为素数 Print i amp quot是水仙花数quot End If Next One Next Ten Next Hundred End Sub8. Dim a As Double x0 As Double x1 As Double a ValInputBox“输入 a” x0 a 初值 x1 2 / 3 x0 a / 3 x0 x0 第一次迭代后的值 Do While Absx1 - x0 gt 0.000001 控制精度 x0 x1 迭代 x1 2 / 3 x0 a / 3 x0 x0 Loop Print “立方根: ” x1 第 5 章 习题参考答案 一、判断题 题号 1 2 3 4 5 6 答案 √ √ × × √ √ 二、选择题 题号 1 2 3 答案 D A C 三、
程序填空 1. Preserve an1 ai1ai ai1m n1 或 Ubounda 2. Print K-1 t ak j: ak j aj k: aj k t 3. Rnd100 P10 P J P 0 四、编写程序1.Private Sub Command1_ClickDim A As Integer N As IntegerDim i As Integer M As Integer t As Integer k As Integer N ValInputBoxquot请输入数组的大小 Nquot M ValInputBoxquot请输入移位次数 Mquot 输入循环次数的大小 If N lt 0 Then Exit Sub ReDim AN - 1 Print quot原始数组值quot For i 0 To N - 1 给数组赋值 Ai IntRnd 100 Print Ai Next i Print移位 For i 1 To M 循环体完成右移一位,循环完成右移 j位 t AN - 1 For k N - 1 To 1 Step -1 循环右移 Ak Ak - 1 Next k A0 t Next i打印右移后的数组值 Print quot循环右移quot amp M amp quot位后的数组值quot For i 0 To N - 1 Print Ai Next i PrintEnd Sub2.Const NM 100Private Sub Command1_ClickDim a1 To NM As Single b1 To NM As Integer max As IntegerDim i As Integer j As Integer k As Integer t As Integer For i 1 To NM 输入 100 个数值 ai ValInputBoxquot请输入 aquot amp i amp quot 的值quot If Intai ai Then 判断是否为整数 kk1 整数个数加 1 bk ai 将这个整数存放到数组 B End If Next i 选择排择 For i 1 To k - 1 max i For j i 1 To k If bmax lt bj Then max j Next j If max ltgt i Then t bmax: bmax bi: bi t End If Next i 打印输出 For i 1 To k Print bi If i Mod 5 0 Then Print Next iEnd Sub3.Private Sub Command1_Click Dim a As Integer Dim n i j n ValInputBoxquot输入一个整数 nquot ReDim an Form1.Cls Randomize Print quot产生的 30 个随机整数:quot For i 1 To n ai IntRnd 21 - 10 Print ai If i Mod 10 0 Then Print Next i Print 删除数组的相同数据 j2 Do While j lt n For i 1 To j - 1 查找相同的元素 If aj ai Then Exit For Next i If i lt j Then 如果第 i 个数与前面的数据相同删除第 i 个元素 For i j To n - 1 ai ai 1 Next i nn-1 ReDim Preserve an Else jj1 End If Loop Print quot删除后的数据:quot For i 1 To n Print ai If i Mod 10 0 Then Print Next iEnd Sub4.Private Sub Command1_ClickDim a1 To 50 As Integer i j t p n x n0 已经产生的元素个数 Randomize Do While n lt 50 x IntRnd 90 10 产生10100之间的随机整数 For i 1 To n If x ai Then Exit For Next i If i gt n Then n n 1 an x End If Loop For i 1 To 49 使用选择法排序 p i For j i 1 To 50 If ap gt aj Then p j Next j t ap: ap ai: ai t Next i For i 1 To 50 打印输出 Print ai If i Mod 10 0 Then Print Next iEnd Sub第6章 习题参考答案 一、判断题 题号 1 2 3 4 5 6 答案 √ √ × √ √ × 二、选择题 题号 1 2 3 4 5 答案 D C A D B 三、程序填空题1.(1) nsptrue 2 m mod i0 3 p1 and p2 4 p1nspi2.(1) numberi7 2 int n int m 3 numbernumber10m 四、程序阅读1. a9 b42.1 36 25 16 9 4 1 2 1 4 9 9 4 13. 64. 1 4 6 五、编写程序1.Public Function factx As Integer As Single 求 x Dim f As Single i As Integer f1 For i 1 To x ffi 累积 Next i fact fEnd FunctionPrivate Sub Form_Click Dim n m y Do m ValInputBoxquotmquot n ValInputBoxquotnquot Loop Until m gt n And n gt 0 y factm / factn factm - n Print yEnd Sub2 private sub Insertfuna y Dim i as integern as integer nubounda Redim preserve an1 For iubounda-1 to 0 step -1 If y ltai then ai1ai If i0 then aiy Else ai1y exit for end if next i3. 判断是否为回文函数Private Function Judgestr As String As BooleanDim i As Integer Judge True 假设为回文 For i 1 To Lenstr 2 依次判断对应位置的两个字符,只要有一组不等即不是回文 If Midstr i 1 ltgt Midstr Lenstr 1 - i 1 Then Judge False Exit Function End If Next iEnd Function4.Private Sub Form_Click Dim nx n ValInputBoxquotnquot x ValInputBoxquotxquot Print fen x 调用求值函数过程End Sub求值函数过程Public Function fen x As Single Dim i As Integer t As Single fe 1: t 1 For i 1 To n ttx/i t 为通项 fe fe t Next iEnd Function 。
。
5.。
。
第 7 章 习题参考答案一、判断题题号 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16答案 × × √ √ × × × √ √ √ × × √ √ × √二、填空题 1.___Multiline_______ 2.____Value______ 3.___Selected______、____List______、____0______、___List1.ListCount-1____ 4. 下拉式
列表框 5.___LargeChange_______、____Value______ 6. ShiftCtrl 7.KeyAscii0 if KeyAsciigt57 OR KeyAsciilt48 then KeyAscii0三、程序填空 1. Label1.Font Combo1.Text Combo2.Text Label1.FontBold True Label1.FontItalic True Label1.FontSize ValCombo3.Text 2. List1.Listlist1.ListIndex list1.RemoveItem List1.ListIndex List1.AddItem List2.ListList2.ListIndex List2.RemoveItem四、选择题 题号 1 2 3 4 5 6 7 8 答案 A D D B D D C D五、编程题1.添加功能Private Sub cmdAdd_Click Dim i If Combo1.Text quotquot Then Exit Sub For i 0 To Combo1.ListCount - 1 逐个判断是否有与输入内容相同的项目 If Combo1.Text Combo1.Listi Then Exit Sub 找到相同项目则退出 Next i Combo1.AddItem Combo1.Text 未找到则添加End Sub删除功能Private Sub cmdDelete_Click If Combo1.ListIndex gt 0 Then 是否选中某一项目 Combo1.RemoveItem Combo1.ListIndex 删除选中项目 Else 删除与输入内容相同的项目 For i 0 To Combo1.ListCount - 1 If Combo1.Listi Combo1.Text Then .