高中信息技术VB程序的调试会考复习题.docx
高中信息技术 VB程序调试 会考复习题学校:_姓名:_班级:_考号:_一、选择题1数组排序。点击“产生随机数按钮,让计算机随机产生10个整数,并对这10个整数进展标号,再点击“排序按钮,对这10个整数进展从大到小排序。如下图。程序代码如下:Dim a(1 To 10) As IntegerDim i, j, k, kt As IntegerPrivate Sub Command1_Click() '去除列表框数据For i 1 To 10 Randomize '随机数初始化a(i) Int(Rnd() * 1000) List1.AddItem Str(i) Str(a(i)Next iCommand2.Enabled True'激活排序按钮End SubPrivate Sub Command2_Click()For i 1 To 9 k iFor j _To 10 If a(j) > a(k) Then k jNext j If i <> k Then_End IfNext iFor i 1 To 10List2.AddItem Str(i) Str(a(i)Next iEnd Sub请在、划线处填入适宜语句或表达式,把程序补充完整:程序中划线处应填入_;程序中划线处应填入_。【答案】I+1;t=ak:a(k)=a(i):a(i)=t【解析】2Sub test2()a = 12:b = 12:c = 5Label1.Caption = ""Label2.Caption = ""If a > b Or Not b<c ThenLabel1.Caption = "monday"ElseLabel2.Caption = "tiger"End IfEnd sub该程序段运行后,在标签Label3Caption属性值是( )A "monday" B "tiger" C "mondaytiger" D ""【答案】A【解析】3在窗体上画一个命令按钮,名称为command1,单击命令按钮,执行如下事件过程:Private Sub Command1_Click() Dim a As StringDim c As Stringa = "software and hardware"c = Mid(a, 14, 8)Text1.text = cEnd Sub那么在文本框Text1中显示信息是 A、software and hardwareB、softwareC、hadrwareD、and【答案】C【解析】4有如下Visual Basic程序段:s=1for i= 1 to 11 step 3s=s*inext i语句s=s*i共执行次数为 A11 B10 C5 D4【答案】D【解析】5数学表达式“a>b>c对应VB表达式是 Aa>b>c Ba>b and a>c Ca>b and b>c Da>b or b>c【答案】C【解析】6 表达式 abs(int(-2.88)+int(3.14)值是 。A 5 B 0 C 1 D 2【答案】B【解析】7对以下程序段说法正确是 s=0i=0Do While s<10i=i+1s=s+i*iLoopA该程序循环体执行了3次B该程序段完毕后i值为3C该程序段完毕后i值为4D该程序段完毕后s值为13【答案】ABD【解析】8在Visual Basic代码中,将多个语句合并在一行上并行符是( )A 撇号' B 冒号: C 感慨号! D 问号【答案】B【解析】9有如下一段VB程序。Private Sub Command1_Click() Dim y As Long Text1.Text = "" y = f(3) Label1.Caption = Str(y)End SubFunction f(n As Integer) As Long Text1.Text = Text1.Text + Str(n) If n <= 1 Then f = 1 Else f = f(n - 1) + 2 End IfEnd Function程序运行时,单击命令按钮Command1后,文本框Text1中显示内容是 A 1B 3C 123D 321【答案】D【解析】10以下关于CommandButton 控件表达正确是( )A CommandButton 控件Caption 属性决定按钮上显示内容B 单击VB应用程序中按钮,那么系统激活按钮控件对应Change 事件C CommandButton 控件name 属性决定按钮上显示内容D 以上都不对【答案】A【解析】11某Visual Basic工程相关视图如以下图所示:从图中信息可知,以下说法不正确是( )A 窗体中有一个按钮对象,名称为Command1B 该程序中用到了Timer控件C 当前代码窗口中显示事件处理过程名为“Command1_ClickD 该工程窗体文件名“snow.vbp【答案】D【解析】12在VB中,x=10,那么执行以下语句结果是print "a="aAa=10 Ba=a C10 D10=10【答案】A【解析】13在Visual Basic中,以下语句定义错误是: A BDim False As BooleaC Dim b(1 to 5) As String DDim y As Long【答案】B【解析】14x= "Visual Basic",那么表达式Mid(x,6,3)值为: A"lBa" B"l B" C"Bas" D"lB "【答案】B【解析】15假设运行时输入5、9,以下流程图运行结果是_。A14,45B14,126Ca + b,a * bD126,14【答案】A【解析】16如第20题图所示流程图片段:该流程图执行过后,a、b、c值分别为: a¬5:b¬8c¬a+b:a¬b+c:b¬b+1A. a=21,b=9,c=13 B. a=5,b=8,c=13C. a=5,b=9,c=14 D. a=21,b=9,c=14【答案】A【解析】17编写VB程序,实现如下功能:在文本框Textl和Text2中分别输入一个整数,单击命令按钮Command1,在列表框List1中显示结果,运行效果如第1图所示。结果包含两列数据,第1列为两数之间摄氏温度值间隔1度、升序,第2列为对应华氏温度值。 1图 2图1要使命令按钮Command1上显示文本改为“转换,可在其属性窗口2图) 中将 属性属性值修改为“转换。2为实现上述功能,请在划线处填入适宜代码或选项。Private Sub Command1_Click()Dim t1 As Integer, t2 As IntegerDim i As Integer, t As IntegerDim f As Singlet1 = Val(Text1.Text)t2 = Val(Text2.Text)If Then '(选填字母,从以下A、B、C、D四个选项中选取一项 t = t1: t1 = t2: t2 = tEnd Ifi = t1Do While '(选填字母,从以下A、B、C、D四个选项中选取一项f = i * 9 / 5 + 32 '摄氏温度转换为华氏温度 Str(i) + " " + Str(f) '填程序代码LoopEnd Sub划线、处选项:Ai <= t2 Bf <= t2 Ct1 > t2 D i < f【答案】1Caption 2 C A i = i + 1【解析】18如下图流程图片断该流程图中循环局部完毕后,变量S值是( )A、 5 B、 15C、 25 D、 36【答案】B【解析】小庄编写了一个统计数组元素a(l)到a(n)中“升序段个数s(如下图数据序列,其 “升序段个数等于3)VB程序。局部程序如下:k = 0 : s = 0For i =" 2" To nIf a(i) > a(i - 1) ThenElseIf k =" 1" thens=s+1k=0end ifEnd IfNext iTextl.Text = Str(s)方框中正确语句是( )Ak =" k" - 1Bk =19Ck = -1Dk =" k" + 1【答案】D【解析】20有如下VB 程序,该程序运行后在文本框Text1 中显示结果是 Dim i As Integer, j As Integer, s As Integer, n As Integern =" 3:" s = 0For i =" 1" To nFor j =" 1" To is =" s" + jNext jNext iText1.Text = sEnd SubA 3 B 6C 10 D 18【答案】C【解析】21以下能作为Visual Basic变量名是 Ab+7 BMod C3x DT_1【答案】D【解析】22假设变量m =" 0" .81 ,那么表达式Sqr ( m ) 1 And Not int ( m) > 1 值是_A T B F C 0.9 D 1【答案】A【解析】23如下图,是求绝对值算法,其描述方式分别是 A自然语言、流程图B伪代码、流程图C自然语言、伪代码D流程图、自然语言【答案】A【解析】24Sub test16()X = 9For i = 2 To 51 Step 3 If (X / 2) >= i Then X = X + 1Next iFor i = 2 To -2 Step 3 If (X / 2) >= i Then X = X + 1Next iMsgBox (X+i)End Sub 该程序运行结果是 A、64 B、13 C、61 D、62【答案】B【解析】25以下可作为Visual Basic 变量名是 ( )A、D * 4 B、A_4_B C、4ABC D、 Dim 【答案】B【解析】26在Visual Basic 中,以下优先级最高运算符是( )A* B C< DNot【答案】A【解析】27sual Basic中,语句Command1.Font="宋体"中“Command1”是 A对象名 B属性名 C属性值 D窗体名【答案】A【解析】二、填空题28填空题:共8分,每题2分。1 本程序中,变量a、b 数据类型都是_填写中、英文均可。2以上代码中,表示输出语句是第_行。3本程序中,代码a=a+b含义是_选填或。选项:.把a值赋给a+b.把a加b和赋给a4假设输入两个数分别是10和20,那么程序执行完毕,变量a值是_,变量b值是_。【答案】【解析】29输出结果为 。Dim n as integerDim s as longn=9s=0do while n>=1s=s+nn=n-2loopprint s【答案】25【解析】30有一组数:1、2、4、7、,其第1个数是1,第2个数比第1个数大1,第3个数比第2个数大2,第4个数比第3个数大3,以此类推。求其前20项和。以下VB程序实现上述功能,请把程序中、出填写完整。Dim i As Integer, p As Integer, s As Integeri = 1p = 1s = 0Do While _ s = s + p i = i + 1 _LoopPrint s【答案】i<=20 p=p+i-1【解析】31计算以下表达式值(1).15610 mod 7值是_(2).12+52 MOD 23*372/23+1值为_ (3).如果变量a=2,b=3,c=4,d=5,表达式NOT a>b AND NOT d<>c值是_(4).如果变量 a=7、b=6、c=4、d=5,那么表达式 a<d OR b>c AND c<>d 值为_【答案】112173false4true【解析】32小贝对街机中打手掌游戏很感谢兴趣,于是也用VB做了个打手游戏,界面如图。点击开场按钮command1,标签label1开场从3秒倒计时,倒计时完毕开打,如果打中手掌,label1显示打中了,如果超过去秒,那么显示没打中,游戏完毕。点开场按钮可以重来。请根据题意将以下程序补充完整。Dim t As Integer t用来计时Private Sub Command1_click( )Image1.left=64Label1.caption=t=0Timer1.interval=1001_Image1.Enabled=FalseEnd subPrivate Sub Image1_click( )Timer1.Enabled=FalseImage1. Enadled=FalseLabel1.caption=打中了End SubPrivate Sub Timer1.Timer( )t = t +1if t<=30 then label1.caption=3-int(t/10)if t>32 thenlabel1.caption=没打中For i=1 to 10 手迅速移开动画For j=1 to 10000DoeventsNextjNext iTimer1.Enabled=FalseImage1.Enabled=FalseEnd ifIf t=30 then当t=30时,即倒计时3秒完毕,允许开打,对象image1开场允许响应事件2_End ifEnd sub【答案】1timer1.enabled=true 2image1.enabled=true 【解析】33编写VB程序,实现如下功能: 单击“排序数组a按钮Command1时,对已有数组a数据进展升序排列,并显示在文本框Label1中;单击“显示数组b按钮Command2时,将升序数组b数据显示在文本框Label2中;再单击“合并a和b按钮Command3时,对数组a和数组b升序合并到字符串中,将合并后数据在文本框Label3中显示。(运行效果如下图)。实现上述功能VB代码如下, 请在划线处填入适宜代码。Dim a(1 To 6) As IntegerDim b(1 To 6) As IntegerPrivate Sub Command1_Click() '对数组a中数据进展排序Dim i As Integer, j As Integer ,k as integera(1) = 53 :a(2) = 18:a(3) = 62:a(4) = 22:a(5) = 6:a(6) = 25s = ""For i = 1 To 5k = i For j = i + 1 To 6If a(k) > a(j) Then Next jIf i <> k Thent = a(k): a(k) = a(i): a(i) = tEnd IfNext iFor i = 1 To 6s = s + Str(a(i)Next iLabel1.Caption = sEnd SubPrivate Sub Command2_Click()b(1) = 3: b(2) = 8: b(3) = 15: b(4) = 27: b(5) = 38: b(6) = 49'此处局部代码省略End SubPrivate Sub Command3_Click()'将数组a和b中数据逐个比拟后添加到新字符串s中,并将s在label3中显示i = 1: j = 1: s = ""Do While i <= 6 j <= 6 '如果两数组都还有数据未合并If Thens = s + Str(a(i) : i = i + 1Elses = s + Str(b(j) : j = j + 1End IfLoopDo While i <= 6 '只有数组a还有数据未合并s = s + Str(a(i) : i = i + 1LoopDo While j <= 6 '只有数组b还有数据未合并s = s + Str(b(j) : j = j + 1LoopLabel3.Caption = sEnd Sub【答案】 k=j And a(i) < b(j)【解析】34编写VB程序,实现如下功能:在文本框Text1中输入某一年份,单击“天干地支与生肖按钮Command1,在列表框List1中输出该年份开场12个年份及对应“天干地支与“生肖,运行界面如下图,程序代码如下。1代码“Private Sub Command1_Click()中Click是 。单项选择,填字母:A对象名/B属性名/C事件名2为实现上述功能,请在划线处填入适宜代码。Private Sub Command1_Click()Dim a As Integer, b As IntegerDim i As Integer, n As IntegerDim c1 As String, s1 As StringDim c2 As String, s2 As StringDim c3 As String, s3 As Strings1 = "甲乙丙丁戊己庚辛壬癸"s2 = "子丑寅卯辰巳午未申酉戌亥"s3 = "鼠牛虎兔龙蛇马羊猴鸡狗猪"n = Val(Text1.Text)For i = n To a = (i + 6) Mod 10 b = (i + 8) Mod 12 c1 = Mid(s1, a + 1, 1) c2 = Mid(s2, b + 1, 1) c3 = Mid(s3, b + 1, 1) + "年" + c1 + c2 + " " + c3Next iEnd Sub3由上述算法可知,2024年对应“天干地支为 。【答案】1C2 n+11 str(i)3 甲辰【解析】35学校要进展元旦文艺汇演了,学生会让薛明来担任总记分员,任务就是根据各个评委所打分数,去掉一个最高分和一个最低分,然后计算平均分。薛明很快编写了这个程序,该程序界面如右图所示:程序运行时,每输入一个分数单击“确定按钮Command1,就将该分数记入总分,同时在下面显示到目前为止已输入所有分数。当所有分数输入完毕后,单击“统计->按钮Command2,程序就会在右边显示总分和最后平均分。请答复下面问题:1写出上述图形中所标识对象所属类?如所属类为“文本框。 2以下是薛明编写统计程序,请完善程序。Dim total As Integer, ans As Single, x As Integer, max As IntegerDim min As Integer, s As IntegerPrivate Sub Command1_Click()x = Val(Text1.Text)total = total + xs = s + 1If Then max = xIf x < min Then min = xList1.AddItem xEnd SubPrivate Sub Command2_Click()Label4.Caption = Str(total)ans = ans = ans / (s - 2)Label6.Caption = End SubPrivate Sub Form_Load()total = 0s = 0min = 10000max = 0End Sub【答案】列表框或列表框类或listboxx>max或x>=maxans-max-minstr(ans)【解析】36将以下程序段补充完整。问题:往一个足够大盒子里放小球,第一次放1个,第二次放2个,第三次放3个,即每次放小球数比上一次多1个。问放到第几次盒子里小球才能多于300个?输出答案。n 表示放球次数,sum表示小球总数。Dim n as integer , sum as integer n=0 sum=0 Do While sum<=300 n =_ _ sum =_ _ LoopPrint “放到第 & _ _ & “次盒子里小球才能多于300个【答案】 n+1 sum+n n【解析】三、操作题37求两个整数最大公约数分析:求最大公约数算法思想:1对于两数m,n,使得m>n;2m除以n得余数r;3假设r=0,那么n为求得最大公约数,算法完毕;否那么执行(4);4mn,nr,再重复执行(2)。例如: 求 m=14 ,n=6 最大公约数. M n r14 6 26 2 0请根据以上思路补充下面程序代码:Private Sub Command1_Click()m = InputBox("m=")n = InputBox("n=")If m < n Then t = m: m = n: n = tr = _Do While (r <> 0)m = nn = rr = m Mod nLoopPrint "最大公约数=", nEnd Sub【答案】m mod n【解析】四、判断题38VB开发应用程序两个特征是“对象和“事件驱动; 【答案】错误【解析】39Visual Basic(简称VB)是一种通用基于对象程序设计语言; 【答案】正确【解析】40运行列表框对象语句:List1.AddItem= "同学们好!",会显示:同学们好! 【答案】错误【解析】41TEXT1.TEXT=C和 都没有语法错误; 【答案】正确【解析】42在VB窗口中建立命令按钮对象,双击该对象,建立程序名称中对象名和命令按钮对象名称一样; 【答案】正确【解析】五、简答题43小王编写了一个实现文字查找替换功能VB程序,运行界面如下图。文本框Text1显示原文内容,Text2中输入查找内容,Text3中输入替换内容,单击“全部替换按钮Command1后,Text4显示查找替换结果,Text5中显示替换次数,Text6显示“查找内容在原文中起始位置。实现上述功能VB程序如下,但加框处代码有错,请改正。Private Sub Command1_Click() Dim s As String, resule As String, pos As String Dim count As Integer, i As Integer i = 1: count = 0 resule = "": pos = "" Do While i <= Len(Text1.Text) s = Mid(Text1.Text, i, Len(Text2.Text) If s = Then result = result + count = count + 1 pos = pos + Str(count) i = i + Len(Text2.Text) Else result = result + i = i + 1 End If Loop = result = Str(count) = posEnd Sub【答案】【解析】(1)pos+str(i)(2)result=result+mid(text1.text,i,1)44如果两个质数差为2,那么这两个质数称为孪生质数对;编写VB程序,实现如下功能:单击“显示孪生质数对按钮Command1,在列表框list1中显示100以内所有孪生质数对(运行效果如下图)。实现上述功能VB代码如下, 但加框处代码有错,请改正。Dim a(1 To 50) As IntegerPrivate Sub Command1_Click()Dim i As Integerk = 0: i = 3Do While i <= 100If prime(i) Then k = k + 1a(k) = iEnd Ifi = i + 2LoopFor i = 2 To kIf a(i) = a(i +1)+2 Then Str(a(i - 1) + "和" + Str(a(i)来源:学#科#网Z#X#X#KEnd IfNext iEnd SubFunction prime(x As Integer) As Booleanprime = FalseFor i = 2 To Int(Sqr(x)If x Mod i = 0 Thenprime = TrueExit ForEnd IfNext iEnd Function【答案】 Not prime(i) 或 prime(i)=False a(i) = a(i -1)+2【解析】