1、课后答案网,用心为你服务!第一章 VB开发环境与VB概述 习题答案习题一、选择题1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. BAABDBAACBCDAD第二章 常用控件与界面设计 习题答案习题一、选择题1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. CBCAABBBCCBBDAB16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. BBCCDBBBCCCABBC31. 32. 33. 34. 35. 36. 37. 38. 3
2、9. 40. 41. 42. 43. 44. 45. BCBBDBDDBABABBD46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. AABDCDDCDDCACCB61. B第三章实验与习题实验实验3_1算术运算Private Sub Command1_Click() Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6 Dim x As Single, y As Single, z As Single, m As Single x
3、 = 2: y = 1: z = 1: m = 1 List1.Clear List1.AddItem a / (b + c / b) List1.AddItem (x + Sqr(x 2 + 1) (1 / 3) List1.AddItem (2 * y) / (a * x + b * y) * (a * x - b * y) List1.AddItem 1 + 1 / (1 + 1 / m) List1.AddItem 1 / 2 * (d / 3) (2 * x) List1.AddItem Log(y + Cos(x) 2) List1.AddItem Abs(Exp(x) + Sin
4、x) 3) / (x + y) List1.AddItem Log(Exp(x * y) + Abs(1 / Tan(z) + Cos(x) 3) / (x + y - z) List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10) / Sqr(x + y + 1) List1.AddItem Log(a) / Log(b)End Sub关系运算Private Sub Command2_Click() List1.Clear List1.AddItem Mid(Visual Basic, 1, 12) = Right(Language
5、 Visual Basic, 12) List1.AddItem ABCRG = abcde List1.AddItem Int(134.69) = CInt(134.9) List1.AddItem 78.9 / 32.77 -4.98 List1.AddItem Str(32.345) = CStr(32.345)End Sub逻辑运算Private Sub Command3_Click() Dim x As Integer, y As Integer Dim C1 As Integer, C2 As Integer, C3 As Integer C1 = 70: C2 = 80: C3
6、 90 x = 9: y = -2 List1.Clear List1.AddItem x + y 0 List1.AddItem (x% = 0 And y% = 0) Or (x% 0 And y% = 255 Or C1 90 And C2 90 And C3 80End Sub实验3_2略实验3_3略实验3_4零售结算Private Sub Command1_Click() Dim dj As Single, sl As Single, je As Single, n As Integer Label1.Caption = 金额: dj = InputBox(请输入商品的单价:, 单
7、价框) sl = InputBox(请输入商品的数量:, 数量框, 1) je = dj * sl n = MsgBox(共计金额= & je, vbOKCancel + vbInformation, 结果) If n = vbOK Then Label1.Caption = 金额: & Str(je) & 元End Sub产生随机数Private Sub Command2_Click() Dim m As Integer, n As Integer Dim x1 As Integer, x2 As Integer, x3 As Integer m = Val(Text1.Text): n =
8、 Text2.Text Randomize x1 = Int(Rnd * (n - m + 1) + m) x2 = Int(Rnd * (n - m + 1) + m) x3 = Int(Rnd * (n - m + 1) + m) Label4.Caption = 结果为: & Str(x1) & Str(x2) & Str(x3) End Sub求逆序数Private Sub Command3_Click() Dim a As Integer, h As Integer, t As Integer, n As Integer Randomize a = Int(Rnd * (999 -
9、100 + 1) + 100) h = Mid(CStr(a), 1, 1) t = Mid(CStr(a), 2, 1) n = Right(CStr(a), 1) Label5.Caption = a & - & Format(n * 100 + t * 10 + h, 000)End Sub实验3_5略习题选择题1-20: DBBDB DDBCA DDDCD DBADB21-40: DCDAA B_ACA BCADA B_BCD41-60: BCBDC CADBA CBDDD ABAAA61-80:BBCAB BDAAA CBBDD CBDAD81-89:CBDBB BADC填空题1、2
10、 -32768327672、整型 长整型 单精度 双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”)+Asc(“C”) x0 And y0 Or x0 And y=”a” And c=”A” And c=10 And x20 xz Xor yz5、False 2 True False True True True True6、188 200100 68.56 8765547、a=1 b=1 a=2 b=1a=3 b=1 a=4 b=18、Y Mod 4=0 And Y Mod 1000 Or Y Mod 400 =09、He Said, “Good
11、morning”.10、EDEF11、(A0 And AInt(A) And (B0 And BInt(B)12、a+b+c+d(a+b+c+d)/4sumaver13、(f-2*h)/2(4*h-f)/2简答题1、略2、Private Sub Form_Click() Const g = 9.8 Dim V0 As Single, t As Single Dim S As Single V0 = InputBox(请输入V0的值:) t = InputBox(请输入时间t的值:) S = (1 / 2) * g * t 2 + V0 * t MsgBox (位移量为: & S)End Sub
12、3、Private Sub Command1_Click() Dim l As Single, w As Single, h As Single Dim s As Single l = Text1.Text w = Text2.Text h = Text3.Text s = (l * w + l * h + w * h) * 2 Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1 方法一: x=5 ; y方法二:Is=2;Case Else实验4-2Shape1.BackColor=vbRed;Inter=15;Inter=Inter-1;Inter; 实
13、验4-3 bc b=a a=k实验4-4方法二: s*n; t/s=10-4; (-1)(n+1)*m实验4-6 x2=x3 ; 102. 93. 3; 4 154. this is a book;This Is A Book5. 3 ; 3 ; 3 56. 32 07. 48. 15 19. 1 ; 401 ;10410. 1 2 3 ;1 3; 111. (3)12. 2 0 2413. 10 1414. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False16. abs(t)Mid(n,i+1,1)19. 输入n;N/I=0 ;Print I 第五章
14、数组实验5_1Int(90 * Rnd) + 10a(i) = a(21 - i)a(21 - i) = t5_2k = x Mod 10i = i + 15_3s5_4max = 0 And ch = i If x Mod i = 0 Then k = k + 1 ReDim Preserve a(k) a(k) = i x = x i Else i = i + 1 End If Loop For j = 1 To UBound(a) Print a(j); Next jEnd Sub习题一 选择题1. A2. C3. D4. C5. B6. D7. D8. B9. D10. B11. B1
15、2. D二 填空题1. Variant2. ReDim A(N)A(1)If M A(j)4. InStr(s, ,)Right(s, Len(s) - n)s5. 4 5 66 5 43 2 16. T 1I + 17. k = 6 - i jmax = m8. j = aj = j - 39. i + 1i = i + 110. 237三 编程题1Option ExplicitOption Base 1Private Sub Command1_Click() Dim a(10) As Integer Dim i As Integer, max As Integer For i = 1 To
16、 10 a(i) = Int(90 * Rnd) + 10 Print a(i); Next i Print i = 1 max = 0 Do While i max Then max = a(i) End If End If i = i + 1 Loop If max = 0 Then Print 无要找的数 Else Print max & 是最大的能被3整除的数 End IfEnd Sub2Option ExplicitOption Base 1Private Sub Command1_Click() Dim A() As Integer Dim I As Integer, m As I
17、nteger Dim K As Integer ReDim A(10) For I = 1 To 10 A(I) = I Print A(I); Next I Print m = InputBox(m) K = 9 + m ReDim Preserve A(K) For I = 11 To K A(I) = A(I - 10) Next I For I = 1 To 10 A(I) = A(I + m - 1) Next I For I = 1 To 10 Print A(I); Next I PrintEnd Sub3Option ExplicitPrivate Sub Command1_C
18、lick() Dim I As Integer, J As Integer, K As Integer Dim a() As Integer, n As Integer, p As Integer Dim s As String, Flag As Boolean p = 1 For K = 10 To 100 I = 1 Do While I = 10 And Not Flag J = 1 Do While J J Then M = I - J N = I + J If Sqr(M) = Int(Sqr(M) And Sqr(N) = Int(Sqr(N) Then List1.AddItem
19、 I & & J a(K, 1) = I a(K, 2) = J K = K + 1 End If End If Next JNext IEnd Sub第六章 参考答案实验实验6-11、 Exit Do2、 Y(X)3、 X = -1实验6-2【题目二】42 、26、8实验6-31、 s1, key2、 s As String3、 ch = a And ch = z4、 Mid(s, i, 1) = Chr(Asc(ch) + k - 26)思考:解密函数Private Sub dec(s As String, k As Integer) 解密过程 Dim i As Integer, ch A
20、s String * 1 For i = 1 To Len(s) ch = Mid(s, i, 1) If A = ch And ch = Z Then If Asc(ch) - k = a And ch = z Then 多分支格式,ch介于小写a与z之间 If Asc(ch) - k Asc(a) Then Mid(s, i, 1) = Chr(Asc(ch) - k + 26) 小于a的ASCII值则加上26 Else Mid(s, i, 1) = Chr(Asc(ch) - k) End If End If Next iEnd Sub实验6-41、 b() As Integer, st
21、 As String2、 L = R3、 ReDim Preserve b(R)4、 L = L + 1辗转相除法求最大公约数函数Private Function Gcd(ByVal p As Integer, ByVal q As Integer) As Integer Dim r As Integer r = p Mod q Do While r 0 p = q q = r r = p Mod q Loop Gcd = qEnd Function实验 6-5【题目一】age = age(n - 1) - 3【题目二】1、(Left + Right) / 22、Left = Mid + 1实验6-61、3-12、743、3-14、70实验6-7【题目一】1、 Sqr(2 + t)2、 Abs(a - 1) Sqr(I) Then ReDim Preserve P(UBound(P) + 1) P(UBound(P) + 1) = I P(UBound(P) = I End If Nex
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818