2022年《VB程序设计基础与VBA应用》-章答案 .pdf

上传人:Che****ry 文档编号:35294365 上传时间:2022-08-21 格式:PDF 页数:16 大小:476.42KB
返回 下载 相关 举报
2022年《VB程序设计基础与VBA应用》-章答案 .pdf_第1页
第1页 / 共16页
2022年《VB程序设计基础与VBA应用》-章答案 .pdf_第2页
第2页 / 共16页
点击查看更多>>
资源描述

《2022年《VB程序设计基础与VBA应用》-章答案 .pdf》由会员分享,可在线阅读,更多相关《2022年《VB程序设计基础与VBA应用》-章答案 .pdf(16页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、VB 程序设计基础与 VBA 应用P28 习题一二,单选题1,B 2,B 3,D 4,A 5, D 6,B 7,B 8,C 9,D 三 , 程序设计题5, Private Sub Command1_Click() Form1.FontName = 宋体 Form1.Print 中文字体宋体 End Sub Private Sub Command2_Click() Form1.FontName = 楷体 _GB2312 Form1.Print 中文字体楷体 End Sub Private Sub Command3_Click() Form1.FontName = 仿宋 _GB2312 Form1

2、.Print 中文字体仿宋 End Sub P57 习题二一,判断题对: 1, 3, 7,10,14 错: 2,4,5, 6,8,9,11,12, 13 二,单选题1,A 2, C 3, C 4, B 5,B 6,A 7, B 8, C 9, B 10, C 11, C 12, D 13, B 14, A 15, D 16 , B 17 , B 18, C 19, B 20, B 21, B 22 , D 23, A 24, C 25, B 26, A 27 , D 28, B 三,简答题1. (1) 2 * Cos(alfa) * Sin(alfa/ ( 2 * a ) (2) Sqr( s

3、*(s a)*(s b )*(s - c) (3) ( A*A + B*C*(X +Y) / (A+B) (4) ( 2* 3.14159*r +Exp(-5)* Log(x) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 16 页 - - - - - - - - - (5) 1/( x + 1/(y+1) ) (6) k / ( 1 + a * Exp(-b*x) ) (7) Cos(alfa) 2 + Atn(alfa) (8) Sqr( y3 + 3 * (a*a

4、+b*b) / (x*x+y*y) ) 2. (1) (a+b) Mod c (2) Sqr(Abs(x) (3) Int(x) + 1 (4) Int(Rnd *101)+200 3。( 1)F (2) T (3) F (4) T 4 (1) 1=x And x12 (2) T+3V-2 And (T+V)100 (3) (a+b) = c or (a-c) 0 And Int(a)=a And b0 And Int(b)=b or a0 And b0 (5) x=z (6) a=0 And b0 or a0 And b=0 四, 编程题1. Private Sub Form_Click()

5、 Dim a As Integer, b As Integer, c As Integer Dim y As Single a = InputBox(请输入正整数a 的值 ) b = InputBox(请输入正整数b 的值 ) c = InputBox(请输入正整数c 的值 ) y = (a + b + c) / 3 Print 平均值 : ; y End Sub 2Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer Dimy As Single a = Val(Text1.Text) b = Va

6、l(Text2.Text) c = Val(Text3.Text) y = (a + b + c) / 3 Label1.Caption = Str(y) End Sub 3. Private Sub Form_Click() Dim r As Integer, s As Single Const Pi = 3.14159 r = InputBox(输入圆半径 ) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 16 页 - - - - - - - - - s = Pi

7、* r * r MsgBox 圆面积Area = + Str(s) End Sub P114 习题三一,1, A 2,B 3,B 4,A 5,C 二, 1,37,55 ,64,28, 19 2,y=KIGECA 3,1 121 12321 1234321 123454321 12345654321 4,cHINA !三,1,t As Double s=1 Abs(t)=0.00001 s=s+t 2, s+c -1 s 3, m=n m To n Sum=Sum+j Sum=i 四,1,Private Sub Form_Click()Dim x As Single, f As Single x

8、 = InputBox(输入 x: ) If x -5 Then f = 3 * x * x + 2 * x - 1 ElseIf x = 5 Then f = x * Sin(x) + 2 x Else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 16 页 - - - - - - - - - f = Sqr(x - 5) + Log(x) / Log(10) End If Label1.Caption = f End Sub 2. Private Sub Form_

9、Click() Dim n As Integer, i As Integer, flag As Integer, s As Single, t As Integer n = InputBox(请输入 n 的值: ) sum = 0 t = 1 flag = -1 For i = 1 To n flag = -flag t = t * i s = s + flag * i / t Next i Print s=; s End Sub 3. Private Sub Command1_Click() For i = 1 To 9 For j = 1 To i Print i; *; j; =; i

10、* j; Next j Print Next i End Sub 4. Private Sub Form_Click() For i = 1 To 5 Print Tab(6 - i); For j = 1 To 2 * i - 1 Print *; Next j Print Next i For i = 4 To 1 Step -1 Print Tab(6 - i); For j = 1 To 2 * i - 1 Print *; Next j 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - -

11、- - 第 4 页,共 16 页 - - - - - - - - - Print Next i End Sub P152 练习四一、单选题1,B 2, D 3, C 4,C 5, D 二、程序阅读题1,2 4 7 11 16 2, 1 4 9 16 25 3,2 3 4 5 3 4 5 6 4 5 6 7 4,12 10 9 5,div = 3 三、程序填空题1、Len(str1) Mid(str1, i, 1) p = j i p 2、l = Len(str) a(i) = Mid(str, i, 1) p = s - 96 x(p) = x(p) + 1 3、a(1 To 4, 1 To

12、5) s = 0 a(i, 5) = s / 4 四,程序设计题1,Private Sub Form_Click() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 16 页 - - - - - - - - - Dim a(50) As Integer, i As Integer , j As Integer, sum As Integer Dim max As Integer, min As Integer, aver As Single sum=0 For i = 1

13、 To 50 a(i) = Int(Rnd * 71) + 30 sum = sum + a(i) Next i aver = sum / 50 For i = 1 To 50 Print a(i); If i Mod 5 = 0 Then Print Next i max = a(1): min = a(1) For i = 2 To 50 If a(i) max Then max = a(i) If a(i) min Then min = a(i) Next i Print 最大值: ; max, 最小值: ; min, 平均值 ; aver End Sub 2. Private Sub

14、Form_Click() Dim max As Integer, min As Integer Dim a() As Integer n = Val(InputBox() ReDim a(n) As Integer For i = 1 To n a(i) = Int(Rnd * 100) Print a(i); Next i For i = 1 To n If a(i) Mod 2 = 0 Then min = a(i) Else max = a(i) If min 0 And max 0 Then Exit For Next i For i = 1 To n If a(i) Mod 2 =

15、0 And min a(i) Then min = a(i) ElseIf a(i) Mod 2 = 1 And max a(i) Then max = a(i) End If Next i Print max=; max, min=; min End Sub 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 16 页 - - - - - - - - - 3. 冒泡法:Private Sub Form_Click() Dim a(10) As Integer For i =

16、 1 To 10 a(i) = Int(Rnd * 90) + 10 Print a(i); Next i Print For i = 1 To 9 For j = 1 To 10 - i If a(j) a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t Next j Next i For i = 1 To 10 Print a(i); Next i End Sub 选择法:Private Sub Form_Click() Dim a(10) As Integer For i = 1 To 10 a(i) = Int(Rnd * 90)

17、 + 10 Print a(i); Next i Print For i = 1 To 9 For j = i + 1 To 10 If a(i) = 90 Then score(1) = score(1) + 1 ElseIf a(i) = 80 Then score(2) = score(2) + 1 ElseIf a(i) = 70 Then score(3) = score(3) + 1 ElseIf a(i) = 60 Then score(4) = score(4) + 1 Else score(5) = score(5) + 1 End If Next i For i = 1 T

18、o 5 Print score(i) Next i End Sub P182 练习五一对: 1,2,3, 4,6, 7,9 错:5,8 二1,D 2,C 3,A 4,B 5,D 6,A 7,(全错 ) 8,D 三1, D D B B 2,1)Int(Rnd * 21) + 30 2)For j = i + 1 To 10 3)Call Swap(a(i), a(j) 4)a(10) 3,1) If Isprime(i) And Isprime(x - i) Then 2) Isprime = True 3) If x Mod i = 0 Then 四,19 76 2,4 名师资料总结 - -

19、-精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 16 页 - - - - - - - - - -9 3,6 4 6 48 36 42 4,26 9 五,1、Private Sub Command1_Click() Dim a() As Single, n As Integer, s As Single Dim v As Single, i As Integer n = InputBox(请输入 n 的值 ) ReDim a(n) For i = 1 To n a(i) = InputBox()

20、 Next i v = f(a, n) For i = 1 To n s = s + (a(i) - v) 2 Next i s = Sqr(s) / n Print s End Sub 2,Private function fsum(x() As Single, m As byte)as single fsum = x(1) For i = 2 To m Fsum=fsum+x(i) Next I End function P213 练习六一,单选题1,A 2, A 3,C 4,C 5,C 6, B 7,A 8,A 二,阅读题1代码 1 名师资料总结 - - -精品资料欢迎下载 - - -

21、- - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 16 页 - - - - - - - - - 代码 2 2,名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 16 页 - - - - - - - - - 34名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 16 页 - - - -

22、 - - - - - 5三,程序设计题1Public Sub Rectangle(ByVal a As Single, ByVal b As Single, y As Single) Dim y As Single y = a * b End Sub 2名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 16 页 - - - - - - - - - Public Function Round(ByVal r As Single) As Single Round = 3.14

23、159 * r * r End Function P269 书面练习 7 二程序阅读题1, 保存所有打开的工作簿,关闭ExceL 2, 实现定时提醒,17 :00 显示一个提醒信息。3, 查找工作表“ KK” ,若有,则结束过程,否则,在第一张工作前添加工作表“KK”4, 56 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 16 页 - - - - - - - - - 6把工作表指定区域的数化为以万为单位(输入小数位数)7在当前工作表的第2 行以下第 3 列中输入或修

24、改单元格内容,则自动转换成“编号”工作表中A2 以下 A 列中相同内容的单元格的右边单元格的内容。3程序设计题1,Sub Workbook_BeforeClose(Cancel As Boolean) Dim i As Integer, j As Integer, k As String For i = 66 To 68 For j = 3 To 12 k = Chr(i) & j If Range(k).Value 100 Then Cancel = True MsgBox 成绩应该在0100 之间,否则,不允许关闭工作簿! End If Next j Next i End Sub 2. P

25、rivate Sub ChFmt() Dim i As Long, j As Long For i = 1 To Sheet1.UsedRange.Rows.Count For j = 1 To Sheet1.UsedRange.Columns.Count If Cells(i, j).Value 0 Then Cells(i, j).Font.Color = RGB(255, 0, 0) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 16 页 - - - - - -

26、 - - - Cells(i, j).Font.Bold = True End If Next j Next i End Sub 3, Private Sub Workbook_Open() Dim i As Integer, j As Integer For i = 1 To 10 For j = 1 To 10 Worksheets(sheet1).Cells(i, j) = Int(Rnd() * 90) + 10 Next j Next i End Sub Sub bs6() Dim i As Integer, j As Integer, k As Integer k = 1 For

27、i = 1 To 10 For j = 1 To 10 If Worksheets(sheet1).Cells(i, j) Mod 6 = 0 Then Worksheets(sheet2).Cells(k, 1) = Worksheets(sheet1).Cells(i, j) k = k + 1 End If Next j Next i End Sub 4, Sub zz() Dim i As Integer, j As Integer Dim m As Integer, n As Integer m = InputBox() n = InputBox() For i = 1 To m F

28、or j = 1 To n Worksheets(sheet1).Cells(i, j) = Int(Rnd() * 90) + 10 Next j Next i 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共 16 页 - - - - - - - - - For i = 1 To m For j = 1 To n Worksheets(sheet2).Cells(j, i) = Worksheets(sheet1).Cells(i, j) Next j Next i End Sub 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 16 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

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

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁