VB实验教材的实验与习题答案

上传人:无*** 文档编号:69584122 上传时间:2022-04-05 格式:DOC 页数:62 大小:457KB
返回 下载 相关 举报
VB实验教材的实验与习题答案_第1页
第1页 / 共62页
VB实验教材的实验与习题答案_第2页
第2页 / 共62页
VB实验教材的实验与习题答案_第3页
第3页 / 共62页
点击查看更多>>
资源描述
课后答案网,用心为你服务!第一章 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. 39. 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 = 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(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 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 = 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(请输入商品的单价:, 单价框) 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 = 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 - 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 -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 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 Sub3、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; 实验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 第五章数组实验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. B12. 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 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 Integer 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_Click() 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 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 As 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 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 Next I For I = 80 To 125 If fun(I, P, S1, S2) Then If fun(I, P, S1, S2) Text1 = Text1 & Str$(I) & = & Str(S1) & * & Str$(S2) & vbCrLf End If Next IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As Integer For I = 1 To UBound(P) For J = 1 To UBound(P) - 1 If N = P(I) * P(J) Then S1 = P(I) S2 = P(J) fun = True Exit Function fun = True 位置错 End If Next J Next I End Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) ByVal idx As Integer Dim Ub As Integer, Counter As Integer, K As Integer Ub = UBound(Chess) Chess(idx) = 0 Counter = 1 K = 0位置错 Do Until Counter = Ub - 1 Do Until K = 2 idx = idx + 1 If idx Ub Then idx = 1 K = K + Chess(idx) Loop Chess(idx) = 0 Counter = Counter + 1 Loop For Over = 1 To Ub If Chess(Over) 0 Then Exit For Next OverEnd SubPrivate Sub Command1_Click() Dim Chess(32) As Integer, I As Integer, J As Integer Dim K As Integer, idx As Integer For I = 1 To 32 For J = 1 To 32 Chess(J) = 1 Next J Call Get_Chess(Chess, I, K) If K = 23 Then Text1 = 从第 & Str$(I) & 号棋子开始取 Exit For End If Next IEnd Sub5、Option ExplicitPrivate Sub Form_Click() Dim S As String, Flg As Boolean Do S = InputBox(输入一个自然数) If S = Or Not IsNumeric(S) Then MsgBox 请重新输入, 48 + vbOKOnly Else Exit Do End If Loop judge(S, Flg) Call judge(S, Flg) 或 judge S, Flg If Flg Then Print S; 是回文数 Else Print S; 不是回文数 End If End SubPrivate Sub judge(Ch As String, F As Boolean) Dim L As Integer, I As Integer L = Len(Ch) F = True F = False For I = 1 To L If Mid$(Ch, I, 1) Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next I F = False F = TrueEnd Sub四、编程题1、编程验证任一大于2的偶数可以表示成两个素数之和。Private Function Prime(a As Integer) As Boolean Dim i As Integer For i = 2 To Sqr(a) If a Mod i = 0 Then Exit Function Next i Prime = TrueEnd Function方法一Private Sub Command1_Click() Dim m As Integer, i As Integer m = InputBox(请输入一个大于2 的偶数) If m = 2 Or m Mod 2 0 Then MsgBox 请输入大于2的偶数: Exit Sub If Prime(2) And Prime(m - 2) Then Print m & =2 + & m - 2 Else Do i = i + 1 If Prime(2 * i + 1) And Prime(m - (2 * i + 1) Then Print m & = & 2 * i + 1 & + & m - (2 * i + 1) Exit Do End If Loop While 2 * i + 1 m - (2 * i + 1) End IfEnd Sub方法二Private Sub Command2_Click() Dim m As Integer, i As Integer, p() As Integer, n As Integer Dim flg As Boolean m = InputBox(请输入大于2的偶数) If m = 2 Or m Mod 2 0 Then MsgBox 请输入大于2的偶数: Exit Sub ReDim p(1) p(1) = 2 n = 1 For i = 3 To m - 2 Step 2 If Prime(i) Then n = n + 1 ReDim Preserve p(n) p(n) = i End If Next i For i = 1 To n For j = 1 To n If p(i) + p(j) = m Then Print m & = & p(i) & + & p(j) flg = True Exit For End If Next j If flg = True Then Exit For Next iEnd Sub2、求组合数(n=m),程序中必须包含一个求阶乘的通用过程。Private Function Fact(a As Integer) As Long If a = 0 Or a = 1 Then Fact = 1 Else Fact = a * Fact(a - 1) End If End FunctionPrivate Sub Command1_Click() Dim n As Integer, m As Integer, result As Single n = Val(Text1.Text) m = Val(Text2.Text) If n = m Then result = Fact(n) / Fact(m) / Fact(n - m) Text3.Text = result Else MsgBox 要求n=m,请重新输入 Text1.Text = Text2.Text = Text1.SetFocus End IfEnd SubPrivate Sub Command2_Click() Text1.Text = Text2.Text = Text3.Text = Text1.SetFocusEnd Sub3、编写一个查找10到300之间所有同构数的程序,程序中必须包含一个判定某数是否是同构数的Function过程Istgs。若一个数出现在自己平方数的右端,则此数为同构数。如5在52=25的右端,25在252=625的右端,故5和25为同构数。Private Function Istgs(n As Integer) As Boolean Dim s As String, L As Integer L = Len(CStr(n) s = CStr(n 2) If Right(s, L) = n Then Istgs = TrueEnd FunctionPrivate Sub Command1_Click() Dim n As Integer For n = 10 To 300 If Istgs(n) Then List1.AddItem n & 2 & =
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!