计算机等级 > 二级考试 > Visual Basic > VB模拟试题 > 文章内容

全国计算机二级考试VB程序设计复习试题答案(20)

2016-6-25编辑:ljnbset

1.       Command1_Click( )事件程序的功能是:按顺序读入10名学生4门课程的成绩,计算出每位学生的平均分并输出,程序如下:

Dim n As Integer, k As Integer

Dim score As Single, sum As Single, ave As Single

sum = 0#

For n = 1 To 10

  For k =1 To 4

score = InputBox(“请输入第” & n & “名学生第” & k & “门课的成绩:”)

sum = sum + score

                Next k

                ave = sum / 4

            Print “第” & n & “个学生的平均成绩为:” & ave

            Next n

上述程序运行后结果不正确,调试中发现有一条语句出现在程序中的位置不对。这条语句是(   )

Asum = 0#                             (B)sum = sum + score

(C)ave = sum / 4                      (D)Print “第” & n & “个学生的平均成绩为:” & ave

2.       在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:

            Private Sub Command1_Click( )

                Dim num As Integer

                num = 1

                Do Until num > 6

                   Print num;

                   num = num + 2.4

                Loop

            End Sub

  程序运行后,单击命令按钮,则窗体上显示的内容是(   )

(A)1 3.4 5.8                        B1 3 5

(C)1 4 7                              (D)无数据输出

3.       以下程序的输出结果是(   )

            Dim i As Integer, a As Integer

            Do While i < 20

                Do While True

                   If i Mod 10 = 0 Then

                       Exit Do

                   Else

                       i = i -1

                   End If

                Loop

                i = i + 11 : a = a + i

         Loop

         Print a

(A)21                  B32                      (C)33                      (D)11

4.       在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按钮,然后编写如下程序:

         Private Sub Command1_Click( )

            Dim array1(10,10) As Integer

            Dim i, j As Integer

            For i = 1 To 3

                For j = 2 To 4

                   array1(i,j) = i + j

                Next j

            Next i

            Text1.Text = array1(2,3) + array1(3,4)

         End Sub

  程序运行后,单击命令按钮,在文本框中显示的值是(   )

A12                  (B)13               (C)14                      (D)15

5.       设有如下程序:

Option Base 0

Private Sub Form_Click( )

  Dim a

  Dim i As Integer

  a = Array(1,2,3,4,5,6,7,8,9)

  For i = 0 To 3

    Print a(5 – i);

            Next

         End Sub

程序运行后,单击窗体,则在窗体相显示的内容是(   )

(A)4 3 2 1    (B)5 4 3 2              C6 5 4 3              (D)7 6 5 4

6.       在窗体上画一个名称为Command1的命令按钮,然后编写如下代码:

Option Base 1

Private Sub Command1_Click( )

  d = 0

  c = 10

  x = Array(10, 12, 21, 32, 24)

  For i = 1 To 5

If x(i) > c Then

  d = d + x(i)

  c = x(i)

Else

  d = d – c

End If

            Next i

            Print d

         End Sub

程序运行后,单击命令按钮,则在窗体上输出的内容是(   )

(A)89                  (B)99                C23                         (D)77

7.       假定有以下函数过程:

Function Fun(S As String) As String

  Dim s1 As String

  For i = 1 To Len(S)

s1 = Ucase(Mid(S, i, 1)) + s1

            Next i

            Fun = s1

         End Function

在窗体上画一个命令按钮,然后编写如下事件过程:

         Private Sub Comman1_Click( )

            Dim Str1 As String, Str2 As String

            Str1 = InputBox(“请输入一个字符串:”)

            Str2 = Fun(Str1)

            Print Str2

         End Sub

程序运行后,单击命令按钮,如果在输入对话框中输入字符串“abcdefg”,则单击“确定”按钮后在窗体上输出的结果为(   )

(A)abcdefg          (B)ABCDEFG         Cgfedcba      (D)GFEDCBA

8.       在窗体上画一个名称为Command1的命令按钮和一个名称为Text1的文本框,然后编写如下代码:

         Private Sub Command1_Click( )

            Dim x, y, z As Integer

            x = 5

            y = 7

            z = 0

            Text1.Text = “”

            Call P1(x, y, z)

            Text1.Text = Str(z)

         End Sub

         Sub P1(ByVal a As Integer, ByVal b As Integer, c As Integer)

            c = a + b

         End Sub

程序运行后,如果单击命令按钮,则在文本框中显示的内容是(   )

(A)0                    B12               (C)Str(z)                 (D)没有显示

9.       以下关于过程的叙述中错误的是(   )

(A)      如果过程被定义为Static类型,则该过程中的局部变量都是Static类型

(B)      Sub过程中不能嵌套定义Sub过程

(C)     Sub过程中可以嵌套调用Sub过程

(D)     事件过程可以像通用过程一样由用户定义过程名

10.   在窗体上画一个名称为Command1的命令按钮,再画两个名称分别为Label1、Label2的标签,然后编写如下程序代码:

         Private X As Integer

         Private Sub Command1_Click( )

            X = 5: Y = 3

            Call proc(X, Y)

            Label1.Caption = X

            Label2.Catpion = Y

         End Sub

         Private Sub proc(Byval a As Integer, ByVal b As Integer)

            X = a * a

            Y = b + b

         End Sub

单击命令按钮,两个标签中显示的内容分别是(   )

(A)5和3             B253               (C)25和6               (D)5和6

全国计算机二级考试VB程序设计复习试题答案(19)

热点推荐

登录注册
触屏版电脑版网站地图