




已阅读5页,还剩57页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第一章 VB开发环境与VB概述 习题答案习题一、选择题1.2.3.4.5.6.7.8.9.10.11.12.13.14.BAABDBAACBCDAD第二章 常用控件与界面设计 习题答案习题一、选择题15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.CBCAABBBCCBBDAB30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.BBCCDBBBCCCABBC45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.BCBBDBDDBABABBD60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.AABDCDDCDDCACCB75.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 DB_DB21-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
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 庭院改造方案范本
- 解放路桥占道施工方案
- 2025贵州省水利厅所属事业单位第十三届贵州人才博览会引才模拟试卷附答案详解(模拟题)
- 庆阳水泥渗水砖施工方案
- 逾期咨询债务补救方案范文
- 廊坊液压顶管施工方案
- 2025年春季四川省国农天府农业发展有限公司招聘10人考前自测高频考点模拟试题及答案详解(夺冠)
- 2025年福建省泉州市永春县永源城市建设有限公司招聘11人模拟试卷及完整答案详解
- 2025广西玉林市北流市中医医院招聘编外人员21人模拟试卷及答案详解(名校卷)
- 律所咨询活动方案
- 宿管员业务知识培训内容课件
- 安全生产例会会议记录以及会议内容
- 眼视光技术介绍
- DB64T 2146-2025 工矿企业全员安全生产责任制建设指南
- 间歇充气加压用于静脉血栓栓塞症预防的中国专家共识解读
- 2025年宜宾市中考语文试题卷(含答案详解)
- 2025-2030中国止痛药品市场供需形势及未来前景动态研究报告
- 儿童化妆教学课件
- 配送中心合伙协议书
- 2025中美关税战时政述评-初中《道法》25年时政述评课件
- 中国成人患者围手术期液体治疗临床实践指南(2025版)解读 2
评论
0/150
提交评论