vb课本答案

合集下载

VB课后练习答案.doc

VB课后练习答案.doc

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属性判断是否选中该项。

VB教材习题_参考答案

VB教材习题_参考答案

Visual Basic程序设计教程(李杰主编清华大学出版社 2011.2)习题答案习题2参考答案2.2 单选题1、B2、C3、A4、D5、A6、B7、D8、C9、B 10、D2.3 填空题1、事件驱动2、Cancel3、Name4、Private Sub Form1_Click()5、运行程序6、代码窗口7、Text1.Text = "我是一个学生"8、LostFocus()事件9、Label1.Caption = "请输入用户名"Label1.ForeColor = vbGreen10、(Text1.Text)*22.4 事件练习题1、①该事件的对象是标签Label1,单击标签触发该事件。

②缺省Label1对象的代码是针对窗体,其余有Label1对象的代码是针对标签的。

③Label1.AutoSize = True语句使标签的大小自动随文字的多少而改变。

2、程序运行后,单击命令按钮,在Text1文本框显示"知音海外版",在Text2文本框显示"计算机世界"。

3、单击“显示文本框”命令按钮触发的事件过程Private Sub Command1_Click()Text1.V isible = TrueText1.ForeColor = vbRedText1.Text = "VB程序设计"End Sub单击“隐藏文本框”命令按钮触发的事件过程Private Sub Command2_Click()Text1.V isible = FalseEnd Sub习题3参考答案3.2 单选题1 C2 C3 D4 B5 B6 B7 B8 C9 D3.3填空题1.REM(或‘) _ :2 双引号(“”)#3 $ %4 UCASE()5.(log(1+d*d)-exp(2))^(5/2) [ 还有一种理解方式:(log(1+d*d)-e*e)^(5/2)]6. &O113 &H4B习题4参考答案4.2 单选题BDCBD4.3 填空题1.MsgBox("是否删除? ", vbOkCancel + vbQuestion, "删除")2.The Length of 12345=53. 变量或表达式4. 15. loop4.4 程序设计题1.Private Sub Command1_Click()If Text1.Text = "asdf" ThenMsgBox "密码正确!"ElseMsgBox "密码错误", vbRetryCancel, "错误"End IfEnd Sub2. < 题目中的“连续产生n*n个字母”应该改为“连续产生n个字母”> Private Sub Command1_Click()Dim n%, y%, i%n = V al(Text1.Text)If n > 10 Or n<=0 ThenMsgBox "数据超界!"Text1.Text=””Text1.SetFocusElsey = Int((90 - 65 + 1) * Rnd) + 65For i = 1 To nPrint Chr(y + i)Next iEnd IfEnd Sub3.Private Sub Form_Click()Dim a!, b!, c!, x1!, x21, d!a = V al(Text1.Text)b = V al(Text2.Text)c = V al(Text3.Text)d = b * b - 4 * a * cIf d >= 0 Thenx1 = (-b + Sqr(d)) / (2 * a)X2 = (-b - Sqr(d)) / (2 * a)Print x1; X2ElsePrint "没有实根"End IfEnd Sub4.Private Sub Form_Click()Dim i%, j%, s%, n%,q%n = InputBox("enter n:")q = 0For i = 1 To ns = 0For j = 1 To is = s + jNext jq = q + sNext iPrint qEnd Sub5.Private Sub Form_Click()Dim i%, j%, n%, k%n = 0For i = 1 To 3For j = 1 To 3For k = 1 To 3Print i & j & k,n = n + 1If n Mod 5 = 0 Then PrintNext kNext jNext iPrintPrint "n="; nEnd Sub6.Private Sub Form_Click()Dim i%, j%, n%, k%For i = 1 To 9For j = 0 To 9For k = 0 To 9n = i * 100 + j * 10 + kIf n = i ^ 3 + j ^ 3 + k ^ 3 Then Print n,Next kNext jNext iEnd Sub习题5参考答案5.2 单选题1 A2 B3 C4 C5 D6 D7 A8 C9 D 10 A 11 A 12 B 5.3 填空题1.False2.Caption3.0 ListCount-14.Print List1.List(3)5.Combo1.ReMoveItem 36.LargeChange7.Timer8.5009.Shape10.Borderstyle5.4 程序设计题1.Dim op1, op2, result As SingleDim operator As IntegerPrivate Sub Command1_Click(Index As Integer)If Index >= 0 And Index <= 10 ThenIf txt1.Text = "" Thentxt1.Text = CStr(Index + 1)Elsetxt1.Text = txt1.Text + CStr(Index + 1) End IfEnd IfIf Index >= 12 And Index <= 15 Thenop1 = CDbl(txt1.Text)operator = Indextxt1.Text = ""End IfIf Index = 11 Thenop2 = CDbl(txt1.Text)Select Case operatorCase 12result = op1 + op2Case 13result = op1 - op2Case 14result = op1 * op2Case 15result = op1 / op2End Selecttxt1.Text = CStr(result)End IfEnd SubPrivate Sub Command2_Click()op1 = 0op2 = 0result = 0txt1.Text = ""End SubPrivate Sub Command3_Click()EndEnd Sub2.Private Sub chkBold_Click()If chkBold.Value = vbChecked ThenTxt1.FontBold = TrueElseTxt1.FontBold = FalseEnd IfEnd SubPrivate Sub chkUnderline_Click()If chkUnderline.Value = vbChecked Then Txt1.FontUnderline = TrueElseTxt1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Opt18_Click()Txt1.FontSize = 18End SubPrivate Sub Opt22_Click()Txt1.FontSize = 22End Sub3.Private Sub Form_Load()List1.AddItem "上海"List1.AddItem "北京"List1.AddItem "天津"List1.AddItem "广东"List1.AddItem "辽宁"List1.AddItem "陕西"List1.AddItem "河南"List1.AddItem "深圳"List1.AddItem "四川"List1.AddItem "重庆"End SubPrivate Sub List1_DblClick()For i = 0 To 9If List1.ListIndex = i ThenList2.AddItem List1.List(i)List1.RemoveItem iEnd IfNext iEnd Sub4.Private Sub Command1_Click()Timer1.Enabled=TrueTimer1.Tag=Text1.Text*60Frame1.Caption=“现在开始倒计时”End SubPrivate Sub Timer1_ Timer()Timer1.Tag=Timer1.Tag-1If m<0 ThenTimer1.Enabler=FalseMsgBox“预定的时间到了!”,0,“倒计时”Frame1.Caption=“请输入计时的分钟数:”Text1.Text=0Exit SubEnd Ifn1=Format(m Mod 60,“00”)n2=Format(m \ 60)Mod 60,“00:”)n3=Format(m \ 3600),“00:”)Text1.Text=n3&n2&n1End Sub习题6参考答案6.1单选题1.C2.C3.B4.B5.B6.D7.B8.B9.A10.A6.2 填空题1.Option Base 12.变体类型3.preserve (注意:教材上面写成perserve, 教材错误)4.V ariant变体类型5.96.相同,索引号7.1).通过复制粘贴的方式创建控件数组2).在设计时候添加多个同类型的类型控件,然后通过“属性”窗口将这些控件的名称改为相同,并把Index属性设为不同的下标值。

VB教材课后习题答案

VB教材课后习题答案

<大学程序设计基础-Visual Basic>教材课后习题答案第1章一、选择题1 2 3 4 5 6 7B D BC B B D第2章一、选择题1 2 3 4 5 6 7 8 9 10B C B C B C A A A A11 12 13 14A B A A二、填空题1.rem或’ _ :2.“” # #3.5x2-3x-2sinA/34.3214565.300三、操作题1、程序段:Private Sub Command1_Click()Dim x As Integer, y As IntegerDim s As Long, c As Longx = Text1.Texty = Text2.Texts = x * yc = (x + y) * 2Label3.Caption = "长方形的面积为" + Str(s)Label4.Caption = "长方形的周长为" + Str(c)End Sub3、程序段:Private Sub Command1_Click()Text1.Text = "第一"End SubPrivate Sub Command2_Click()Text1.Text = "第二"End Sub4、程序代码:Private Sub Text1_Change()Text1.MaxLength = 10End Sub5、程序代码:Private Sub Text1_Click()Text1.SelStart = 0Text1.SelLength = Len(Text1.Text)End Sub第3章一、选择题1 2 3 4 5 6 7D A D B A D B二、填空题1. False2.B^2-4*a*c else三、操作题1.从键盘输入三个值,判断它们能否构成三角形的三个边。

如果能构成一个三角形,则计算三角形的面积。

vb习题答案(1-9章)最全的

vb习题答案(1-9章)最全的

第一章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、字节。

VB教材课后习题参考答案

VB教材课后习题参考答案

二. 多项选择题三. 填空题1.事件驱动2.解释编译3.设计、运行和中断。

4.属性、事件和方法。

5.窗体单击(Form_Click)。

6.代码7. MyForm 。

习题2参考答案一.单选题二. 多项选择题三. 填空题1、⑴sin(50*3.14/180) ⑵(2+x*y)/(2-y^2)⑶a^2-(3*a*b/(3+a)) ⑷(x^3)^(1/8)+sqr(y^2+4*a^2/(x+y^3))2、int(rnd*(51)+50)3、⑴138 ⑵3 ⑶214 ⑷inchina ⑸70 (6)45⑺0习题3二.多项选择题三.填空题1. MultiLine,ScrollBars, 2 (或Vertical) 。

2. Label1.caption= "a*b=" 。

3. height 和 width 。

4. 2 。

5. Text1.SetFocus 。

6.编程技术,程序设计。

7.Change内容改变,将文本框内容显示在标签中。

GotFocus(获得焦点),选中文本框内容。

8.(1)Value ,(2) Value习题4参考答案三.填空题1、s = True And a >= 18 And a <= 20 And h > 165 Or s = False And a >= 16 And a <= 18 And h > 1602、600003、6,-2,24、Select Case xCase Is <= 0y = 4Case Is < 10y = 0Case Is < 15y = 1Case Is < 20y = 2Case Is <= 30y = 3Case Elsey = 4End Select5、(1)x>100 And x Mod 5=0 (2)0 (3)len(Text1.Text) (4)Text1.Text6 (1)D (2)A (3)B第5章习题5一.单选题1. A 2. C 3.⑴ C⑵ B 4. B 5. C 6. A7.D 8.D 9.A 10.C 11.A二.多项选择题1. ABCDE 2. BE 3. ABCDE三.分析程序1.⑴(4 ,13) ⑵(3,8) ⑶(3,27) ⑷(5,11) ⑸(3,10)2.12343. 64. 175. (1)len(s) (2)mid(s,k,1) (3)c & t (4)text2.text6. (1)0 (2)n+1 (3)2^n7.(1) mid(x,p+3) (2) 3 (3) p8. (1)Text1.Text (2)len(s)(3)x>="a" and x<="z" or x>="A" and x<="Z"(4) y & x9. (1)change (2)value习题6参考答案一.单项选择题1、D2、A3、C4、(1)B,(2)B5、C6、C7、A8、(1)C (2)B (3)A (4)B (5)D二.多项选择题1、CE2、DE3、ABC三.填空题1、数组D为 2 维数组,共有 16 个元素,第一维下标从 0 到 3 ,第二下标从 -1 到 2 。

VB-课本标准答案

VB-课本标准答案

VB-课本答案————————————————————————————————作者:————————————————————————————————日期:第三部分习题与解答第1章程序设计语言与程序设计1.1填空题1.VB是以(事件驱动)作为运行机制的新一代可视化程序设计语言。

2.程序设计语言是(人)与(计算机)交流的工具。

3.若从机器执行的角度来对程序设计语言进行分类,则可以分为(低级语言)和(高级语言)两种。

4.计算机系统中,对高级语言的翻译工具称为(编译)程序或(解释)程序。

5.源程序中的错误一般分为(编译)错误、(运行)错误和(逻辑)错误等三种。

6.VB把一个应用程序称为一个(工程),它包含各种文件。

1.2 选择题1.把a和b的乘积写成ab的错误属于(c )错误。

a) 编译b) 运行c) 逻辑d) 编译和运行2.用户在什么时候都可以按(b )键来查看与当前进行的工作相关的帮助。

a) Held b) F1 c) ESC d) F104 窗体文件的扩展名为(d )。

a) .vbp b) .bas c) .exe d) .frm4.指示一个窗体位置的值是窗体的(c )。

a) 对象b) 事件c) 属性d) 方法5.下面选项中不能运行VB程序的操作是(a )。

a) 双击窗体b) 单击“启动”按钮图标c) 从菜单栏运行菜单中选“全编译执行”菜单命令d) 按F5键1.3 问答题1.低级语言和高级语言的各自特点是什么?答:参见教材1.1。

2.什么是数据描述和数据处理?答:参见教材1.2。

3.源程序的翻译方式有哪两种,简述它们的工作过程。

答:参见教材1.1。

4.一个好程序的基本要求是什么?答:参见教材1.2。

5.Visual BASIC 集成开发环境的主窗口由哪些部分构成?各自的主要功能是什么?答:参见教材1.3。

6.简述在VB的环境下,对象、属性、方法、事件和事件驱动程序的概念,并用例子进行说明。

答:在VB的环境下,对象是系统中的基本运行实体,它封装了数据和操作。

VB1-3章_习题答案(课本习题)

VB1-3章_习题答案(课本习题)

VB习题答案(1-3章)习题一一、选择题1.C 2.C 3.A 4.C 5.C 6.C 7.B二、填空题1.学习版、专业版、企业版2.窗体界面3.Alt+F4三、简答题1.简述Visual Basic语言的特点。

Visual Basic是Windows操作平台下的可视化编程语言,它继承和发展了BASIC语言的基本功能,具有简单易学、功能强大等特点。

Visual Basic提供了可视化设计工具,以图形用户界面(GUI)为PC机用户提供了一个直观的工作环境。

支持面向对象的程序设计(OOP),采用事件驱动方式,提供对象的链接与嵌入(OLE)和访问数据库等功能。

2. Visual Basic 6.0的集成开发环境由哪些部分组成,各部分的主要功能是什么?1. 标题栏:用来显示打开的工程名称和系统的工作状态。

2. 菜单栏:菜单栏中包括“文件”、“编辑”、“视图”、“工程”、“格式”、“调试”、“运行”、“查询”、“图表”、“工具”、“外接程序”、“窗口”和“帮助”共有13个菜单项。

这是一组下拉式菜单,提供了设计、编辑、编译和调试应用程序所需要的绝大部分功能和命令。

3. 工具栏: Visual Basic 6.0提供了“编辑”、“标准”、“窗体编辑器”和“调试”4种工具栏。

工具栏上形象直观的排列着一些最常用的命令按钮,对应特定的常用操作命令。

4. 控件箱:控件箱提供了一组控件。

设计界面时,用户可以用鼠标双击控件箱中的控件,在窗体中画出该控件,或用鼠标单击控件箱中的控件,然后在窗体中拖动鼠标画出所需的控件。

5. 窗体设计器:窗体设计器是应用程序最终面向用户的窗口。

各种控件、图形、数据以及程序的运行结果都在窗体设计器窗体中显示出来。

6. 工程资源管理器:在工程资源管理器窗口中(图1-2),列出了应用程序的工程以及工程中的窗体和模块。

7. 属性窗口:属性窗口主要用来设置Visual Basic窗体及各控件的属性特征,属性窗口的主体部分分为左右两列,左边是控件的属性名列表,右边是控件的属性值列表。

vb课后习题答案

vb课后习题答案
第一章: 一:选择题 1-5 CCCCA 6-10 CBACA 11 A 二:填空题 1: 视图 工具箱 2: 对象 事件驱动 3: 代码 窗体设计器 4: 属性 方法 事件 5: 对象的特征 6: 一个对象可执行的动作 7: 属性窗口 赋值语句 三:简答题 1:略 2:略 四:编程题 【属性窗口设置】 Caption 这是我的第一个练习 【代码窗口设置】 Private Sub Form_Click() Print "我可以用Visual Basic语言编写程序了!" End Sub 第二章: 一:选择题 1-5: BDDCA 6-10: CBADD 11-15: DDBDB 16-20: DBCDC 21-23: CCD 二:填空题 1: Value 2: 下拉列表框 3: Scroll 4: LargeChange 5: ASCII码 6: Enabled 7: ListCount 8: PopupMenu 9: Alt 10:复选 11:CommonDialog1.ShowColor 或者: ShowColor 12:Flags 13: 1 14:- 15:GFED 第三章 一:选择题 1-5: ADADC 6-10: BCBDB 11-15:BBCBB 16-20:DCADA 21-25:ABCBB 26-30:DBBCB 31-34:BBDD 二:填空题 1: Right(CStr(x),1) & Left(CStr(x),1) 2: x Mod 5=0 Or x Mod 9=0 3: False 4: CDEF 5: s>="A" And s<="Z" Or s>="a" And s<="z" 6: x>=0 And x<100 7: Int(Rnd*(X-

vb书本习题参考答案

vb书本习题参考答案

参考答案第1章概述二.选择题:1.C2. B.3.C.4.C.5.A6.C7.D8.B9.B 10.B11.A12.C 13.D 14.C 15.D16.A17.C 18.A19.A20.D 21.B三.填空题:1.面向对象,事件驱动2.编译,解释3.设计,运行,中断4.F55.调试6.切换文件夹四.编程及上机调试:1.略2.Sub Form_Click( )Label1.Caption = “你单击了窗体”End SubSub Form_DblClick( )Label1.Caption = “你双击了窗体”End Sub第2章面向对象编程基础二.选择题:1.C2. C.3.B.4.B.5.D6.D7.B8.B9.C 10.D11.B 12.B 13.B 14.C 15.A16.B 17.B 18.B 19.C 20.B三.填空题:1.窗体,控件2.属性,事件,方法mand2_click4.picture5.中部,代码四.编程及上机调试:1.Private Sub Command1_Click()Form1.WindowState = 2End SubPrivate Sub Command2_Click()Form1.WindowState = 0End SubPrivate Sub Command3_Click()Form1.WindowState = 1End Sub2.Private Sub Command1_Click()Form1.Picture = LoadPicture("d:\picture\flower.wmf")Command1.V isible = FalseCommand2.V isible = FalseEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_DblClick()Form1.Picture = LoadPicture("")Command1.V isible = TrueCommand2.V isible = TrueEnd Sub第3章常用标准控件二.选择题:1.C2. B3.C.4.D5.B6.B7.A8.C9.B 10.C11.C 12.A13.C 14.B 15.D16.D 17.C 18.A19.D 20.A21.B三.编程及上机调试:1.Private Sub Check1_Click()If Check1.V alue = 1 ThenText1.FontBold = TrueElseText1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.V alue = 1 ThenText1.FontItalic = TrueElseText1.FontItalic = FalseEnd IfEnd SubPrivate Sub Check3_Click()If Check1.V alue = 1 ThenText1.FontUnderline = TrueElseText1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Command1_Click()Text1.Text = " "End Sub2.Private Sub Command1_Click()Text2.Text = List1.ListCountEnd SubPrivate Sub Command2_Click()List1.AddItem Text1.TextText1.Text = " "End SubPrivate Sub Command3_Click()Dim i As Integeri = List1.ListIndexList1.RemoveItem iCommand3.Enabled = FalseText1.SetFocusText2.Text = List1.ListCountEnd SubPrivate Sub Form_Load()Command3.Enabled = FalseEnd SubPrivate Sub List1_Click()Command3.Enabled = TrueEnd Sub第4章VB语言基础二.选择题:1.A2. D3.D.4.A5.A6.A7.C8.D9.C 10.B11.A 12.D 13.C 14.A15.A16.C 17.D 18.A19.B 20.D21.C 22.A23.B 24.C 25.C三.编程及上机调试:1.Private Sub Form_Load()Dim x As Integer, s As String, d As IntegerRandomizex = Int(Rnd * 9000 + 1000)s = Trim(CStr(x))d = V al(Right(s, 1) + Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1))ShowPrint "产生的数;"; x; "倒序数"; dEnd Sub2.Private Sub Form_KeyPress(KeyAscii As Integer)Print "输入字符:"; Chr(KeyAscii), "ASCII码为:"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Sub3.Private Sub Form_Click()MsgBox "在这里显示提示" & vbCrLf & "提示信息", 2 + 16, "请确认"End Sub或Private Sub Form_Click()MsgBox "在这里显示提示" + Chr(13) + "提示信息", vbAbortRetryIgnore _ + vbCritical, "请确认"End Sub第5章程序控制结构二.单选题1.D2. C3.C.4.D.5.B6.C7.A8.A9.D 10.C11.C 12.C 13.B 14.B四.编程及上机调试1. Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")If x > 20 Theny = x ^ 2 + 3 * x + 2ElseIf x >= 10 Theny = Sqr(3 * x) - 2ElseIf x > 0 Theny = 1 / x + Abs(x)End IfPrint "x="; x, "y="; yEnd Sub(2)Select Case实现:Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")Select Case xCase Is > 20y = x ^ 2 + 3 * x + 2Case Is >=10y = Sqr(3 * x) - 2Case Is > 0y = 1 / x + Abs(x)End SelectPrint "x="; x, "y="; yEnd Sub2.Private Sub Form_Click()Dim a As Integer, b As Integer, c As IntegerFor i = 100 To 999a = i \ 100b = (i - a * 100) \ 10c = i Mod 10If a ^ 3 + b ^ 3 + c ^ 3 = i ThenPrint i;k = k + 1If k Mod 2 = 0 Then PrintEnd IfNext iEnd Sub3.Private Sub Command1_Click()p = 60: r = 0.014Dop = p * (1 + r)n = n + 1Loop Until p >= 70Print n; "年后世界人口达到"; p; "亿"End Sub4.Private Sub Command1_Click()Dim s As Single, x As Integer, t As Single, n As Integer x = V al(InputBox("请输入x的值", , 2))s = 1n = 1m = 1Don = n + 1m = -mt = m * n / x ^ (n - 1)If Abs(t) < 0.00001 Then Exit Dos = s + tLoop Print s End Sub。

vb课后所有习题答案

vb课后所有习题答案

并不完善,仅供参考。

5.1答案一、选择题1---10:DCCAC ACDDC11---13:DDD二、判断题TTFFT TFTT三、分析1、Pos=pos+1Neg=neg+1Print pos;neg2、不见了3、程序改为:Dim a%()N = InputBox("please input n:")ReDim a(n, n)For i = 1 To nFor j = 1 To iIf j = 1 Or j = i Thena(i, j) = 1Elsea(i, j) = a(i - 1, j) + a(i - 1, j - 1)End IfPrint Tab((j - 1) * 6); a(i, j);Next jPrintNext i三、1、Option Base 1Private Sub Command1_Click()Dim A(10) As IntegerDim sum!RandomizeA(i) = (50 - 20 + 1) * Rnd + 20Next iFor i = 1 To 10Print A(i);Next iPrintMax = A(1)For i = 1 To 10If A(i) > Max ThenMax = A(i)End IfNext iPrint "最大值" & MaxMin = A(1)For i = 1 To 10If A(i) < Min ThenMin = A(i)End IfNext iPrint "最小值" & Minsum = 0For i = 1 To 10sum = sum + A(i)Next iPrint "总和="; sum & "平均值="; sum / 102、Option Base 1Private Sub Command1_Click()Dim a(20) As Integera(1) = 1a(2) = 1For i = 3 To 20a(i) = a(i - 1) + a(i - 2)Next iIf i Mod 5 = 0 ThenPicture1.Print a(i)ElsePicture1.Print a(i),End IfNext iEnd Sub3、Option Base 1Private Sub Form_Click()Dim a(3, 4) As IntegerFor i = 1 To 3For j = 1 To 4a(i, j) = InputBox(":")Next jNext iMax = a(1, 1): imax = 1: jmax = 1 Min = a(1, 1): imin = 1: jmin = 1 For i = 1 To 3For j = 1 To 4If Max < a(i, j) ThenMax = a(i, j)imax = ijmax = jEnd IfIf Min > a(i, j) ThenMin = a(i, j)imin = ijmin = jEnd IfNext jNext iFor i = 1 To 3For j = 1 To 4Print a(i, j);Next jPrintNext iPrintPrint "Max="; Max; " 行号"; imax; " 列号"; jmax Print "Min="; Min; " 行号"; imin; " 列号"; jmin End Sub4、Option Base 1Private Sub Command1_Click()Dim a()a = Array(7, 6, 5, 1, 8, 5, 3, 9, 4)n = Val(InputBox("请输入要删除的数:"))For i = 1 To UBound(a)If a(i) = n Thenk = iExit ForEnd IfNext iFor i = k + 1 To UBound(a)a(i - 1) = a(i)Next iReDim Preserve a(UBound(a) - 1)For i = 1 To UBound(a)Print a(i);Next iPrintEnd Sub5.2答案一、选择题1---10:ADBAD BABBB11---:BDDBA二、判断题TTFFF FFFTF(15题BackColor去掉空格,FillSte全部漏了y)三、1、1000Timer1.Enabled = trues = (x Mod 3600) Mod 602、n=3 x=42 y=9四、1、Private Sub Command1_Click()For i = 0 To List1.ListCount - 1List3.AddItem List1.List(i)Next iFor i = 0 To List2.ListCount - 1List3.AddItem List2.List(i)Next iEnd Sub2、Private Sub Form_Load()Label1.Left = 0Label1.Top = 0End SubPrivate Sub Timer1_Timer()Static iIf i = 0 ThenLabel1.BackColor = vbRedElseIf i = 1 ThenLabel1.BackColor = vbBlueElseLabel1.BackColor = vbGreeni = -1End Ifi = i + 1If Label1.Top > Form1.Height ThenLabel1.Left = 0Label1.Top = 0ElseLabel1.Left = Label1.Left + (Form1.ScaleWidth - Label1.Width) / 10Label1.Top = Label1.Top + (Form1.ScaleHeight - Label1.Height) / 10End IfEnd Sub3、Dim t1 As DoubleDim t2 As DoublePrivate Sub Command1_Click()t1 = NowLabel1.Caption = Format(t1, "hh:mm:ss")Label2.Caption = Format(t1, "hh:mm:ss")Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseLabel3.Caption = Format(t2 - t1, "hh:mm:ss")End SubPrivate Sub Form_Load()Timer1.Interval = 1000Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()t2 = NowLabel2.Caption = Format(t2, "hh:mm:ss")End Sub5.3答案一、选择题DBD(第3题答案是d、12 7,12漏了1)DC BCD(A多了一个”值”字)A 二、TTTTT三、1、2 5 9该题Command3改为command12、函数改为:Sub swap(b() As Integer)n = UBound(b)For k = 1 To n \ 2t = b(k)b(k) = b(11 - k)b(11 - k) = tNext kEnd Sub3、四、程序设计1、子过程和函数过程各一个做法Sub subsushu(x As Integer, k As Boolean)k = TrueFor i = 2 To x - 1If x Mod i = 0 Thenk = FalseExit ForEnd IfNext iEnd SubFunction fsushu(x As Integer) As Boolean fsushu = TrueFor i = 2 To x - 1If x Mod i = 0 Thenfsushu = FalseExit ForEnd IfNext iEnd FunctionPrivate Sub Command1_Click()Dim k As Booleanx% = InputBox("input x:")Call subsushu(x, k)If k = True ThenPrint x; "是素数"Print x; "非素数"End IfEnd SubPrivate Sub Command2_Click() x% = InputBox("input x:")If fsushu(x) = True ThenPrint x; "是素数"ElsePrint x; "非素数"End IfEnd Sub2、Option Base 1Sub fmax(a() As Integer, max) max = a(1)For i = 1 To UBound(a)If a(i) > max Thenmax = a(i)End IfNext iEnd SubPrivate Sub Command1_Click() Dim a(10) As IntegerFor i = 1 To 10a(i) = Rnd * 100Next iFor i = 1 To 10Print a(i);Next iPrintCall fmax(a(), max)Print "max="; maxEnd Sub3、Function xsum(x)Sum = 1For i = 1 To xSum = Sum + x ^ iNext ixsum = SumEnd FunctionPrivate Sub Command1_Click()a = 3b = 5c = 7d = 9Print a / xsum(a) + b / xsum(b) + c / xsum(c) + d / xsum(d)End Sub4、Function sp(ss, sc, sr)Do While InStr(ss, sc) > 0x = InStr(ss, sc)If x = 1 Thenss = sr & Right(ss, Len(ss) - Len(sc))Elses1 = Left(ss, x - 1)s2 = Right(ss, Len(ss) - (x - 1) - Len(sc))ss = s1 & sr & s2End IfLoopsp = ssEnd FunctionPrivate Sub Command1_Click()ss = "abcabcbc"sc = "bc"sr = "99"Print sp(ss, sc, sr)End Sub5.4答案一、选择题BCBAA B(其中y=IIf(x&gt;10,100,-100) f,Show 改为y = IIf(x > 10, 100, -100)f.Show)BBA二、1、“文本文件(*.txt)|*.txt”CommonDialog1.FileName2、Form1.hide三、1、2题合并如下Private Sub baocun_Click()CommonDialog1.ShowSaveOpen CommonDialog1.FileName For Output As #1 Print #1, Text1.TextClose #1End SubPrivate Sub beijingse_Click()CommonDialog1.ShowColorText1.BackColor = CommonDialog1.ColorText1.BackColor = CommonDialog1.ColorEnd SubPrivate Sub dakai_Click()CommonDialog1.ShowOpenOpen CommonDialog1.FileName For Input As #1 While Not EOF(1)Line Input #1, iText1.Text = Text1.Text & i & vbCrLfWendClose #1End SubPrivate Sub qianjingse_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub tuichu_Click()EndEnd SubPrivate Sub ziti_Click()CommonDialog1.ShowFontText1.FontName = CommonDialog1.FontNameText1.FontSize = CommonDialog1.FontSizeEnd Sub5.5答案一、选择题第一题好像都是对的?(多了个D)BAAD(其中c:“filel.txt都改为c:\file1.txt C二、分析题1 、dat改为txt文件y= 5 a= 5y= 15 a= 10y= 30 a= 152、程序改为Private Sub command1_click()Dim indata As StringText1.Text = ""Open "c:\a1.txt" For Input As #1Do While Not EOF(1)Input #1, indataText1.Text = Text1.Text & indataLoopClose #1End Sub3、程序改为Private Sub Form_Click()Dim x As Single, y As SingleOpen "d:\nm1.txt" For Input As #1Open "d:\NM2.txt" For Output As #2Do While Not EOF(1)Input #1, xPrint xy = x ^ 2Write #2, yPrint yLoopClose #1, #2End Sub三、设计题1、略2、略此2题好像比较简单。

VB 课后习题参考答案

VB 课后习题参考答案

第1章 习题参考答案一、思考题 略二、选择题1. C2. B第2章 习题参考答案一、判断题二、填空题1. 窗体font2. 不能在代码中设置 3. selstart 4. Locked5. TabIndex 、 0 6. vbModal 或 17. Activate 、 Deactivate 8.PictureBox 和 Frame -三、选择题第3章 习题参考答案一、思考题1、double2、 xyC@abc , 15eyd , Is , #END X8[P]3、变量有 (1) (4) (6) (8),常量有 (2)字符串型 (3)逻辑型 (5)字符串型 (7)字符串型 (9)日期型 (10)实型 4、 fe d cb a++5、 (1) 26 (2) 3.75 (3) 36、写出下列Visual Basic 表达式的值:(1) False (2) True (3) True (4) False (5) True(6) True (7) False (8) False7、将下列命题用Visual Basic布尔表达式表示:(1) z>x and z>y (2) abs(a)<=abs(b+2) or a > b+2(3) p mod q=0 (4) x<-5 or x>-2 and x<2 or x>5(5) x<z and y>z or x>z and y<z (6) a<b and a mod 2=08、写出下列函数的值:(1) -4 (2) 换行符(3) –3 (4) -1 (5) hello(6) ello (7) 16 (8) “-459.65” (9) 5二、填空题1.整型、长整型、双精度型、双精度型2.(X mod 10)*10+X\103.sin(1/4*3.14)+sqr(x+2*exp(y))/abs(x-y)4.(a+b)/(c*d-sqr(1-a^2))5.x mod 5=0 or x mod 9=06.False7.-3 、 2 、-2 、 28.CDEF9.x>0 and y>0 or x<0 and y<0 或x*y>010.s>=”A” and s<=”Z” or s>=”a” and s<=”z”三、选择题四、编程题1、Private Sub Form_Click()Dim x%, Ten%, hundred%x = Val(Text1.Text)Ten = (x \ 10) Mod 10hundred = x \ 100Print "百位数是: " & hundredPrint "十位数是: " & TenEnd Sub2Private Sub Form_Click()Dim char As String * 1Form1.CurrentX = Rnd * Form1.ScaleWidthForm1.CurrentY = Rnd * Form1.ScaleHeightchar = Chr(Int(Rnd * 16) + 65)Print charEnd Sub第4章习题参考答案一、判断题二、选择题三、程序阅读写出下列各段程序执行后的输出结果。

VB教材习题_参考答案1-6章

VB教材习题_参考答案1-6章

Visual Basic程序设计教程(李杰主编清华大学出版社 2011.2)习题答案习题2参考答案2.2 单选题1、B2、C3、A4、D5、A6、B7、D8、C9、B 10、D2.3 填空题1、事件驱动2、Cancel3、Name4、Private Sub Form1_Click()5、运行程序6、代码窗口7、Text1.Text = "我是一个学生"8、LostFocus()事件9、Label1.Caption = "请输入用户名"Label1.ForeColor = vbGreen10、(Text1.Text)*22.4 事件练习题1、①该事件的对象是标签Label1,单击标签触发该事件。

②缺省Label1对象的代码是针对窗体,其余有Label1对象的代码是针对标签的。

③Label1.AutoSize = True语句使标签的大小自动随文字的多少而改变。

2、程序运行后,单击命令按钮,在Text1文本框显示"知音海外版",在Text2文本框显示"计算机世界"。

3、单击“显示文本框”命令按钮触发的事件过程Private Sub Command1_Click()Text1.Visible = TrueText1.ForeColor = vbRedText1.Text = "VB程序设计"End Sub单击“隐藏文本框”命令按钮触发的事件过程Private Sub Command2_Click()Text1.Visible = FalseEnd Sub习题3参考答案3.2 单选题1 C2 C3 D4 B5 B6 B7 B8 C9 D3.3填空题1.REM(或‘) _ :2 双引号(“”)#3 $ %4 UCASE()5.(log(1+d*d)-exp(2))^(5/2) [ 还有一种理解方式:(log(1+d*d)-e*e)^(5/2)]6. &O113 &H4B习题4参考答案4.2 单选题BDCBD4.3 填空题1.MsgBox("是否删除? ", vbOkCancel + vbQuestion, "删除")2.The Length of 12345=53. 变量或表达式4. 15. loop4.4 程序设计题1.Private Sub Command1_Click()If Text1.Text = "asdf" ThenMsgBox "密码正确!"ElseMsgBox "密码错误", vbRetryCancel, "错误"End IfEnd Sub2. < 题目中的“连续产生n*n个字母”应该改为“连续产生n个字母”> Private Sub Command1_Click()Dim n%, y%, i%n = Val(Text1.Text)If n > 10 Or n<=0 ThenMsgBox "数据超界!"Text1.Text=””Text1.SetFocusElsey = Int((90 - 65 + 1) * Rnd) + 65For i = 1 To nPrint Chr(y + i)Next iEnd IfEnd Sub3.Private Sub Form_Click()Dim a!, b!, c!, x1!, x21, d!a = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = b * b - 4 * a * cIf d >= 0 Thenx1 = (-b + Sqr(d)) / (2 * a)X2 = (-b - Sqr(d)) / (2 * a)Print x1; X2ElsePrint "没有实根"End IfEnd Sub4.Private Sub Form_Click()Dim i%, j%, s%, n%,q%n = InputBox("enter n:")q = 0For i = 1 To ns = 0For j = 1 To is = s + jNext jq = q + sNext iPrint qEnd Sub5.Private Sub Form_Click()Dim i%, j%, n%, k%n = 0For i = 1 To 3For j = 1 To 3For k = 1 To 3Print i & j & k,n = n + 1If n Mod 5 = 0 Then PrintNext kNext jNext iPrintPrint "n="; nEnd Sub6.Private Sub Form_Click()Dim i%, j%, n%, k%For i = 1 To 9For j = 0 To 9For k = 0 To 9n = i * 100 + j * 10 + kIf n = i ^ 3 + j ^ 3 + k ^ 3 Then Print n,Next kNext jNext iEnd Sub习题5参考答案5.2 单选题1 A2 B3 C4 C5 D6 D7 A8 C9 D 10 A 11 A 12 B 5.3 填空题1.False2.Caption3.0 ListCount-14.Print List1.List(3)5.Combo1.ReMoveItem 36.LargeChange7.Timer8.5009.Shape10.Borderstyle5.4 程序设计题1.Dim op1, op2, result As SingleDim operator As IntegerPrivate Sub Command1_Click(Index As Integer)If Index >= 0 And Index <= 10 ThenIf txt1.Text = "" Thentxt1.Text = CStr(Index + 1)Elsetxt1.Text = txt1.Text + CStr(Index + 1) End IfEnd IfIf Index >= 12 And Index <= 15 Thenop1 = CDbl(txt1.Text)operator = Indextxt1.Text = ""End IfIf Index = 11 Thenop2 = CDbl(txt1.Text)Select Case operatorCase 12result = op1 + op2Case 13result = op1 - op2Case 14result = op1 * op2Case 15result = op1 / op2End Selecttxt1.Text = CStr(result)End IfEnd SubPrivate Sub Command2_Click()op1 = 0op2 = 0result = 0txt1.Text = ""End SubPrivate Sub Command3_Click()EndEnd Sub2.Private Sub chkBold_Click()If chkBold.Value = vbChecked ThenTxt1.FontBold = TrueElseTxt1.FontBold = FalseEnd IfEnd SubPrivate Sub chkUnderline_Click()If chkUnderline.Value = vbChecked Then Txt1.FontUnderline = TrueElseTxt1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Opt18_Click()Txt1.FontSize = 18End SubPrivate Sub Opt22_Click()Txt1.FontSize = 22End Sub3.Private Sub Form_Load()List1.AddItem "上海"List1.AddItem "北京"List1.AddItem "天津"List1.AddItem "广东"List1.AddItem "辽宁"List1.AddItem "陕西"List1.AddItem "河南"List1.AddItem "深圳"List1.AddItem "四川"List1.AddItem "重庆"End SubPrivate Sub List1_DblClick()For i = 0 To 9If List1.ListIndex = i ThenList2.AddItem List1.List(i)List1.RemoveItem iEnd IfNext iEnd Sub4.Private Sub Command1_Click()Timer1.Enabled=TrueTimer1.Tag=Text1.Text*60Frame1.Caption=“现在开始倒计时”End SubPrivate Sub Timer1_ Timer()Timer1.Tag=Timer1.Tag-1If m<0 ThenTimer1.Enabler=FalseMsgBox“预定的时间到了!”,0,“倒计时”Frame1.Caption=“请输入计时的分钟数:”Text1.Text=0Exit SubEnd Ifn1=Format(m Mod 60,“00”)n2=Format(m \ 60)Mod 60,“00:”)n3=Format(m \ 3600),“00:”)Text1.Text=n3&n2&n1End Sub习题6参考答案6.1单选题1.C2.C3.B4.B5.B6.D7.B8.B9.A 10.A6.2 填空题1.Option Base 12.变体类型3.preserve (注意:教材上面写成perserve, 教材错误)4.Variant变体类型5.96.相同,索引号7.1).通过复制粘贴的方式创建控件数组2).在设计时候添加多个同类型的类型控件,然后通过“属性”窗口将这些控件的名称改为相同,并把Index属性设为不同的下标值。

vb课后习题答案(红色参考书)

vb课后习题答案(红色参考书)

第一章VB开发环境与VB概述习题答案习题一、选择题1. B2. A3. A4. B5. D6. B7 A.8. A9. C10.B11. C12. D13. A14. D第二章常用控件与界面设计习题答案习题一、选择题1. C2.B3.C4.A5.A6.B7.B8.B9.C 10.C 11.B 12.B 13.D 14.A 15.B 16.B 17.B 18.C 19.C 20.D21.B 22.B 23.B 24.C 25.C26.C27. A28. B29.B 30.C 31.B 32.C 33.B 34.B35.D 36.B 37.D 38.D 39.B40.A 41.B 42.A 43.B44.B 45.D 46.A 47.A 48.B49.D 50.C 51.D 52.D 53.C54.D 55.D 56.C 57.A 58.C 59.C 60.B 61.B第三章实验与习题实验实验3_1‘算术运算Private Sub Command1_Click()Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6Dim x As Single, y As Single, z As Single, m As Singlex = 2: y = 1: z = 1: m = 1List1.ClearList1.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.ClearList1.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 <= 97.5 / 43.87 And -45.4 > -4.98List1.AddItem Str(32.345) = CStr(32.345)End Sub‘逻辑运算Private Sub Command3_Click()Dim x As Integer, y As IntegerDim C1 As Integer, C2 As Integer, C3 As IntegerC1 = 70: C2 = 80: C3 = 90x = 9: y = -2List1.ClearList1.AddItem x + y < 10 And x - y > 0List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)List1.AddItem x = 0 Xor y = 0List1.AddItem C1 + C2 + C3 >= 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 IntegerLabel1.Caption = "金额:"dj = InputBox("请输入商品的单价:", "单价框")sl = InputBox("请输入商品的数量:", "数量框", 1)je = dj * sln = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果")If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"End Sub‘产生随机数Private Sub Command2_Click()Dim m As Integer, n As IntegerDim x1 As Integer, x2 As Integer, x3 As Integerm = Val(Text1.Text): n = Text2.TextRandomizex1 = 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 IntegerRandomizea = 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.D2.B3.B4.D5.B6.D7.D8.B9.C 10.A11.D 12.D 13.D 14.C15.D16.D17B18.A19.D20.B21.D 22.C 23.D 24.A 25.A 26.B 27.A 28.A 29.C 30.A31.B 32.C 33.A 34.D 35.A 36.B 37.B38.B39.C40.D41.B42.C43.B44.D 45.C 46.C 47.A 48.D 49.B 50.A51.C 52.B 53.D 54.D 55.D56.DA7.B58.A59.A60.A61.B62.B 63.C 64.A 65.B 66.B 67.D 68.A 69.A 70.A 71.C72.B 73.B 74.D75.D 76.C 77.B 78.D 79.A 80.D 81.C 82.B 83.D 84.B 85.B 86.B 87.A 88.D 89.C填空题1、2 -32768~327672、整型长整型单精度双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))x>0 And y>0 Or x<0 And y<0c>=”a” And c<=”z” Or c>=”A” And c<=”Z”x>=10 And x<20x<z Xor y<z5、False 2 True False True True True True6、188 200100 68.56 8765547、a=1 b=1a=2 b=1a=3 b=1a=4 b=18、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =09、He Said, “Good morning”. 10、EDEF11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))12、a+b+c+d (a+b+c+d)/4 sum aver13、(f-2*h)/2 (4*h-f)/2简答题1、略2、Private Sub Form_Click()Const g = 9.8Dim V0 As Single, t As SingleDim S As SingleV0 = InputBox("请输入V0的值:")t = InputBox("请输入时间t的值:")S = (1 / 2) * g * t ^ 2 + V0 * tMsgBox ("位移量为:" & S)End Sub3、Private Sub Command1_Click()Dim l As Single, w As Single, h As SingleDim s As Singlel = Text1.Textw = Text2.Texth = Text3.Texts = (l * w + l * h + w * h) * 2Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1 方法一:x<=5 ; y 方法二:Is<=2 ;Case Else实验4-2 Shape1.BackColor=vbRed; Inter=15; Inter=Inter-1; Inter 实验4-3 b<c b=a a=k实验4-4 方法二:s*n ; t/s<10^-5实验4-5 方法一:m>=10^-4 ; (-1)^(n+1)*m实验4-6 x2=x3 ; <10^-6实验4-7实验4-8 i+2*j+5*k=10 ; n实验4-9 题目一:a) 5 b)i=16 p=12 n=5 c)i=9 p=8 n=1 题目二:120 10实验4-10 N=1 ;S=N& "*3 " & "+1 "实验4-11 Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St实验4-12 i\100 ; (i Mod 100)\10习题一、选择题1.C2.C3.A4.D5.A6.B7.B8.D9.B二、填空题1.Is=0 ; 1 To 10 ; Is >10 2. 9 3. 3 ; 4 15 4. this is a book ;This Is A Book 5. 3 ; 3 ; 3 5 6. 32 0 7. 4 8. 15 19. 1 ; 401 ;104 10. 1 2 3 ;1 3; 1 11. (3)12. 2 0 24 13. 10 14 14. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False 16. abs(t)<10^(-7) ; s+t17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1) S=S+118. Mid(n,i,1)>Mid(n,i+1,1) 19. "输入n";N/I=0 ;Print I第五章数组实验5_1 Int(90 * Rnd) + 10 a(i) = a(21 - i) a(21 - i) = t5_2 k = x Mod 10 i = i + 15_3 s5_4 max < a(i, j) row = I col = j5_5 1 ReDim Preserve prime(m) prime(j)5_6 d Mod 25_7 Exit For a(j + 1) = a(j)5_8 N – I A(j) = A(j + 1)5_9 A(i, 1) J Min = Max Not Flag5_10 ch >= "0" And ch <= "9" P = P & ch ReDim Preserve C(k)5_11 Private Sub Form_Click()Dim x As Integer, i As Integer, k As Integer, j As IntegerDim a() As Integerx = InputBox("输入正整数x=")i = 2Print x; "的质因子为:";Do While x >= iIf x Mod i = 0 Thenk = k + 1ReDim Preserve a(k)a(k) = ix = x \ iElsei = i + 1End IfLoopFor j = 1 To UBound(a)Print a(j);Next jEnd Sub习题一选择题1.A2.C3.D4.C5.B6.D7.D8.B9.D 10.B 11.B 12.D二填空题1. Variant2. ReDim A(N) A(1) If M < A(I) Then M = A(I)3. Int(26 * Rnd) + 65 Chr(t) i + 1 To 10 A(i) > A(j)4. InStr(s, ",") Right(s, Len(s) - n) s5. 4 5 6 6 5 4 3 2 16. T – 1 I + 17. k = 6 - i – j max = m 8. j = a j = j - 39. i + 1 i = i + 1 10. 2 3 7三编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("ê?è?m")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IFor I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As Integer Dim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopLoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As Integer A(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IText3.Text = SEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = Val(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub第六章参考答案实验实验6-11、Exit Do2、Y(X)3、X >= -1实验6-2 【题目二】42 、26、8实验6-3 1、s1, key 2、s As String 3、ch >= "a" And ch <= "z"4、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 * 1For i = 1 To Len(s)ch = Mid(s, i, 1)If "A" <= ch And ch <= "Z" ThenIf Asc(ch) - k < Asc("A") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfElseIf ch >= "a" And ch <= "z" Then '多分支格式,ch介于小写a与z之间If Asc(ch) - k < Asc("a") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfEnd IfNext 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 IntegerDim r As Integerr = p Mod qDo While r <> 0p = qq = rr = p Mod qLoopGcd = qEnd Function实验6-5 【题目一】age = age(n - 1) - 3【题目二】1、(Left + Right) / 2 2、Left = Mid + 1实验6-6 1、3 -1 2、7 4 3、3 -1 4、7 0 实验6-7 【题目一】1、Sqr(2 + t) 2、Abs(a - 1) < eps【题目二】1、Dim X As Integer 2、"S(" & I & ")=" & S(I)3、(j * i + 1)习题参考答案一选择题1.B2.D3.C4.C5.C6.B7.B8.B9.A 10.D 11.D 12.A 13.A 14.A 15.B 16.B 17.D18.C19.D20.B21.C 22.C 23.B 24.A 25.D 26.D 27.A 28.B二、填空1(1)形式、(2)实在2(1)按地址传递、(2)ByVal3(1)窗体模块、(2)标准模块、(3)类模块4(1) 6 5(1)4 20 1016(1) 6 26 、(2)-2 987(1)10 6 、(2) 5 -58(1) 6 5 、(2)8 79(1)11 、(2)710(1)Fun(i) 、(2)Fun=p11(1) 4 、(2)20.712(1)29 、(2)28.713(1)k = j 、(2)b() As Integer14(1)gec 、(2)ge 、(3) 315(1)p1 = True And p2 = True 或p1 And p2 、(2)p1 = p2 –2 、(3)Isp = True 、(4)m Mod i = 016(1)Convert(st) 、(2)Len(s) 、(3)"A" To "F" 、(4)k = k + p * h17(1)isualVi 、(2)sualVisu18(1)s + a 、(2)n + 1 、(3)x As Single, n As Integer 、(4)p * (x + i) / ((2 * i - 1) * i * x)三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean Dim K As IntegerReDim A(1)A(1) = 50———————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean) Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As Integer Dim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd 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 IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub5、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1、编程验证任一大于2的偶数可以表示成两个素数之和。

vb课后习题参考答案

vb课后习题参考答案

vb课后习题参考答案第一章习题参考答案一、填空题1、对象事件驱动2、编译运行模式解释运行模式二、简答题1、简述VB的特点。

答:①可视化的程序设计方法②面向对象的程序设计思想③事件驱动的编程机制④结构化的程序设计语言⑤高度的可扩充性⑥强大的数据库访问能力⑦支持动态数据交换⑧支持对象链接与嵌入2、简述VB的安装过程。

答:①向光驱中放入VB安装光盘;②计算机将运行自动安装程序,若没有,执行VB目录下的Setup.exe;③根据提示逐一回答问题,并点击“下一步”;④点击“完成”;2、如何启动VB。

答:三种方法:①单击“开始”按钮,选择“程序”菜单下的“Microsoft Visual Basic 6.0 中文版”菜单项并单击;②双击桌面上的VB6.0快捷图标;③在“开始”菜单的运行对话框中输入命令来启动VB;第二章习题参考答案一、选择题:1-10、DCACD BCBBC11-20、BADCA BBAAB21-29、AACBB CDDC二、填空题1.窗体、控件2.属性值3.属性窗口设置、代码窗口设置4.事件过程5.对象名、下划线、事件名6.Form_Click第三章习题参考答案一、选择题1、B2、C3、A4、B5、A6、C7、C二、填空题1、11字符型、字节型、整型、长整型、单精度型、双精度型、货币型、逻辑型、日期型、对象型、变体型。

String、Byte、Integer、Long、Single、Double、Currency、Boolean、Date、Object、Variant2、双引号(英文)、#3、ASCII、1、25、&、+、+6、Now()、Time、日期型三、解答题1、(3)2、(1 )3、(1)常量(关键字)(2)字符型常量(3)逻辑型常量(4)变量(5)字符串常量(6)变量(7)字符串常量(8)变量(9)日期型常量(题目应是#11/16/1999#)(10)数值型常量(单精度)4、315、(1)(1+y/x)/(1-y/x) (2)x^3+3*x*y/(2-y)(3)sqr(abs(a*b-c^3)) (4)sqr(s*(s-a)*(s-b)*(s-c))6、7、(1)13 (2)17(3)#1999-11-12# (4)zxy123ABC8、(1)19 (2)8.16666666666667(3)5.25 (4)29、(1)-4 (2)2 . 82842712474619 (3)-3 (4)49 (5)”hello” (6)He7)16 (8)“-459.65” (9)510、(4)11、(2)12、(4)第四章习题参考答案一、选择题:1—7: DAABBCD二、填空题1.500.00%2.将字号扩大为原来的二倍3. B三、编程题(略)1.文本框、标签和命令按钮的名称分别为text1、label1、command1Private Sub Command1_Click()Label1.caption=text1.textCommand1.caption=text1.textEnd Sub2.单价、数量、折扣和应付款对应的文本框的名称分别为:text1、text2、text3和text4,计算和清除命令按钮的名称分别为:command1和command2。

vb教程参考答案

vb教程参考答案

课本第3章习题参考答案(第100页)1. 输入梯形的上边长、下边长及高度,计算梯形的面积并输出。

要求使用InputBox 函数输入,使用Print方法输出。

2. 输入小时、分、秒,将它们换算为秒,然后输出。

要求使用文本框分别输入,使用标签输出。

3. 输入直角三角形的两个直角边,输出其斜边、周长和面积。

要求使用InputBox函数输入,使用Print方法输出。

4. 输入4课成绩,输出总成绩和平均成绩。

通过InputBox 函数输入数据,使用消息框MsgBox 进行输出。

6.编写程序,输入x,输出如下分段函数y 的值。

10. 编写程序,输入n ,计算1 + 2 + 3 + … + n 的和。

3x+2, x<00,x=02x-1, x>011. 编写程序计算11+ 22 +33 + 44 + …+ 1010的和。

12. 编写程序,输入10个同学的成绩(0~100),输出最高成绩和最低成绩。

13. 编写程序,输出100以内的素数。

14. 输入若干个学生的成绩,统计其中90分以上、70~89分、60~69分、小于60分的人数并输出。

当输入的成绩小于0时结束输入。

16. 用矩形法求指定区间内函数f (x)的积分 1)(dxx f ,其中发f (x) =1 + sin (x)。

17. 输入任意一个字符串,将其逆序后输出,例如,输入的字符串为“abcde”,则输出为“edcba”。

18. 输入任意一一个字符串,分别统计其中字母A、E和Z的个数,不区分大小写。

课本第4章习题参考答案(第136页)1. 编写程序,将2,4,6,…,18,20共10个数据赋予一个数组,然后将各数组元素按相反顺序输出。

2. 输入10个学生的成绩,计算总分与平均分。

3. 输入10个学生的成绩,输出最高分和最低分。

5. 编写程序,将长度为5的一维数组中的数组元素循环右移动一个位置,最后一个元素移到第一个元素位置上。

例如,若数组元素各个值为1,2,3,4,5,则移动后的值为5,1,2,3,4。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《Visual Basic程序设计》参考答案
第1章程序设计及VB概述
一、选择题
1、C
2、A
3、A
4、C
5、B
6、C
7、D
8、A
9、D 10、C
二、填空题
1、对象Windows(不确定)事件驱动
2、窗体工程
3、查看对象查看代码
4、CmdExam Click lbldisp
5、“启动”按钮“运行”菜单“启动”命令F5
6、Click事件过程
7、Cancel
8、Label1
第2章V isual Basic程序设计基础
一、选择题
1、A
2、C
3、D
4、B
5、C
6、A
7、B
8、A
9、B 10、D
二、写出下列表达式的值
1、 6
2、0
3、8
4、False
5、False
6、True
7、-1
8、16.7
9、"C" 10、"Basic"
11、"VISUAL " 12、5
三、将代数式改写成VB表达式
1、(a + b) / (c * d - Sqr(1 - a * a)) + 5 ^ (1 / 3) * Cos(3.14159 / 3) ^ 2
2、Sin(45 * 3.14159 / 180) + Abs(x - y)
3、2 * Exp(x) + Log(x * y)
4、(Log(50) / Log(10) - Log(20)) / (9 * Exp(3))
5、Abs(x) >= Y And Abs(x) <> Z
6、m < 100 And m >= 0
7、(A Mod 3 = 0) Or (A Mod 7 = 0)
8、(N Mod 4 = 0 And N Mod 100 <> 0) Or (N Mod 400 = 0)
第3章程序的基本控制结构
一、选择题
1、⑴ C ⑵D
2、B
3、B
4、B
5、C
6、A
7、D
8、BD
9、C 10、D
11、A12、A13、D 14、A15、A16、D
二、填空题
1、15 15
2、x= 3 y=10
3、 1 2 3 4 5 6 7 8 9 0
* * * * *
* * * * *
* * * * *
4、⑴12345 ⑵54321
5、ABCDE
6、32
7、⑴k ⑵If x < n Then n = x : nk = i⑶mk ⑷m
8、⑴exit for ⑵f1 And f2 Then ⑶f1 = f2
9、⑴n ⑵ Len(CStr(nn) - 1) ⑶ c-1
⑷ Loop Until nn = 0 ⑸ n = m Then
10、⑴ Opt1.Value = True ⑵ Opt2.Value ⑶ Opt3.Value
⑷ CStr(k) ⑸ k-10 ⑹ Asc("A")
第4章数组
一、选择题
1、B
2、A
3、D
4、C
二、填空题
1、Option Base 1
2、ReDim Preserve
3、Lbound UBound
4、可变
5、Index
6、 4 11
7、27
8、arr(1) Fmin=1 min = arr(i)
第5章应用程序界面设计
一、选择题
1、C
2、B
3、A
4、B
5、D
6、D
7、D
8、DA
9、BC 10、A 11、A12、B 13、A14、A15、A
二、填空题
1、通用
2、Style
3、Print lstEx.List(2)
4、CmbEx.ListIndex = 4
5、“-”
6、PopupMenu
7、Enabled Interval True >0
8、窗体、图片框、框架
9、MultiLine ScrollBars
10、AutoSize Stretch
11、Image1.Picture = LoadPicture("c:\pic1.jpg")
12、Change
13、另存为
14、顶级
15、⑴ListIndex Text 或List(List1.ListIndex)
⑵List(2)
⑶x , Lst1.ListIndex +1
⑷ListCount – 1 Selected RemoveItem i
第6章过程
一、选择题
1、C
2、C
3、C
4、A
5、D
二、填空题
1、内存空间或者:地址
2、传值传址
3、Sub TestAB(a As Single, b!, c As Boolean)
4、过程名=<表达式>
5、局部变量
6、Static
7、本过程模块整个工程
8、模块级工程级
9、过程调用自身递归结束递归描述
10、 6 8 4
6 4 3
11、0.6 1.8
12、 2 5 8 11
13、 3 1 3
0 1 3
4 1 3
0 1 3
1 1 3
第7章鼠标和键盘
填空题
1、11
2、MouseDown MouseUp MouseMove
3、Shift Ctrl Alt
4、MouseDown MouseUp MouseUp
5、A a
6、Ctrl + Alt + 单击鼠标右键
7、Form-66
Text-66
第8章文件
一、选择题
1、C
2、B
3、A
4、D
5、D
二、填空题
1、程序文件和数据文件顺序文件和随机文件ASCII文件和二进制文件
2、顺序随机二进制
3、Output Append Input Random Binary Random
4、打开(建立)读/写关闭
5、Input# LineInput# Input() Get Put
6、Input As #10 Output As #20
7、Dir1.Path Drive1_Change()
第9章多窗体和多文档界面
一、选择题
1、C
2、C
3、D
4、C
5、C
二、填空题
1、Load UnLoad
2、Show Hide
3、无效
4、图片框
5、图片框、计时器
第10章文本和图形
选择题
1、A
2、C
3、A
4、B
5、C。

相关文档
最新文档