vb考试复习5章-6章习题(34页).doc
-第5章 选择结构程序设计-、选择题1. 下列语句正确的是【 】。(多选)(A)If XY Then Print "X不等于Y"(B)If X<>Y Then Print "X不等于Y"(C)If X><Y Then Print "X不等于Y"(D)If X=Y Print "X不等于Y"2. 下列语句正确的是【 】。(A)If AB Then T=A A=B B=T(B)If AB Then T=A;A=B;B=T(C)If A>=B Then T=A A=B B=T(D)If A>=B Then T=A:A=B:B=T3. 下列语句正确的是【 】。(A)If X<3*Y And X>Y Then Y=X3(B)If X<3*Y And X>Y Then Y=X3(C)If X<3*Y:X>Y Then Y=X3(D)If X<3*Y And X>Y Then Y=X*34. 关于语句If x=l Then y=1,下列说法正确的是【 】。(A)x=1和y=1均为赋值语句(B)x=1和y=1均为关系表达式(C)x=1为关系表达式,y=1为赋值语句(D)x=1为赋值语句,y=1为关系表达式5. 执行以下语句后显示结果为【 】。Dim x As IntegerIf x Then Print x Else Print x-1(A)1(B)O(C)一1(D)不确定6. 如果X的值小于或等于Y的平方,则打印"OK",表示这个条件的单行格式If语句是【 】。(A)If x<=y2 Then Print "OK"(B)If x<=y2 Print "OK"(C)If x<=y2 Then "OK"(D)If x<=y2 Then Print "OK"7. 如果A为整数且|A|=100,则打印"OK",否则打印"Error",表示这个条件的单行格式If语句是【 】。(A)If Int(A)=A And Sqr(A)>=1O Then Print "OK" Else Print "Error"(B)If Fix(A)=A And Abs(A)>=100 Then Print "OK" Else Print "Error"(C)If Int(A)=A And (A>=100,A<=-100) Then Print "OK" Else Print "Error"(D)If Fix(A)=A And A>=100 And A<=-100 Then Print "OK" Else Print "Error"8. 下列程序段【 】能够正确实现条件:如果X<Y, 则A=15,否则A=-15。(A)If X<Y Then A=15(B)If X<Y Then A=15:Print AA=-15A=-15Print A Print A(C)If X<Y Then (D)If X<Y Then A=15A=15:Print A Else A=-15Else Print AA=-15:Print A End IfEnd If9. 能够实现以下分段函数的程序段是【 】。(多选)f(x)= 1+X XO1-X X<O(A) If X>=O Then Y=1+X (B) If XO Then Y=1+XY=1-X Else Y=1-X End If(C) If X>=O Then Y=1+X(D) If X<O Then Y=1-XIf X<O Then Y=1-XY=1-X Else: Y=1+X End If10. 下列【 】程序段不能实现以下分段函数。(多选)f(x)= sqr(x+1)x1 x2+3x<1(A) x=Val(Text1.Text) (B) x=Val(Text1.Text)f=x*x+3 If x>=1Then f=Sqr(x+1)If x>=1 Then f=Sqr(x+1) If x<1 Then f=x*x+3Print f Print f(C) x=Val(Text1.Text) (D) x=Val(Text1.Text)If x<1 Then If x>=1Then f=Sqr(X+1) f(x)=x*x*+3 f=x*x*+3Else Print fF(x)=Sqr(X+1)End IfPrint f11. 计算分段函数: 0 x<0 1 0x<1f(x)= 2 1x<2 3x2下面程序段中正确的是【 】。(A) If x<0 Then y=0(B) If x>=2 Then y=3If x<1 Then y=1 If x>=1 Then y=2If x<2 Then y=2 If x>=0 Then y=1If x>=2 Then y=3 If x<0 Then y=0(C) If x<0 Then(D) If x>=2 Theny=0 y=3ElseIf x>=0 Then ElseIf x>=1 Theny=1 y=2ElseIf x>=1 Then ElseIf x>=0 Theny=2 y=1Else Elsey=2 y=0End If End If12. 计算分段函数: 0 x<0 1 0x<1f(x)= 2 1x<2 3x2下面程序段中正确的是【 】。(A) Select Case x(B) Select Case x Case x<O Case x<Oy=0 y=0Case x>=O And x<1 Case x<1y=1 y=1Case x>=1 And x<2 Case x<2y=2 y=2Case Else Case Elsey=3 y=3End Select End Select(C) Select Case x(D) Select Case xCase Is <OCase Is<Oy=0 y=0Case Is<1Case Is>=0,Is<1y=1 y=1Case Is<2 Case Is>=1,Is<2y=2 y=2Case ElseCase Is>=2y=3 y=3End Select End Select二、判断程序或程序段的执行结果1.下列程序段的执行结果为【 】。X=2Y=1If X*Y<1 Then Y=Y-1 Else Y=-1Print Y-X>O(A)True(B)False(C)-1(D)12.下列程序段的执行结果为【 】。J1=10J2=30If J1<J2 Then Print J2;Print J1(A)10(B)30(C)10 30(D)30 103.下列程序段的执行结果为【 】。X=5Y=-20If Not X>O Then X=Y-3 Else Y=X+3Print X-Y;Y-X(A)-3 3(B)5 -8(C)3 3(D)25 -254.下列程序段的执行结果为【 】。A="1"B="2"A=Val(A)+Val(B)B=Val("12")If A<>B Then Print A-B Else Print B-A(A)-9(B)9(C)12-12(D)05.下列程序段的执行结果为【 】。A=75If A>6O Then I=1If A>70 Then I=2If A>80 Then I=3If A>90 Then I=4Print "I="I(A)I=1(B)I=2(C)I=3(D)I=46.下列程序段的执行结果为【 】。A="abed"B="bcde"E=Right(A,3)F=Mid(B,2,3)If E<F Then Print E+F Else Print F+E(A)cdebcd(B)cdd(C)cdcd(D)bcdcde7.下列程序段的执行结果为【 】。A=75If A>60 ThenI=1ElseIf A>70 ThenI=2ElseIf A>80 ThenI=3ElseIf A>9OthenI=4EndIfPrint "I="I(A)I=1(B)I=2(C)I=3(D)I=48.下列程序段的执行结果为【 】A=1:B=OSelect Case ACase 1Select Case BCase OPrint "*O*"Case lPrint "*1*"End SelectCase 2Print "*2*"End Select(A)*O*(B)*1*(C)*2*(D)O9.下列程序段的执行结果为【 】。x=Int(Rnd+4)Select Case xCase 5Print "优秀"Case 4Print "良好"Case 3Print "通过"Case ElsePrint "不通过"End Select(A)优秀(B)良好(C)通过(D)不通过三、程序填空1. 以下程序用于判断输入的年份是否是闰年。如果年份能被4整除但不能被100整除,或者年份能被400整除,则该年为闰年;否则不是闰年。Private Sub Command1_Click()y=InputBox("请输入年份")If (1) ThenPrint y &"年为闰年"Else Print y &"年不是闰年"LEnd IfEnd Sub2. 下面的程序用于求三个数中的最大数、最小数。Private Sub Command1_Click()a=Val(InputBox("请输入第一个数")b=Val(InputBox("请输入第二个数")C=Val(InputBox("请输入第三个数")Max=aMin =aIf b> (1) Then Max=bIf b< (2) Then Min=bIf (3) Then Max=cIf (4) Then Min=cPrint "最大数为"MaxPrint "最小数为"MinEnd Sub3. 以下程序判断从文本框Text1中输入的数据,如果该数据满足条件:除以3余2,除以5余3,除以7余4, 则输出;否则将焦点定位在文本框Text1中,选中其中的确文本。Private Sub Command1_Click()x=Val(Text1.Text)If (1) Then Print xElse (2) (3) (4) End IfEnd Sub4. 下面的程序用于根据文本框A中输入的内容进行以下处理:当A<6.6时,打印"A<6.6";当A=6.6时,打印"A=6.6";当A>6.6时,打印"A>6.6"。Private Sub Command1_Click()If (1) ThenPrint "A<6.6" (2) Val(A.Text)=6.6 ThenPrint "A=6.6"ElsePrint "A>6.6" (3) End Sub5. 下面的程序用于根据文本框X中输入的内容进行以下处理:若X为2、4、6,则打印"X的值为2、4、6";若X为3、5,则打印"X的值为3、5";若X为7、8,则打印"X的值为7、8";否则,打印"X不在范围内"。Private Sub Command1_click()Select Case Val(X.Text)Case (1) Print "X的值为2、4、6"Case (2) Print "X的值为3、5"Case (3) Print "X的值为7、8" (4) Print "X不在范围内"End SelectEnd Sub6. 下面程序用来计算:A+B(A>5)N= B/A(A=5)0(A<5)Private Sub Command1_C1ick()A=Val(Text1.Text)B=val(Text2.Text)Select Case ACase (1) N=A+BCase (2) N=B/ACase (3) N=OEnd SelectText3.Text=NEnd Sub第六章 循环结构程序设计一、判断程序或程序段的执行结果1. 下列程序段的执行结果为【 】。I=0For G=10 To 19 Step 3 I=I+1Next GPrint I(A)4(B)5(C)3(D)62. 下列程序段的执行结果为【 】。X=0For K=1 To 10 Step 2 X=X+KNext KPrint K;X(A)-1 6(B)-1 16(C)1 6(D)11 313. 下列程序段的执行结果为【 】。K=0For I=1 To 3 A=IIKPrint ANext I(A)1 1 1(B)1 4 9(C)0 0 0(D)1 2 34. 下列程序段的执行结果为【 】。N=10For K=N To 1 Step -1 X=Sqr(K)X=X-2Next KPrint X-2(A)-3(B)-1(C)1(D)1.162277655. 下列程序段的执行结果为【 】。X=1Y=1For I=1 To 3 F=X+Y X=Y Y=FPrint FNext I(A)2 3 6(B)2 2 2(C)2 3 4(D)2 3 56. 下列程序段的执行结果为【 】。A="ABBACDDCBA"For I=6 To 2 Step -2X=Mid(A,I,I)Y=Left(A,I)Z=Right(A,I)Z=X & Y & ZNext IPrint Z(A)ABA(B)AABAAB(C)BBABBA(D)ABBABA7. 给出下面程序段的输出结果【 】。For X=1.5 To 5 Step 1.5Print XNext X8. 给出下面程序段的输出结果【 】。For I=-5 To Lo Step -1X=X+IPrint XNext I9. 给出下面程序段的输出结果【 】。Z="ABCDEFGABCDEFG"For I=6 To 2 Step -3U=String(I,Z)V=Left(Z,I)W=Mid(Z,I,I)X=Right(Z,I)Y=X+W+V+UNext IPrint U,V,W,X,Y10. 给出下面程序段的输出结果【 】。For I=O To 3Print Tab(4*I+1);I;"2" & INext I11. 给出下面程序段的输出结果【 】。其中,Trim函数用于去除字符串前后的空格。For I=1 To 7Print Tab(8-I);String(I,Trim(Str(I)Next I12. 下列程序段的执行结果为【 】。A=0:B=1DoA=A+BB=B+1Loop While A<10Print A;B(A)10 5(B)A B(C)0 1(D)10 3013. 下列程序段的执行结果为【 】。I=4A=5DoI=I+1A=A+2Loop Until I>=7Print "I="IPrint "A="A(A) I=4(B)I=7(C)I=8(D)I=7A=5 A=13 A=7 A=1114. 下列程序段的执行结果为【 】。N=OJ=1Do Until N>2N=N+1J=J+N*(N+1)LoopPrint N;J(A) 0 1(B)3 7(C)3 21(D)3 1315. 给出下面程序段的输出结果【 】。P=OS=0Do P=P+2S=S+PLoop While P<11Print "S="S16. 给出下面程序段的输出结果【 】。M1=1M2=1Do While M2<>6M1=M1*M2M2=M2+1Loop Print "M1="M1, "M2="M217. 下列程序段的执行结果为【 】。N=0For I=1 To 3For J=5 To 1 Step -1N=N+1Next JNext IPrint N;J;I(A) 12 0 4(B)15 0 4(C)12 3 1(D)15 3 118. 下列程序段的执行结果为【 】。A=0B=0For I=-1 To 2 Step -1For J=1 To 2 B=B+1Next JA=A+1Next IPrint A;B(A) 2 4(B)-2 2(C)4 2 (D)2 319. 下列程序段的执行结果为【 】。K=0For J=1 To 2For I=1 To 3 K=I+1Next IFor I=1 To 7 K=I+1Next INext JPrint K(A)10(B)6(C)11 (D)1620. 下列程序段的执行结果为【 】。For X=5 To 1 Step -1For Y=1 To 6-XPrint Tab(Y+5); "*"Next yPrintNext X (A)*(B)*(C)*(D) * * * * * * * * * * * * *21. 下列程序段的执行结果为【 】。S=0:T=0:U=OFor X=1 To 3For Y=1 To XFor Z=Y T0 3S=S+1Next ZT=T+1Next YU=U+1Next XPrint S;T;U(A)3 6 14(B)14 6 3(C)14 3 6(D)16 4 322. 给出下面程序段的输出结果【 】。For a=1 To 6Print Tab(7-a);For b=1 To 2*a-1Print "*"Next bNext a23. 给出下面程序段的输出结果【 】。N=1DoFor k=N To 5Print "*"Next kPrintN=N+1Loop Until N>524. 给出下面程序段的输出结果【 】。For A=O To 1For B=1 To 2For C=2 To 3Print (A=O Or B=1) And (C=2 And A=B) Or Not (C=3);Next CNext BNext A25. 给出下面程序段的输出结果【 】。Dim i As Integer,j As Integer,k As Integerk=0For i=O To 10 Step 3For j=1 To 10If j>5 Then k=k+4:Exit Fork=k+1Next jPrint I,kIf i>8 Then Exit ForNext iPrint i,k二、程序填空1. 以下程序用来产生20个(0,99)之间的随机整数,并将其中的偶数打印出来。Private Sub Command1_Click()RandomizeFor I=1 To 20X=Int(Rnd* (1) )If X/2= (2) Then Print XNext IEnd Sub2. 以下程序用来计算由键盘输入的N个数中正数之和,负数之和,正数的个数,负数的个数。其中用C累加负数之和,IC累加负数的个数,D累加正数之和, ID累明加正数的个数。Private Sub Command1_Click()N=lOC=0:IC=0:D=0:ID=OFor k=I To NA=Val(InputBox("请输入A")If A<O Then C= (1) : (2) If A>O Then D= (3) : (4) Next kPrint "负数的个数为:",ICPrint "负数的和为:",CPrint "正数的个数为: ",IDPrint "正数的和为:",DEnd Sub3. 下面是一个体操评分程序。20位评委,除去一个最高分和一个最低分,计算平均分(设满分为100分)。Private Sub Command1_Click()Max=0Min=10For I=1 To 20N=Val(InputBox("请输入分数")If (1) Then Max=NIf (2) Then Min=NS=S+NNext IS= (3) P=S/18Print "最高分"Max,"最低分"MinPrint "最后得分:"PEnd Sub4. 搬砖问题:36块砖,36人搬,男的搬4块,女的搬3块,2个小儿抬1块,要求1次全部搬完,问需男、女、小儿各多少人。Private Sub Command1_click()For Male =1 To 9For Female =1 To 12For Boy =2 To 36 Step 2If Boy + Female + Male =36 And (1) Then Print Male,Female,BoyEnd IfNext BoyNext FemaleNext MaleEnd Sub5. 以下程序用于计算N=1+(1+3)+(1+3+5)+(1+3+5+39)。Private Sub Command1_Click()T=OM=1Sum =0DoT=T + (1) Sum = Sum + (2) M=M + 2Loop While (3) Print "Sum="SumEnd Sub6. 以下程序用于计算数学表达式12-22+32-42+.+(N-1)2-N2。Private Sub Command1_Click()N=val(InputBox("请输入大于零的偶数N:")S=0I=1C=1DoS=S+C*I*IC= (1) I= (2) Loop While (3) Print "S="SEnd Sub7. 以下程序用于求S=1+3+32+33+310的值。Private Sub Command1_Click()S= (1) T=1For I=1 To 10T= (2) S=S + TNext IPrint "S="SEnd Sub8. 以下程序输入N个书名,并将书名中含有连续3个字母COM的所有书名显示出来。Private Sub Command1_Click()n=InputBox("请输入数量:")For i=1 To nbookname=InputBox("请输入书名:")l=Len (1) If l>=3 ThenIf (2) Then Print booknameEnd IfNext iEnd Sub9. 以下程序用于在带垂直滚动条的文本框Textl中输出3到100之间的全部素数。Private Sub Command1_Click()Text1.Text ="For N=3 To lOOK=Int(sqr(N)I=2Flag =ODO While I<= (1) And Flag =0If N Mod I=O Then Flag =1 Else I=I+1LoopIf (2) ThenText1.Text=Text1.Text & Str(N) & Chr(13) & Chr(10)End IfNext NEnd Sub10. 以下程序用来输出20个在开区间(10,87)中的随机整数R,每行输出4个整数。Private Sub Command1_Click()For I=1 To 20 R= (1) Print R;If (2) Then PrintNext IEnd Sub11. 以下程序在文本框Text1中输入任一字符串,并按相反的次序显示在文本框Text2中。Private Sub Command1_Click()Dim N As String,C AS String,DAS StringN=Text1.TextM= (1) For I=M To 1 Step 1C=Mid(N,I,1)D=D & (2) Next I (3) =DEnd Sub12. 以下程序用于在单击图片框Picture1时显示图6_1所示的结果。Private Sub Picture1_Click()Picture1.Print Tab(5); "*"For I=1 To 4Picture1.Print (1) Next IFor I=3 To 1 Step 1Picture1.Print (2) Next IPicture1.Print Tab(5);"*"End Sub13. 以下程序在窗体上打印出如图6_2示的数据。Private Sub Fonm_Click()For N=1 To 6Print Tab(20-3*N);For M=1 To 2*N-1If M<=N Then (1) Else (2) Print ANext MPrint Next NEnd Sub14. 单击窗体时输出"斐波那契数列"的前20项。该数列第一项为0,第二项为1,其后每一项的值都是前两项之和。即:0,1,1,2,3,5,8,13, 从题后供选择的答案中选出正确答案,填入以下程序中相应处,构成完整程序。Private Sub Fonm_Click()X1=0X2=1N=0Do While (1) Print X1,X2X1= (2) X2= (3) N=N+1LoopEnd Sub供选择的答案:(1)(A)N<10(B)N<9(C)N<10(D)N<20(2)(A)X1+X2(B)X2(C)X1+N(D)X2+N(3)(A)X1+X2(B)X2(C)X1+N(D)X2+N15. 单击窗体时输出图6_3所示的图形。从题后供选择的答案中选出正确答案,填入以下程序中相应处,构成完整程序。Private Sub Form_Click()For N=1 To 6 Print (1) For M=1 To 6 Print "*"Next MPrint (2) For M=1 To 6Print "*"Next MPrintNext NEnd Sub供选择的答案:(1)(A)Tab(6-N);(B)Tab(6+N);(C)Tab(7-N);(D)Tab(7+N);(2)(A)Tab(12+N);(B)Tab(11+N);(C)Tab(11-N);(D)Tab(12-N);16. 单击命令按钮Command1时利用台劳级数展开式求sin x 的近似值。展开式为:x-x3/3!+x5/5!-+(-1)i*x(2i+1)/(2i+1)!+ (i=0,1,2,.,n) 从题后供选择的答案中选出正确答案,填入以下程序中相应处,构成完整程序。(设在文本框Text1中输入的是角度,以上公式中的x为弧度)Private Sub Command1_Click()X1=Val(Text1.Text)X=X1*3.1415926/180N=Val(Text2.Text)Y= (1) F=1For I=1 To N (2) S=1For k=1 To (3) T=T*KS= (4) Next kF=(-1)*FY=Y+F* (5) Next IPrint "sin("X1;")="YEnd Sub供选择的答案:(1)(A)O(B)X(C)1(D)N(2)(A)T=X(B)T=0(C)T=N(D)T=1(3)(A)2*I+1(B)I+1(C)2*I(D)I(4)(A)S*K(B)S*X(C)X*N(D)S*N(5)(A)T/S(B)S*F(C)S/T(D)S/F17. 单击命令按钮Command1时利用梯形法求sinx的定积分,区间为0,2。从题后供选择的答案中选出正确答案,填入以下程序中相应处,构成完整程序。Private Sub Command1_Click()A=0B=2N=30S=0H=(B-A)/NFor k= (1) To NT=(Sin(A+(K-1)*H)+Sin(A+K*H)*H/2S= (2) Next kPrint (3) End Sub供选择的答案:(1)(A)0(B)1(C)N(D)A(2)(A)S+1(B)T(C)T+T(D)S+T(3)(A)"Area="S(B)T(C)S=S(D)K18. 单击命令按钮Command1时利用矩形法求(1+ex)的定积分,区间为0,1。从题后供选择的答案中选出正确答案,填入以下程序中相应处,构成完整程序。Private Sub Command1_Click()A=0B=1N=100X=A:H=(B-A)/NF0= (1) S=0For I=1 To NS1=F0*HS= (2) X= (3) F0=1+Exp(X)Next IPrint SEnd Sub供选择的答案:E(1)(A)0(B)1+Exp(H)(C) 1+Exp(X)(D)H(2)(A)S+1(B)S+S1(C) S+F0(D)S1(3)(A)X+H(B)X+1(C) 1+Exp(X)(D)S第 34 页-