vb第六章答案
- 格式:doc
- 大小:899.00 KB
- 文档页数:24
习题六一、选择题答案Aadcc dc二、填空题答案1、a(I,j)+b(I,j)2、下标越界3、64、1 2 2 4 3 6第六章选择题部分解析3、sum表示a数组各元素的和X表示a数组元素和的平均值最后打印出a数组中大于平均值的元素Sum=1+2+3+4+5=15,x=3大于3的有4,55、倒着看文本框中显示什么?答:显示的是array1(1,3)+array2(2,3)的和接着往前看程序发现array1(i,j)=i+j所以array1(1,3)=1+3=4Array2(2,3)=2+3=5所以4+5=9二、填空题解析2、x数组最大元素是x(6)退出for循环时,i=7然后print x(i)相当于print x(7)但是没有x(7)这个元素,超出最大下标了。
若把print x(i)改为print x(a)则值是36第六章编程题1、Private Sub Form_Click()Dim a(1 To 20) As Integer, i As IntegerDim j As Integerj = 0 '用来表示小于60的个数Picture1.Print "产生的数组为:"Picture1.PrintPicture2.Print "其中小于60的元素有:"Picture2.PrintFor i = 1 To 20a(i) = Int(Rnd * 100 + 1)Picture1.Print a(i);If i Mod 10 = 0 Then Picture1.PrintIf a(i) < 60 Thenj = j + 1Picture2.Print a(i); " ";If j Mod 10 = 0 Then Picture2.PrintEnd IfNext iEnd SubPrivate Sub Form_Load()RandomizeEnd Sub2、Private Sub Form_Click()Dim a(1 To 10) As IntegerDim max As Integer, min As Integer, i As IntegerFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Picture1.Print a(i);If i Mod 5 = 0 Then Picture1.PrintNext imax = a(1)min = a(1)For i = 2 To 10If a(i) > max Then max = a(i)If a(i) < min Then min = a(i)Next iLabel1.Caption = "最大数为:" & maxLabel2.Caption = "最小数为:" & minEnd SubPrivate Sub Form_Load()RandomizeEnd Sub3、Dim a(1 To 20) As IntegerPrivate Sub Command1_Click()Dim x As Integer, flag As Integer, i As Integerflag = 0 '标志,表示数组中是否存在xx = InputBox("请输入x的值,为整数", "输入", 1) For i = 1 To 20If x = a(i) Thenflag = 1 'flag改变,说明存在Exit ForEnd IfNext iIf flag = 1 ThenPrint "数组中存在" & xPrint "位置:" & iElsePrint "数组中不存在" & xEnd IfEnd SubPrivate Sub Form_Click()Dim i As IntegerFor i = 1 To 20 '生成数组a(i) = Int(Rnd * 100) '题目没要求,随便的范围Next iFor i = 1 To 19 '冒泡排序For j = 20 To i + 1 Step -1If a(j) > a(j - 1) Thent = a(j)a(j) = a(j - 1)a(j - 1) = tEnd IfNext jNext iFor i = 1 To 20 '打印数组Print a(i);If i Mod 5 = 0 Then PrintNext iEnd SubPrivate Sub Form_Load()RandomizeEnd Sub4、Private Sub Form_Click()Dim a(1 To 15) As SingleDim i As Integer, c1 As Integer, c2 As Integer, c3 As Integer, avg As SingleFor i = 1 To 15a(i) = InputBox("请输入第" & i & "个学生的成绩", "输入成绩", 60)avg = avg + a(i)Next iavg = avg / 15For i = 1 To 15If a(i) > avg Then c1 = c1 + 1If a(i) < 60 Then c2 = c2 + 1If a(i) >= 90 Then c3 = c3 + 1Next iPrint "高于平均分的人数"; c1Print "<60的人数"; c2Print ">=90的人数"; c3End Sub5、Dim a(1 To 4, 1 To 4) As Integer, b(1 To 4, 1 To 4) As Integer, c(1 To 4, 1 To 4) As IntegerPrivate Sub Command1_Click()‘(2)题For i = 1 To 4For j = 1 To it = a(i, j)a(i, j) = a(j, i)a(j, i) = tNext jNext iPicture2.ClsPicture2.Print "a转置后:"Picture2.PrintFor i = 1 To 4For j = 1 To 4Picture2.Print a(i, j); " ";Next jPicture2.PrintNext iEnd SubPrivate Sub Command2_Click()‘(3)题Picture2.ClsMax = c(1, 1)t1 = 1t2 = 1For i = 1 To 4For j = 1 To 4If c(i, j) > Max ThenMax = c(i, j)t1 = it2 = jEnd IfNext jNext iPicture2.Print "max=", MaxPicture2.Print "c("; i; ","; j; ")"End SubPrivate Sub Command3_Click()‘(4)题Picture1.ClsPicture2.ClsFor i = 1 To 4For j = 1 To iPicture1.Print a(i, j); " ";Next jPicture1.PrintNext iFor i = 1 To 4For j = i To 4Picture2.Print Tab(j * 5); b(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command4_Click()‘(5)题Picture1.ClsFor i = 1 To 4t = a(1, i)a(1, i) = a(3, i)a(3, i) = tNext iFor i = 1 To 4For j = 1 To 4Picture1.Print a(i, j); " ";Next jPicture1.PrintNext i End SubPrivate Sub Command5_Click()‘(1)题Picture3.Print "c矩阵:"Picture3.PrintFor i = 1 To 4For j = 1 To 4c(i, j) = a(i, j) + b(i, j)Picture3.Print c(i, j); " ";Next jPicture3.PrintNext iEnd SubPrivate Sub Form_Load()ShowPicture1.Print "a矩阵:"Picture1.PrintPicture2.Print "b矩阵:"Picture2.PrintFor i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 40 + 30)b(i, j) = Int(Rnd * 35 + 101)Picture1.Print a(i, j); " ";Picture2.Print b(i, j); " ";Next jPicture1.PrintPicture2.PrintNext iEnd Sub。
第6章过程与函数一、填空题1.数组名作为过程或函数实参,相应的形参传递方式为____按地址传递____。
2.一维长整型数组a作过程形参写作:a() As Long,二维长整型数组b作过程形参写作:____b() As Long ____。
3.过程形参为整型,对应实参为5.64,传递给形参的值为____6____。
4.调用过程时对形参的改变不会导致相应实参变量的改变,则该形参采用____按值传递____方式。
5.调用过程时对形参的改变就是对相应实参变量的改变,则该形参采用____按地址传递____方式。
6.声明Single类型全局变量x,写作____Public x As Single(或 Publicx!)____;声明Integer类型静态变量x,写作____Static x As Integer(或 Static x%)____。
7.在窗体Form1的过程中引用窗体Form2中的全局变量y,写作____Form2.y____。
8.阅读如下代码,单击窗体后,窗体上的显示结果为____s = 2 s = 5 s =9____。
Dim i As Integer, n As IntegerPrivate Sub Form_Click()Dim i As IntegerFor i = 1 To 3s = sum(i): Print "s ="; s;Next iEnd SubPrivate Function sum(n As Integer)Static j As Integerj = j + n + 1: sum = jEnd Function二、选择题1.VB程序设计语言中,函数过程与子过程必须分别用关键字( C)声明。
(A)Private,Public (B)Public,Private(C)Function, Sub (D)Sub, Function2.要调用一个已经定义好的函数myfunction( ),用语句的方式调用函数,下列写法哪个是正确的(D)(A)Call myfunction (B)myFunction(C)myFunction ( ) (D)CallmyFunction( )3.定义过程时,如果在过程名前加关键字Private,则该过程为( A)。
VB课后练习答案P12第一章课后练习答案:一、选择题二、填空题第二章(P39)选择题答案:填空题答案:1.Cmdl, Click2.Text 1.Text二"Hello"P64第三章课后练习答案一、选择题二、填空题1.(Y Mod 4=0 And Y Mod 10000) Or Y Mod 400=0 2.a<>0 And b*2-4*a*c>=0 3.X Mod 5=0 And X Mod 2=0 或 Tnt(x/5)=X/5 And Int(X/2)=X/2 4. 注意:返回的均是字符型。
第四章课后答案:P79一、选择题答案为:$$41.50010二、填空题三、程序设计题(提示)1、鸡的头数为x,兔的头数为y,则可列方程式:\x-\- y = h (兀 * 2 + y * 4 =于求得x, y 的值再在窗体上输出结果。
2、 利用Format 格式函数,再通过窗体的Print 将格式化后的信息输出到窗体上。
3、 厶员I 的周长=2加" $岡的面积=加25、通过Inputbox 函数或用文本框输入三边和圆的半径a,b,c, r,利用公式:. a + b + cn 二 ---------2 S 三角形面积=Jh (h - - b )(h - c )P97第五章课后练习答案:第9题| D一、选择题答案D 改为:30二、填空题第]题Y Mod 4二0 And Y Mod 100二0 Or Y Mod 400二0 第2题笫3题笫4题Private Sub Command l_Click()X=Val(Textl.Text)Select Case XCase Is>200. Isv-10()Print “xv 100 Or x>200"Case ls<=0Y=l()()-XCase Isv二100Y=100+XCase Is<=200Y=400End SelectText2.Text=yEnd Sub三、程序设计题(提示)1、判断条件:假设一个整数为xX Mod 3=0 Or x Mod 5=0 或x/3=x\3 Or x/5=x\52、选项按钮的知识点在P182,利用该控件的Wlue属性判断是否选中该项。
1.阅读程序,写出程序结果答: 6 7 92 5 81 3 42.提示:在交换首尾对称位置的数组元素时注意,循环的终值只能到数组的一半,而不能到数组的最大下标,否则会将数组元素值又还原成原来的数值。
程序界面如下图5-2所示:图5-2参考程序如下:Private Sub Command1_Click()Dim a(15) As Integer, i As Integer, j As Integer, t As Integer'给数组赋值,并输出在文本框1中For i = 1 To 15a(i) = Int(Rnd * 100) + 1Text1.Text = Text1.Text & Str(a(i))Next i'交换数组对称位置的数据For i = 1 To 7t = a(i)a(i) = a(16 - i)a(16 - i) = tNext i'输出交换后的数组内容For i = 1 To 15Text2.Text = Text2.Text & Str(a(i))Next iEnd Sub3.提示:可以对数组的每个元素与其后面的所有元素逐个进行比较,如果有相同的数,将后面出现的数值清为0,最后统计所有不为0的数据个数。
参考程序如下:Private Sub Command1_Click()Dim a(20) As Integer, i As Integer, j As Integer, k As Integer'给数组赋值,并输出在窗体上RandomizeFor i = 1 To 20a(i) = Int(Rnd * 100) + 1Print a(i);Next iPrint'统计有多少个不相同的数For i = 1 To 19For j = i + 1 To 20If a(j) = a(i) Then a(j) = 0Next jNext i'统计不相同的数,并输出在窗体上For i = 1 To 20If a(i) <> 0 Then k = k + 1Next iPrint "一共有" & k & "个不相同的数"End Sub4.本题的主要思路是:先给数组的20个数赋值并输出,然后按照求最大值的算法思想,先将前4个数之和赋给存放最大值的变量max,同时记录4个数中第一个数的下标,然后对剩下的每4个数求和,判断是否大于max,如果是,将新的最大值送给max,同时记录其首数据的下标,最后,只要输出四个相邻数之和的最大值,并输出这四个数即可。
第6章图形控件和图形方法一、判断题1.√2.×3.√4.×5.√6.×7.×8.√9.√10.√二、选择题1.C 2.B 3.C 4.A 5.A 6.C 7.A 8.C 9.C 10.B 11.A 12.B 13.B 14.C 15.C三、填空题1.Circle (ScaleLeft + ScaleWidth / 2, ScaleTop + ScaleHeight / 2), 8002.LoadPicture 3.AutoSize、Stretch、False、False 4.选中、属性5.形状、矩形6.Picture1.Picture=LodePicture("C:\Windows\Cloud.bmp")7.图片框、其他控件8.缇、SclaeMode 9.颜色10.颜色、圆弧起点处转角、圆弧终点处转角、椭圆纵轴与横轴长度之比四、程序阅读题程序1. 转动一条红色直线,其轨迹形成一个圆程序2. 在窗体上随机的位置、用随机的颜色、半径绘制100个空心的圆。
程序3. 在图片框内绘制多个蓝色边框矩形,填充样式在“实心〞、“透明〞间交替变换。
程序4. 在图片框内绘制1个红色边框的蓝色实心椭圆。
五、程序填空题1.〔1〕List2.AddItem Str(i) 〔2〕Shape1.shape 〔3〕List2.ListIndex2.〔1〕1 〔2〕B 〔3〕-(50,60) 或-Step(80,0) 〔4〕P1.drawstyle3.〔1〕0 〔2〕ScaleWidth/2 〔3〕ScaleHeight / ScaleWidth注意:此题Form_load事件第1句代码有误,应为FillColor=vbGreen4.〔1〕Long 〔2〕P1.Point(a, b) 〔3〕P2.ScaleLeft + P2.ScaleWidth - a六、程序设计题程序1.界面如图6-32所示,过程设计如下:Private Sub Form_Load()Dim i As ByteList1.ClearFor i = 1 To 7List1.AddItem iNext iEnd SubPrivate Sub Form_MouseMove(Button As Integer, _Shift As Integer, X As Single, Y As Single)Label1.Caption = XLabel2.Caption = YEnd SubPrivate Sub List1_Click()Form1.ScaleMode = List1.TextEnd Sub程序2.界面设计略,过程设计如下:Dim x1 As Single, y1 As SinglePrivate Sub Form_Load()Form1.ScaleMode = 3Form1.ForeColor = RGB(255, 0, 0)Form1.FillColor = RGB(0, 0, 255)Form1.FillStyle = 0End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)x1 = X: y1 = YEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Line (x1, y1)-(X, Y), , BEnd Sub程序3.界面设计略,过程设计如下:Private Sub Form_Click()Form1.ClsDim r As SingleForm1.ScaleMode = 3Form1.DrawWidth = 2Form1.FillStyle = 0Form1.FillColor = vbBlueIf Form1.ScaleHeight <= Form1.ScaleWidth Thenr = Form1.ScaleHeight / 3Elser = Form1.ScaleWidth / 3End IfForm1.Circle (Form1.ScaleLeft + Form1.ScaleWidth / 2, _Form1.ScaleTop + Form1.ScaleHeight / 2), r, vbYellowEnd SubPrivate Sub Form_Resize()Call Form_ClickEnd Sub程序4. 界面如图6-33和6-34所示,过程设计如下:Dim x As Single, y As Single, c As LongDim r As Byte, g As Byte, b As BytePicture1.ScaleMode = 3For x =Picture1.ScaleLeft To Picture1.ScaleLeft + Picture1.ScaleWidth For y = Picture1.ScaleTop To Picture1.ScaleTop + Picture1.ScaleHeightc = Picture1.Point(x, y)If c >= 0 Thenr = c Mod 256g = (c \ 256) Mod 256b = (c \ 256 \ 256) Mod 256Picture1.PSet (x, y), RGB(r / 2, g / 3, b / 4)End IfNext yNext xEnd Sub程序5. 界面如图6-35所示,过程设计如下:Dim x As IntegerPrivate Sub Form_Load()P1.Width = P1.HeightP1.ScaleMode = 3P1.Scale (-10, 10)-(10, -10)P1.DrawWidth = 2x = 90Timer1.Enabled = FalseEnd SubTimer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()P1.PSet (8*Cos(x*3.141593 / 180), 8 * Sin(x * 3.141593 / 180)), vbRed x = x + 1If x > 450 Then Timer1.Enabled = FalseEnd Sub。
第一章VB程序设计概述二、选择题CADAB ACDAB CBDBB第二章VB可视化编程基础二、选择题ABDCA CACBC DADAD BDBBB三、填空题1.可视2.LEFT TOP WIDTH HEIGHT3.按字母序4.查看代码5.工具、选项6.Form1 Font7.Multiline8.只读属性9.工程属性通用Form1.show10.tabindex 0第三章VB语言基础二、选择题BCADB ADBBC DBCBA DAABB三、填空题1.整型、长整型、单精度、双精度2.sin(30*3.14/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)3.160 今天是:3-224.False5.-4 3 -3 3 -4 46.“CDEF”7.(x mod 10)*10+x\108.(35\20)*20=20 ( 35 \ 20 ) * 20 = 209.x mod 3=0 or x mod 5=010.27.6 8.2 8 1 100 397 true false第四章VB程序控制结构二、选择题DBCAD ABCAB D25BAC CBACB DABBC三、填空题1.字符型整型2. 1 2 33.x>74.x<amin5.10246.117.128.6 I “*”;9.0 100 i+1 10.2*I 6 “*”;三、编程题1.Private Sub Form_Click()Dim n As Integer, i As Integer, s As Longs = 1n = Val(InputBox("请输入一个整数:"))For i = 1 To ns = s * iNext iMsgBox n & "!=" & sEnd Sub2.Private Sub Form_Click()Dim i%, k%For j = 3 To 100k = Int(Sqr(j))For i = 2 To kIf j Mod i = 0 Then Exit ForNext iIf i > k Theny$ = y$ & " " & jEnd IfNext jMsgBox y, , "显示质数"End Sub3.Private Sub Form_Click()Dim i%, s%For i = 1 To 100s = s + iNext iMsgBox "1+2+3+……+100=" & sEnd Sub4.Private Sub Form_Click()Dim x%, y%For x = 1 To 50For y = 1 To 33z = 100 - x - yIf 2 * x + 3 * y + 0.5 * z = 100 ThenPrint "小鸡、公鸡、母鸡分别为:"; x; y; z End IfNext yNext xEnd Sub5.Private Sub Command1_Click()Dim a%, b%, c%, p!, s!doa = Val(InputBox("请输入三角形的第一条边"))if a=-1 then exit dob = Val(InputBox("请输入三角形的第二条边"))c = Val(InputBox("请输入三角形的第三条边"))If a + b > c And a + c > b And b + c > a Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Print sElseMsgBox "你输入的三边不能构成三角形,请重新输入"End IfloopEnd Sub6. Private Sub Form_Click()Dim i As Integer, j As Integer,k as integerFor i = 1 To 8For k=1 to 8-iPrint spc(3);Next kFor j = 1 To 2 * i - 1Print i;Next jPrintNext iEnd Sub7. Private Sub Form_Click()Dim i As Integer, j As Integer, k As IntegerFor i = 1 To 30For j = 1 To 30For k = 1 To 30If i ^ 2 + j ^ 2 = k ^ 2 ThenPrint i & " ^ 2 + " & j & "^ 2 =" & k & "^ 2"End IfNext kNext jNext iEnd Sub8.Private Sub Form_Click()Dim x As Integer, a As Integer, b As Integer, c As Integer, ss As String ss = ""For x = 100 To 999a = Int(x / 100)b = Int((x - 100 * a) / 10)c = x - 100 * a - 10 * bIf a ^ 3 + b ^ 3 + c ^ 3 = x Thenss = ss & " " & xEnd IfNext xPrint ssEnd Sub9.Dim sr As Long, r As Singlesr = Val(InputBox("请输入收入:"))Select Case srCase Is < 200r = 0Case 200 To 400r = (sr - 200) * 0.04Case 400 To 5000r = sr * 0.04Case Is >= 5000r = sr * 0.05End SelectPrint "收入为" & sr & "时所缴纳的税为:" & rEnd Sub10.Private Sub Form_Click()Dim t As Single, wf As Singlet = Val(InputBox("请输入上网时间:"))Select Case tCase Is < 10wf = 50Case 10 To 60wf = t * 6Case Is >= 60wf = t * 4End SelectIf wf >= 200 Thenwf = 200End IfPrint "上网时间为" & t & "小时上网的费用为:" & wf End Sub11. Private Sub Form_Click()Dim yf As Integeryf = Val(InputBox("请输入月份"))Select Case yfCase 12, 1, 2MsgBox yf & "月份是冬季"Case 3, 4, 5MsgBox yf & "月份是冬季"Case 6, 7, 8MsgBox yf & "月份是冬季"Case 9, 10, 11MsgBox yf & "月份是冬季"Case ElseMsgBox "输入错误,请重新输入"End SelectEnd Sub12.if的方法Private Sub Form_Click()Dim x As Single, f As Singlex = Val(InputBox("请输入一个数"))If x < 0 Thenf = 2 * x - 1ElseIf x = 0 Thenf = 4 * xElseIf x > 0 Thenf = 7 * x - 5End IfPrint "f(" & x & ")=" & fEnd SubSelect case语句:Private Sub Form_Click()Dim x As Single, f As Singlex = Val(InputBox("请输入一个数"))Select Case xCase Is < 0f = 2 * x - 1Case 0f = 4 * xCase Is > 0f = 7 * x - 5End SelectPrint "f(" & x & ")=" & fEnd Sub第五章数组一、选择题DCACD DBCDC BADAD二、填空题1.名称Index2.preserve3.变体4.235.1 2 3 1 4 16.1 2 3 2 4 67. max max=arr1(i)三、编程题1.Option Base 1Private Sub Form_Click()Dim a(10) As Integer, i%, temp%For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个整数")) Next iPrint "原来各元素的值为:"For i = 1 To 10Print a(i);Next iFor i = 1 To 5temp = a(11 - i)a(11 - i) = a(i)a(i) = tempNext iPrintPrint "交换后各元素的值为:"For i = 1 To 10Print a(i);Next iEnd Sub2.Option Base 1Private Sub Form_Click()Dim a As Variant, b As Variant, c As Variant, i%a = Array(2, 8, 7, 6, 4, 28, 70, 25)b = Array(79, 27, 32, 41, 57, 66, 78, 80)ReDim c(8)For i = 1 To UBound(a)c(i) = a(i) + b(i)Next iFor i = 1 To UBound(c)Print c(i);Next iEnd Sub3.Option Base 1Private Sub Form_Click()Dim a() As Variant, i%, j%, n%, m%, max%, hh%, lh%n = Val(InputBox("请输入一个整数:"))m = Val(InputBox("请输入一个整数:"))ReDim a(n, m)For i = 1 To n - 1For j = 1 To m - 1a(i, j) = Int(Rnd * 101 + 50)If max < a(i, j) Then max = a(i, j): hh = i: lh = jNext jNext iPrint "最大值为:"; max; "所在的行号为:"; hh; "所在的列号为:"; lh End Sub4.Option Base 1Private Sub Form_click()Dim a(50) As Integer, b(9) As Integer, i%, j% For i = 1 To 50a(i) = Int(Rnd * 90 + 10)j = Int(a(i) / 10)b(j) = b(j) + 1Next iFor j = 1 To 9Print b(j);Next jEnd Sub5.Option Base 1Private Sub Command1_Click(Index As Integer) Select Case IndexCase 0Text3 = Val(Text1) + Val(Text2)Case 1Text3 = Val(Text1) - Val(Text2)Case 2Text3 = Val(Text1) * Val(Text2)Case 3Text3 = Val(Text1) / Val(Text2)End SelectEnd Sub6.Private Sub Form_click()Dim s!, i&, j&i = 3s = 1j = 0Doj = j + 1s = s + (-1) ^ j / ii = i + 2Loop While 1 / i > 10 ^ (-6)Print 4 * sEnd Sub7.Option Base 1Private Sub Form_click()Dim a(40) As Long, i As Integera(1) = 1a(2) = 1For i = 3 To 39a(i) = a(i - 1) + a(i - 2)Next iFor i = 1 To 40Print a(i);Next iEnd Sub8.冒泡法:Option Base 1Private Sub Form_click()Dim a(10) As Single, ok As Boolean, i%, j%, x!For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Print a(i);Next iFor i = 10 To 2 Step -1ok = TrueFor j = 1 To i - 1If a(j) > a(j + 1) Thenx = a(j)a(j) = a(j + 1)a(j + 1) = xok = FalseEnd IfNext jIf ok Then Exit ForNext iPrintPrint "冒泡排序的结果为:"For i = 1 To 10Print a(i);Next iEnd Sub选择法:Option Base 1Private Sub Form_click()Dim a(10) As Single, p!, i%, j%, min!For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Print a(i);Next iFor i = 1 To 9p = iFor j = i + 1 To 10If a(j) < a(p) Then p = jNext jIf p <> i Thenmin = a(i)a(i) = a(p)a(p) = minEnd IfNext iPrintPrint "排序后的结果为:"For i = 1 To 10Print a(i);Next iEnd Sub第六章过程一、选择题CDBAB DBCCC ABCBD CDB二、填空题1.sub function2.形式实际3.内存的同一地址4.myf(a%,b() as integer ) as Boolean5.值传递地址传递6.lbound ubound7.局部8.通用任何过程9.2 5 9 10.2411.2 12.30 7013.-1三、编程题1. Option Base 1Private Sub Form_Click()Dim m1%, m2%, b() As IntegerFor i = 3 To 7 Step 2ReDim b(i)For j = 1 To ib(j) = Int(Rnd * 90 + 10)Print b(j);Next jm1 = b(1)m2 = b(1)Call mm(m1, m2, b())PrintPrint "最大值为:"; m1Print "最小值为:"; m2Next iEnd SubPublic Sub mm(max%, min%, a() As Integer) Dim i%For i = LBound(a) To UBound(a)If a(i) > max Then max = a(i)If a(i) < min Then min = a(i)Next iEnd Sub2.sub过程:Public Sub jc(n%, s&)Dim i%s = 1For i = 1 To ns = s * iNext iEnd SubPrivate Sub Form_click()Dim s&, a%, b%, c%, s1&a = Val(InputBox("请输入一个整数:"))b = Val(InputBox("请输入一个整数:"))c = Val(InputBox("请输入一个整数:")) Call jc(a, s1)s = s1 + sCall jc(b, s1)s = s1 + sCall jc(c, s1)s = s1 + sPrint a & "!+" & b & "!+" & c & "!=" & s End SubFunction过程:Public Function jc(n%) As LongDim i%, s%s = 1For i = 1 To ns = s * iNext ijc = sEnd FunctionPrivate Sub Form_click()Dim s&, a%, b%, c%, s1&a = Val(InputBox("请输入一个整数:"))b = Val(InputBox("请输入一个整数:"))c = Val(InputBox("请输入一个整数:"))s1 = jc(a) + jc(b) + jc(c)Print a & "!+" & b & "!+" & c & "!=" & s1 End Sub3.Public Sub jo(n As Integer)If n Mod 2 = 0 ThenPrint "false"ElsePrint "true"End IfEnd Sub4.Private Sub Form_click()Dim b(1 To 100) As Integer, i%For i = 1 To 100b(i) = Int(Rnd * 100 + 1)Next iCall sort(b())For i = 1 To 100If i Mod 10 = 0 Then PrintPrint b(i);Next iEnd SubPublic Sub sort(a() As Integer)Dim n%, ok As Boolean, k As Integern = UBound(a)For i = 1 To n - 1ok = TrueFor j = 1 To n - iIf a(j) > a(j + 1) Thenk = a(j): a(j) = a(j + 1): a(j + 1) = k: ok = False End IfNext jIf ok Then Exit ForNext iEnd Sub5.Private Sub Form_click()Dim b(1 To 10) As Integer, i%For i = 1 To 10b(i) = Val(InputBox("请输入第" & i & "个整数")) Next iCall sort(b())Print "排序后的结果"For i = 1 To 10Print b(i);Next iEnd SubPublic Sub sort(a() As Integer)Dim n%, p%, k As Integern = UBound(a)For i = 1 To n - 1p = iFor j = i + 1 To nIf a(j) < a(p) Then p = jNext jIf p <> i ThenMin = a(i)a(i) = a(p)a(p) = MinEnd IfNext iEnd Sub6.Public Sub gys(m%, n%)Dim r%, t%If m <> 0 And n <> 0 ThenIf m < n Thent = m: m = n: n = tEnd Ifr = m Mod nDo While r <> 0m = nn = rr = m Mod nLoopEnd IfEnd Sub7.Public Sub ws(n%, s%)Dim k%, i%For i = 1 To n - 1If n Mod i = 0 Then s = s + iNext iEnd SubPrivate Sub Form_click()Dim m%, sum%, c$For m = 1 To 999sum = 0Call ws(m, sum)If sum = m Then c = c & sum & " " Next mMsgBox cEnd Sub8.Public Function ef(a(), k%, wz%) As Integer Dim i%, low%, mid%, top%low = LBound(a)top = UBound(a)Do While low <= topmid = (low + top) / 2If k > a(mid) Thenlow = mid + 1ElseIf k = a(mid) Thenwz = midExit FunctionElsetop = mid - 1End IfLoopwz = -1End Function9.Function MaxGY(x As Integer, y As Integer) Dim Temp As IntegerTemp = x Mod yIf Temp = 0 ThenMaxGY = yElseMaxGY = MaxGY(y, Temp)End IfEnd FunctionPrivate Sub Form_click()Dim m%, n%m = Val(InputBox("请输入第一个整数:"))n = Val(InputBox("请输入第二个整数:")) Print "最大公约数是:"; MaxGY(m, n)End Sub10. Function Ss(n%)If n = 1 ThenSs = 10ElseSs = Ss(n - 1) + 2End IfEnd FunctionPrivate Sub Form_click()Dim r%, x%r = 5x = Ss(5)Print "第5个小孩的岁数为:"; xEnd Sub第七章应用程序界面设计一、选择题BCDCA CDBBD CADAA CADBD DAAAB CAA二、填空题1.form1.show unload form12.form2.show form1.hide3.属性方法事件4、工程属性工程属性5.子窗体主窗体6、keypress list(i) additem7.0 list1.listindex list1.listcount-18、1000 true time() 9、AA10、下拉式组合框、简单组合框和下拉式列表框第八章VB图形操作一、选择题DCCDA CDAAA BABBC CAAA二、填空题1、不会也不会 2.、Scaleheight Scalewidth3、(300,-150)4、右上5、twip6、0~157、B 8、-2π~09、逆10、drawwidth11、右上12、move13、cls 14、坐标原点、坐标度量单位、坐标轴的长度与方向15、VB程序设计vbprogramming三、编程题1、Private Sub Command1_Click()Const pi = 3.14159P1.Circle (Val(Text1), Val(Text2)), Val(Text3)End SubPrivate Sub Command2_Click()P1.ClsText1 = ""Text2 = ""Text3 = ""End Sub2、Private Sub Form_Load()Pic1.Picture = LoadPicture("F:\VB程序设计\上课课件\tea.jpg")End SubPrivate Sub Pic1_Click()Pic2.Picture = Pic1.PicturePic1.Picture = LoadPicture("")End Sub3、Dim a1!, b1!Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) a1 = Xb1 = YEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Circle (a1, b1), Sqr((a1 - X) ^ 2 + (b1 - Y) ^ 2)End Sub4、Dim a1!, b1!Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Thena1 = Xb1 = YEnd IfEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 ThenLine (a1, b1)-(X, Y), vbGreen, BFEnd IfEnd Sub5、Private Sub Form_Click()Scale (-200, 200)-(200, -200)Dim i!For i = 0 To 140 Step 20Line (-i - 10, i + 10)-(i + 10, -i - 10), , BNext iEnd Sub第9章vb文件操作一、选择题BDDCC BBAAB二、填空题1、驱动器列表框、目录列表框和文件列表框2、change 3\file1.path=dir1.path4、name “D:\old.doc” as “c:\new.doc”5、dir1.path=drive1.drive file1.path=dir1.path6、filecopy “d:\text.doc”,”e:\text.doc”7、eof 8、input not eof(1)9、for inputFor outputnot eof(1)str1Close #110、pattern 11、空12、字节。
第1章认识Access2003一、选择题1. C2. B3. C4. A5. D6. B7. A二、填空题1. Office2003办公软件,数据库管理2. 标题栏,菜单栏,工具栏,工作区,状态栏,任务窗格3. 一条记录,一个字段4. 一对一,一对多,多对多5. 查看,分析,更改数据,数据来源6. 打印输出7. Internet三、判断题1.× 2.√ 3.× 4.√ 5.√6.× 7.× 8.√ 9.× 10.√四、简答题1.启动Access2003的方法有3种:通过“开始”菜单启动;通过桌面快捷方式启动;通过“开始”菜单中的Access2003选项启动。
2.退出Access2003的方法有5种:单击主窗口的“关闭”按钮;在菜单栏中选择“文件→退出”命令;双击控制菜单图标;单击控制菜单图标,在弹出的下拉菜单中单击“关闭”命令;直接按Alt+F4键。
3.使用Access2003的帮助系统主要有3种方法:使用“帮助”任务窗格;使用“Office 助手”;使用上下文帮助。
4. Access2003数据库的对象包括表、查询、窗体、报表、数据页、宏和模块7种。
5.通过阅读“罗斯文”示例数据库可以帮助用户理解Access数据库的相关概念,掌握Access2003的相关操作。
第2章数据库和表的创建一、选择题1.D 2.C 3.D 4.C 5.D 6.B 7.B二、填空题1.数据库2.设计,数据表3. OLE对象4.是/否5.主键6. 0000三、判断题1.√ 2.× 3.√ 4.× 5.×6.√ 7.× 8.√ 9.× 10.√四、简答题1.创建数据库有三种方法:使用空数据库、使用“本机上的模板”和利用“Office Online 模板”创建数据库;创建表有三种方法:使用“向导”、使用“通过输入数据创建表”和使用“表设计器”。
第6章习题参考答案一、判断题题号 1 2 3 4 5 6答案√√×√√×二、选择题题号 1 2 3 4 5答案 D C A D B三、程序填空题1.(1)nsp=true(2) m mod i=0(3) p1 and p2(4) p1=nsp(i)2.(1)number(i,7)(2) (int n, int m)(3) number=number*10+m四、程序阅读1. a=9 b=42.(1) 362516941(2)1499413.64. 1 4 6五、编写程序1.Public Function fact(x As Integer) As Single '求x!Dim f As Single, i As Integerf = 1For i = 1 To xf = f * i '累积Next ifact = fEnd FunctionPrivate Sub Form_Click()Dim n%, m%, y!Dom% = Val(InputBox("m="))n% = Val(InputBox("n="))Loop Until m >= n And n >= 0y = fact(m) / (fact(n) * fact(m - n))Print yEnd Sub2 private sub Insertfun(a%(), y%)Dim i as integer,n as integern=ubound(a)Redim preserve a(n+1)For i=ubound(a)-1 to 0 step -1If y <a(i) thena(i+1)=a(i)If i=0 then a(i)=yElsea(i+1)=yexit forend ifnext i3. '判断是否为回文函数Private Function Judge(str As String) As BooleanDim i As IntegerJudge = True '假设为回文For i = 1 To Len(str) \ 2 '依次判断对应位置的两个字符,只要有一组不等即不是回文If Mid(str, i, 1) <> Mid(str, Len(str) + 1 - i, 1) ThenJudge = FalseExit FunctionEnd IfNext iEnd Function4.Private Sub Form_Click()Dim n%,x!n = Val(InputBox("n="))x = Val(InputBox("x="))Print fe(n, x) '调用求值函数过程End Sub'求值函数过程Public Function fe(n%, x!) As SingleDim i As Integer, t As Singlefe = 1: t = 1For i = 1 To nt = t * x / i 't为通项fe = fe + tNext iEnd Function5.。
课后习题参考答案第1章Visual Basic 6.0一、判断题1--5:√×√×√6――10:××√×√11――13:√××二、选择题1――5:ADBBB 6――10:.CACDB三、填空题1、图片框和框架2、对象3、控件屏幕4、Load5、Load Activate四、程序设计题1、Private Sub Command1_Click()Print Text1.TextEnd SubPrivate Sub Command2_Click()EndEnd Sub2、Private Sub Command1_Click()Form1.FontSize = Form1.FontSize + 3Print "青春无悔"End SubPrivate Sub Command2_Click()FontSize = FontSize - 3Print "青春无悔"End SubPrivate Sub Command3_Click()Form1.FontBold = TruePrint "青春无悔"End SubPrivate Sub Command4_Click()FontBold = FalsePrint "青春无悔"End Sub3、Private Sub Command1_Click()Text1.Visible = FalseEnd SubPrivate Sub Command2_Click()Text1.Visible = TrueText1.FontName = "楷体_gb2312"Text1.FontSize = 15Text1.Text = "我学会了创建一个应用程序了!"End Sub第二章判断题:1~5错错错错错第3章顺序结构程序设计一、思考题略二、程序阅读题1.A=2 B=1 C=22.123.BABCBACBC4. 1 2 False5.1-12-123-1234-三、选择题1.B2.D3.B4.B5.D6.C四、程序设计题1.Private sub form_click()Dim r!,s!R=val(inputbox(“r=”))S=3.14159*r*rPrint “s=”;sEnd sub2.Private sub form_click() Dim x as singleX=val(inputbox(“x=”))Print fix(x*x*1000)/1000,fix(sqr(x)*1000)/1000End sub第4章选择结构程序设计一、判断题1.错2.错3.错4.错5.对二、选择题1.A 2. D 3.A 4.B 5.A 6.A三、程序阅读题1.X=3 y=72.w=4w=13w=135w=313.X_`a12 Uvw&4.12 9四、程序填空题1.(1) chr(keyascii) (2) chr(keyascii)=”)” (3)count1=count1-1 (4)count1=0 (5)count1>02.(1) max (2)min (3)c>max (4)c<min3.(1)x mod 3=2 and x mod 5=3 and x mod 7=4 then(2)text1.setfocus (3) text1.selstrat=0 (4)text1.sellength=len(text1.text)五、1.Private Sub Command1_Click()Dim y As Integery = Val(InputBox("y="))If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Print "是闰年"ElsePrint "不是闰年"End IfEnd SubPrivate Sub Command1_Click()Dim y As Integer,y1 as stringy = Val(InputBox("y="))If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Y1= "是闰年"ElseY1= "不是闰年"End If? y,y1End SubPrivate Sub Command1_Click()Dim y As Integer,y1 as stringy = Val(InputBox("y="))Y1= "不是闰年"If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Y1= "是闰年"End If? y,y1End Sub2.Private Sub Command1_Click()Dim a%, b%, c%, x!,s!a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c="))If a + b > c And a + c > b And b + c > a Thenx = (a + b + c) / 2s = Sqr(x * (x - a) * (x - b) * (x - c))Print "s="; sElsePrint "不是三角形,重输a,b,c"End IfEnd SubPrivate Sub Command1_Click()Dim a%, b%, c%, x!,s!,t%a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c=")) ‘a,b,c=3,4,5t=0If a + b > c And a + c > b And b + c > a Thenx = (a + b + c) / 2s = Sqr(x * (x - a) * (x - b) * (x - c))t=1End IfIf t=0 then“不是“endifEnd Sub3.Private Sub Command1_Click()Dim x!, y!x = Val(InputBox("x="))y = x * x - x – xIf x < 0 And x <> -3 Theny = x * x + x - 6ElseIf 0 <= x And x < 10 And x <> 2 And x <> 3 Then y = x * x - 5 * x + 6End IfPrint "x="; x, "y="; yEnd SubPrivate Sub Command1_Click()Dim x!, y!x = Val(InputBox("x="))If x < 0 And x <> -3 Theny = x * x + x – 6elseIf 0 <= x And x < 10 And x <> 2 And x <> 3 Theny = x * x - 5 * x + 6elsey=x^2-x-1End IfPrint "x="; x, "y="; yEnd SubPrivate sub form_click()Dim y%,z%,dj%,p!,t!Y=val(inputbox(“月”))Z= val(inputbox(“订票数”))Dj= val(inputbox(“票价”))Select case ycase 7,8,9If z>=20 then p=0.15 else p=0.05case 1 to 5,10,11If z>20 then p=0.3 else p=0.2Case elseP=0.2End selectT=z*dj*p? tend sub5.private sub form_click()dim m1%,m2%,m3%,dj$m1=val(inputbox(“m1=”)): m2=val(inputbox(“m2=”)): m3=val(inputbox(“m3=”))if (m1+m2+m3)/3>=95 or ( a=100 and b=100 and c>=80) or ( a=100 and c=100 and b>=80) or ( c=100and b=100 and a>=80) thendj=”一等”elseif (m1+m2+m3)/3>=90 or ( a=100 and b>=75 and c>=75) or ( b=100 and a>=75 and c>=75) or ( c=100 and b>=75 and a>=75) thendj=”二等”elseif a>=75 and b>=75 and c>=75 then dj=”三等” else dj=”没有” endif ? “dj=”;dj end sub第5章 循环结构程序设计1.判断题×√√√××√×2.选择题BBBBCC 3.填空题(1)7(2)Do/Loop For/Next While/Wend (3)-364.程序阅读题(1) (2)(3)4 (4)5.程序填空题(1)①sign=1 ②For i=2 to 19(2)①Len(str1) ②length-1 ③Mid(str1,i,2) ④Sum=0(3)①I mod 7=5 and i Mod 5 = 3 And i Mod 3=2 ②i<1000(4)①last_one = last_two ②last_two = this_one ③i=i+1 ④i-2(5)①I>int(sqr(m)) ②Int(Sqr(n-m))6.编程题(1)Private Sub Form_Click()Dim i As Integer, j As IntegerDim s As Double, Sum As Doubles = 188688646886424688642 1 2 3 4Sum=10# # # # # ## # # # ## # # ## # ## ##For i = 1 To 11 Step 2For j = 1 To is = s * jNext jSum = Sum + sNext iPrint SumEnd Sub(2)Private Sub Form_Click()Dim m%, n%, mn%, r%, t%m = Val(InputBox("m="))n = Val(InputBox("n="))If n <= 0 Or m <= 0 ThenMsgBox "数据有误"EndEnd Ifmn = m * nIf m < n Thent = m: m = n: n = tEnd IfDo While (n <> 0)r = m Mod n: m = n: n = rLoopForm1.Print "最大公约数="; mForm1.Print "最小公倍数="; mn / m End Sub(3)Private Sub Form_Click()Dim i%, j%For i = 1 To 5Print Spc(20 - i);For j = 1 To 2 * i - 1Print Trim(Str(i));Next jPrintNext iFor i = 4 To 1 Step -1Print Spc(20 - i);For j = 1 To 2 * i - 1Print Trim(Str(10 - i));PrintNext iEnd Sub(4)Private Sub Form_Click()Dim x As IntegerDim y As IntegerDim z As IntegerFor x = 0 To 100For y = 0 To 100 - xz = 100 - x - yIf 5 * x + 3 * y + z / 3 = 100 Then Print x, y, zNext yNext xEnd Sub(5)Private Sub Form_Click()Dim x As Single, y As Single, a As Single, i As Integerx = Val(InputBox("输入x:"))a = 1: y = a: i = 0While a >= 0.00001i = i + 1: a = a * x / i: y = y + aWendPrint "y="; yEnd Sub第六章答案一、判断题1.错2.错3.错4.错(可以为小数,不过仍然是当作整数来处理)5.错6.错二、选择题1.C2.C3.A4.D三、程序填空1.(1)N-1 (2)T = A(J): A(J) = A(J + 1): A(J + 1) = T(3)Print A(I)2.(1)a(i, j) = 1(2)Print四、程序阅读1.52.1 2 3 41 2 3 41 2 3 41 2 3 41 1 1 12 2 2 23 3 3 34 4 4 43.(前面空4个空格)1 12 11 102 13 16 93 14 15 84 5 6 7第7章过程判断题:1、对2、错3、错4、错5、对6、对7、错选择题:1.B 2、D 3、D 4、C 5、A程序阅读题:1、y=5 a=52、n=1z=4y=15 a=10n=2z=7y=30 a=15n=3z=103、32 644、2 2 216648644645、A1=10 B1=20A2=20 B2=10程序填空题:1、(1)hwstring(str) (2)"" (3)As Boolean(4)n=len(strtxt) (5) True (6)False2.(1)Xsch(Nman,Nkcen) (2)n(3)sum=sum+x(i,j) (4)tt/n (5)x(i,m+1)<1.2*ver and x(i,m+1)>=1.1*ver 3.(1)number(i)(2)Byval n as Integer (3)number= number+7*10^ (i-1)4.(1)temp=1 (2)temp (3)nFactor( i ) (4)sum 程序设计题:1、具体程序为:Function Maxnum(ByRef a() As Integer, ByVal n As Integer) As IntegerDim i As IntegerMaxnum = a(1)For i = 2 To nIf a(i) > Maxnum Then Maxnum = a(i)Next iEnd FunctionFunction Avenu(ByRef a() As Integer, ByVal n As Integer) As SingleDim i As Integer, sum As IntegerFor i = 1 To nsum = sum + a(i)Next iAvenu = sum / nEnd FunctionSub Sortrnum(ByRef a() As Integer, ByVal n As Integer)Dim i As Integer, j As Integer, k As IntegerDim temp As IntegerFor i = 1 To nk = iFor j = i + 1 To nIf a(k) > a(j) Then k = jNext jIf i <> k Thentemp = a(i)a(i) = a(k)a(k) = tempEnd IfNext iEnd SubPrivate Sub Form_Click()Dim b(10) As Integer, i As IntegerFor i = 1 To 10b(i) = InputBox("请输入整数", "输入")Next iCall Sortrnum(b(), 10)Print "从小到大排序为:"For i = 1 To 10Print b(i);NextPrintPrint "最大数为:"; Maxnum(b(), 10)Print "平均数为:"; Avenu(b(), 10)End Sub2、具体程序为:Function fe(n%, x!) As SingleDim temp As Single, i As Integerfe = 1temp = 1For i = 1 To ntemp = temp * x / ife = fe + tempNext iEnd FunctionPrivate Sub Form_Click()Dim n As Integer, x As Singlen = Val(InputBox("请输入n", "输入"))x = Val(InputBox("请输入x", "输入"))Print "e的值为:"; fe(n, x)End Sub3、具体程序为:Sub sort(a() As Single, n As Integer)Dim i As Integer, j As Integer, k As Integer Dim temp As SingleFor i = 1 To nk = iFor j = i + 1 To nIf a(k) < a(j) Then k = jNext jIf i <> k Thentemp = a(i)a(i) = a(k)a(k) = tempEnd IfNext iEnd SubPrivate Sub Form_Click()Dim a(10) As Single, i As IntegerFor i = 1 To 10a(i) = Val(InputBox("请输入数据", "输入")) Next iCall sort(a(), 10)Print "从大到小为:"For i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext iEnd Sub第8章常用控件参考答案:一、判断题1、×2、×3、√4、√5、×6、×7、×8、×9、× 10、×11、× 12、√ 13、× 14、√ 15、√二、单选题1、A2、B3、A4、C5、B6、D7、A8、B9、C 10、C11、A 12、A 13、C 14、B 15、A三、填空题1、Autosize WordWrap2、Enabled Visible3、文本框和列表框4、拖动滚动框5、Change6、Command1.Setfocus7、Timer8、MaxLength 9、AddItem 10、定时器屏蔽12345.五、程序填空题1、(1) Label1.left (2) –Label1.Width2、(1) List1.ListIndex<0 (或者List1.ListIndex = -1)(2) List1.RemoveItem List1.ListIndex(3) Text1.Text=”” (4) List1.AddItem Text1.Text3、(1) 1 to 2*I-1 (2) Command2.Enabled=True(3) Command2.Enabled=False4、(1) ndec<>0 (2) ndec mod 16 (3) ai=ndec(4) end (5) ai & shex (6)shex5、(1) Timer1.Enabled=True (2) x \ 3600 (3) (x-h*3600)\60(4) x=x+16、(1) m<len(str1)/2 (2) mid (str1,m+1,1) (3)mid (str1,len(str1)-m,1)六、程序设计题1、P rivate Sub Command1_Click()If Text1.Text = "" ThenMsgBox "请先输入添加项"ElseList1.AddItem Text1.TextEnd IfEnd SubPrivate Sub Command2_Click()If List1.ListIndex < 0 Then ‘或者if list1.listindex=-1 then MsgBox "请选择一删除项"ElseList1.RemoveItem List1.ListIndexEnd IfEnd SubPrivate Sub Command3_Click()If List1.ListIndex < 0 ThenMsgBox "请选择一修改项"ElseText1.Text = List1.TextEnd IfCommand4.Enabled = TrueEnd SubPrivate Sub Command4_Click()Dim a As IntegerIf List1.Text = Text1.Text ThenMsgBox "请先修改此项"Elsea = List1.ListIndexList1.RemoveItem List1.ListIndexList1.AddItem Text1.Text, aEnd IfEnd SubPrivate Sub Form_Load()Command4.Enabled = FalseEnd Sub2、D im a As IntegerPrivate Sub Command1_Click()a = Int(Rnd * 100) + 1End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Static i As IntegerIf KeyAscii = 13 ThenIf Val(Text1.Text) > a ThenLabel1.Caption = "太大了,请重输"i = i + 1ElseIf Val(Text1.Text) = a ThenLabel1.Caption = "恭喜你,你答对了!"i = 0Command1_ClickElseLabel1.Caption = "太小了,请重输!"i = i + 1End IfIf i > 10 ThenMsgBox "你失败了!"EndEnd IfEnd IfEnd Sub3、Private Sub Command1_Click()Dim n As Integer: n = Len(Text1.Text)Dim s(1 To 1000) As String, i As Integer, j As Integer, t AsString, a As StringFor i = 1 To ns(i) = Mid(Trim(Text1.Text), i, 1)Next iFor i = 1 To n - 1For j = i + 1 To nIf s(i) > s(j) Thent = s(i): s(i) = s(j): s(j) = tEnd IfNext j, iFor i = 1 To n: a = a + s(i): Next iPrint aCommand1.Enabled = False: Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click(): End: End SubPrivate Sub Form_Load()Text1.MaxLength = 200Command2.Enabled = False: Command1.Enabled = TrueEnd Sub4、Dim a(1 To 1000) As String, b(1 To 1000) As String, c(1 To 1000) As Double, d(1 To 1000) As DoublePrivate Sub Combo1_click()Text1.Text = a(Combo1.ListIndex + 1)Text2.Text = b(Combo1.ListIndex + 1)Text3.Text = c(Combo1.ListIndex + 1)Text4.Text = d(Combo1.ListIndex + 1)End SubPrivate Sub Command1_Click()Combo1.AddItem Text1.Texta(Combo1.ListCount) = Text1.Textb(Combo1.ListCount) = Text2.Textc(Combo1.ListCount) = Val(Text3.Text)d(Combo1.ListCount) = Val(Text4.Text)End SubPrivate Sub Command2_Click()For i = Combo1.ListIndex + 1 To Combo1.ListCount - 1a(i) = a(i + 1)b(i) = b(i + 1)c(i) = c(i + 1)d(i) = d(i + 1)Next ia(i) = ""b(i) = ""c(i) = 0d(i) = 0Combo1.RemoveItem Combo1.ListIndexText1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Form_Load()Dim i As IntegerCombo1.AddItem "张三"Combo1.AddItem "李四"Combo1.AddItem "王五"a(1) = "张三": a(2) = "李四": a(3) = "王五"b(1) = "浙江林学院": b(2) = "浙江工业大学": b(3) = "浙江大学"c(1) = 311300: c(2) = 310027: c(3) = 310014d(1) = 63742212: d(2) = 88394277: d(3) = 88326531End Sub5、Private Sub Check1_Click()If Check1.Value = 1 ThenLabel1.FontBold = TrueElseLabel1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check1.Value = 1 ThenLabel1.FontItalic = TrueElseLabel1.FontItalic = FalseEnd IfEnd SubPrivate Sub Option1_Click()Label1.FontName = "宋体"End SubPrivate Sub Option2_Click()Label1.FontName = "楷体_gb2312"End Sub6、Private Sub Command1_Click()Dim a As String, i As Integer, n As IntegerDim s As Integer, q As Integer, l As Integern = Len(Text1.Text)For i = 1 To na = Mid(Text1.Text, i, 1)If a >= "a" And a <= "z" Thens = s + 1 '大写个数ElseIf a >= "A" And a <= "Z" Thenq = q + 1 '小写个数ElseIf a >= "0" And a <= "9" Thenl = l + 1End IfNext iText2.Text = sText3.Text = qText4.Text = lEnd SubPrivate Sub Form_Load()Text1.SetFocusEnd Sub7、Private Sub Form_Click()Dim i As Integer, j As Integer, t As IntegerFor i = 0 To List1.ListCount - 1List3.AddItem List1.List(i)Next iList1.ClearDo While List2.ListCountList3.AddItem List2.List(0)List2.RemoveItem 0LoopFor i = 0 To List3.ListCount - 2For j = i + 1 To List3.ListCount - 1If List3.List(i) > List3.List(j) Thent = List3.List(i): List3.List(i) = List3.List(j): List3.List(j) = tEnd IfNext j, iEnd SubPrivate Sub Form_Load()Dim i As Integer, n As Integern = InputBox("")For i = 1 To nList1.AddItem Int(Rnd * 90) + 10List2.AddItem Int(Rnd * 90) + 10Next iEnd Sub第9章对话框和菜单1.判断题:×√√(题中应把flag改为flags)√√××√√× ××√××2.选择题:DDCCD BDCCB3.填空题1.-2.一级子菜单3.将顶级菜单设置为不可见4.popupmenu pmenu,0,x,y5.showfont6.工程、部件7.click8.代码窗口,click9.下拉式,弹出式打开/另存为、颜色,字体、打印、帮助4. 程序阅读题打开对话框2、*.txt3、allfiles*.exe*.txt*.doc4、Checking,No File Selectd,重试(R),取消5. 程序填空题“c:\winnt”commondialog1.showopen,loadpicture(commondialog1.filename)6. 程序设计题1、界面如图:代码如下:Private Sub Command1_Click()CommonDialog1.FileName = ""CommonDialog1.Flags = 4096CommonDialog1.Action = 1If CommonDialog1.FileName = "" ThenMsgBox "No File Selectd", 5 + vbExclamation, "Checking"ElseList1.AddItem CommonDialog1.FileNameEnd IfEnd Sub2、代码如下:Private Sub a_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub b_Click()CommonDialog1.Flags = 1CommonDialog1.ShowFontText1.FontSize = CommonDialog1.FontSizeEnd SubPrivate Sub c_Click()CommonDialog1.Flags = 1CommonDialog1.ShowFontText1.FontName = CommonDialog1.FontNameEnd SubPrivate Sub d_Click()EndEnd Sub第10章 图形操作和图形控件一、判断题×√×××√×√××二、选择题BAADACAA三、填空题(1)pic1.Circle (pic1.ScaleLeft + pic1.ScaleWidth / 2, pic1.ScaleTop + pic1.ScaleHeight / 2), 700(2)在图片框picture1中,以(800,1000)为圆心画一个半径为500的圆(3)Form1.Scale (-200, 250)-(300, -100)(4)Autosize stretch四、程序阅读题1、窗体宽和高的1/4为起点,画一个边长为1000的正方形,并画出其正向对角线2、在图片框中交替画出实心和空心的矩形,空心矩形是黄色边框。
一、实验目的
1、通过实验理解过程的基本概念。
2、创建过程的作用、方法和过程调用方法。
3、理解sub过程和function过程的异同。
4、理解过程调用时的参数传递的两种方式及特点。
5、理解过程、变量的作用域。
6、具备使用过程编写能力。
7、理解递归的概念及编程方法和特点。
二、实验内容
1
2
3
4
5
6
7
8
例6-1 求组合数m n C =
)!
(!!
m n m n 的值,设m=6,n=10
例6-2
一个整型数组有10个元素,将第一个元素与最后一个元素对调,第
二个与倒数第二个对调,……,输出对调前后数组各元素的值。
例6-5
编写求一组整数平均值的过程,并在主程序中调用。
例6-8
窗体级变量的作用范围示例。
例6-11
判断一个数是否为回文数。
所谓回文数就是这样的数,将这个数从左
到右读和从右到左读的值相同。
例6-12
设计一个数值转换函数,能够将十进制数转化为十六进制以内的任意进制数。
课后题
第一题:自定义一个与vb内部函数abs功能完全相同的函数过程myabs,要求函数过程中不能调用vb内部函数abs。
第二题:编写一个求4个数中最大值max和最小值min的过程,并在程序中调用。
第三题:设a为一整数,如果2a的低位与a相同,则称为守行数。
编写一个过程判断正整数形参是否为守行数,然后再主程序调用查询
1-2000内的所有守行数。
第四题:编写函数过程gdc求两个数的最大公约数。
调用此程序试求1260,198,72的最大公约数。
第五题:编写产生随机函数过程,输出n个指定区间的随即整数,并在主程序中调用。
第六题:编写过程求方阵两个对角线元素之和,并在主程序中调用。
第七题:编写判断一个整数是否为素数的过程,并调用该过程输出100-200之间的所有素数。
第九题:编写过程实现将两个按照升序排列的数组合成另一个按降序排列的数组,并在主程序中调用。
第十题:有一个数列前两项为1,从第三项开始,每一项均为前两项之和,求这个数列的第二十项。
第十一题:编写一个程序,用来计算下列表达式的值,并在主程序中调用。
三、实验总结
1、本次试验我们的主要目的是学习两个过程,包括sub和function
过程,可以说这次的实验是这学期实验中最重要的,是学习过程中的难点,因此我们必须要认真对待。
2、在编写程序的时候,是选用sub过程还是用function过程,这
是很多同学很难抉择的难题。
一般情况下,如果不需要返回过程处理结果,或者需要返回多个处理结果,则选用sub过程;
如果需要返回的运算结果只有一个,则选用function过程则比较简单。
3、过程调用中的参数传递包括:按地址传递和按值传递,我们需
要根据自己的需要选择合适的参数传递方式。
需要注意的是,在调用过程,与形参对应位置的实参必须是相同类型的变量和数组,否则会出现错误。