2007年秋江苏省计算机等级考试二级VB考试真题及答案

第二部分 Visual Basic 程序设计

一、 选择题(用答题卡答题,答案依次填在21~30答题号内)

21.下列语句中,正确的是 21 。

A. Text1.SetFocus B. Form1.Clear C. Label1.SetFocus D. List1.Cls
转贴请注明 : www.pghome.net
22.创建一个名为“文件”的菜单项,使其可用Alt+F方式访问,则在菜单编辑器的标题文本框中应输入 22 。

A. 文件($F) B. 文件(&F) C. 文件(#F) D. 文件(%F)

23.数学表达式的VB算术表达式为 23 。

A. Sin(27) + Sqr(x + Exp3)/(x + y)

B. Sin(27 * 3.14159 / 180) + Sqr(x + Exp(3)) / Abs(x + y)

C. Sin(27 * 3.14159 / 180) + Sqr(x + e ^ 3) / Abs(x + y)

D. Sin(27 * pi / 180) + Sqr(x + Exp(3) / Abs(x + y)

24.以下说法不正确的是 24 。

A. 使用不带关键字Preserve的ReDim语句可以重新定义数组的维数

B. 使用不带关键字Preserve的ReDim语句可以改变数组各维的上、下界

C. 使用不带关键字Preserve的ReDim语句可以改变数组的数据类型

D. 使用不带关键字Preserve的ReDim语句可以对数组中的所有元素进行初始化

25.下列 25 是合法的变量名。

A. abs B. -a1 C. cdc d D. Abc_10

26.要向文件data.txt添加数据,正确的文件打开命令是 26 。

A. Open data1.txt For Output As #1 B. Open data1.txt For Input As #1

C. Open data1.txt For Append As #5 D. Open data1.txt For Write As #5

27. 以下对数组参数的说明中,错误的是 27 。

A. 在过程中可以用Dim语句对形参数组进行声明 B. 形参数组只能按地址传递

C. 实参为动态数组时,可用ReDim 语句改变对应形参数组的维界

D. 只需把要传递的数组名作为实参,即可调用过程

28.设a = 3,b = 2,c = 1,运行print a > b > c的结果是 28 。

A. True B. False C. 1 D. 出错

29.能够将任意一个两位整数X的个位数与十位数对调(例如将78 转换为87)的表达式是 29 。

① Val(Right(X, 1) & Left(X, 1))

② Val(Right(Str(X), 1) & Left(Str(X), 1))

③ Val(Right(CStr(X), 1) & Left(CStr(X), 1))

④ Val(Mid(X, 2, 1) + Mid(X, 1, 1))

A. ③ B. ②③ C. ①④ D. ①③④

30.下列 30 是正确的VB常量。

A. D-6 B. E-6 C. 5D D. 5E-6

二、 填空题(请将答案填写在答题纸的相应答题号内,每个答案只占一行)

1.执行下面程序,单击Command1,则窗体上显示的第一行是 (1) ,第二行是 (2) ,第三行是 (3) 。

Option Explicit

Private Sub Command1_Click()

Dim a As String, i As Integer

Dim x As String, z As String

a = iamstudent

i = InStr(5, a, d)

Do

x = Mid(a, i, 3)

z = Right(x, 1)

z = UCase(x & z)

i = i - 2

Print z

Loop Until i = 1

End Sub

2. 执行以下程序,单击Command1,则在Picture1上显示的第一行是 (4) ,第二行是

(5) ,第三行是 (6) 。

Option Explicit

Private Sub Command1_Click()

Dim A(3, 3) As Integer, i As Integer, j As Integer

Dim k As Integer

i = 3 : j = 2 : A(i, j) = 1 : k = 1

Do Until k > 9

k = k + 1

If i + 1 > 3 And j + 1 <= 3 Then

i = 1 : j = j + 1

ElseIf i + 1 <= 3 And j + 1 > 3 Then

i = i + 1 : j = 1

ElseIf i + 1 > 3 And j + 1 > 3 Then

i = i - 1

ElseIf i + 1 <= 3 And j + 1 <= 3 And A(i + 1, j + 1) <> 0 Then

i = i - 1

Else

i = i + 1 : j = j + 1

End If

A(i, j) = k

Loop

For i = 1 To 3

For j = 1 To 3

Picture1.Print A(i, j)

Next j

Picture1.Print

Next i

End Sub

3. 执行下面的程序,单击Command1,则窗体上第一行显示的是 (7) ,第二行显示的是

(8) 。

Option Explicit

Dim x As Integer

Private Sub Command1_Click()

Dim y As Integer

x = 10 : y = 2

Call process(y)

Print x, y

Call process((y))

Print x, y

End Sub

Private Sub process(n As Integer)

Dim y As Integer

If n > 0 Then

x = x - n

y = x

Else

x = x + n

y = x + 2

End If

n = -n

End Sub

4.执行下面的程序,连续三次单击命令按钮Command1之后,A数组共有 (9) 个元素;数组元素A(2)的值是 (10) ,A(4)的值是 (11) 。

Option Explicit

Option Base 1

Private Sub Command1_Click()

Static A() As Integer, n As Integer

Dim i As Integer, k As Integer

k = n

n = n + 2

ReDim Preserve A(n)

For i = k + 1 To n

A(i) = i * n + 1

Next i

For i = 1 To n

Print A(i)

Next i

Print

End Sub



5.执行下面的程序,单击Command1,在窗体界面上显示的第一行是 (12) ,第二行是

(13) ,第三行 (14) ,第四行是 (15) 。

Option Explicit

Private Sub Command1_Click()

Dim a As Integer, b As Integer, i As Integer

i = 1218

a = i \ 100

b = i Mod 100

If b <> 0 Then

Print a

Print b

Print Lcd((a), (b)) a b

Print Lcd(a, b) a b

End If

End Sub



Private Function Lcd(x As Integer, y As Integer) As Integer

Dim d As Integer

If x < y Then

d = x : x = y : y = d

End If

d = x

Do

If x Mod y = 0 Then

Lcd = x

Exit Do

Else

x = x + d

End If

Loop

End Function

6.本程序的功能是利用无穷级数求cos(x)的近似值。已知:


当第n项的绝对值小于等于10-7,计算终止。

Option Explicit

Private Sub Command1_Click()

Dim x As Single, n As Integer, sum As Single

Dim a As Single

x = Text1

(16)

a = 1

n = 1

Do

a = -a

a = (17)

sum = sum + a

n = n + 1

Loop Until (18)

Text2 = sum

End Sub

7.下面程序的功能是求一个4×4方阵的范数。方阵的数值是随机生成的-20~20之间的整数。方阵范数是指方阵各列元素的绝对值之和中的最大的数值。

Option Explicit

Option Base 1

Private Sub Command1_Click()

Dim a(4, 4) As Integer

Dim i As Integer, j As Integer

For i = 1 To 4

For j = 1 To 4

a(i, j) = (19)

Picture1.Print Right( & Str(a(i, j)), 4)

Next j

Picture1.Print

Next i

Text1.Text = (20)

End Sub

Private Function fan(a() As Integer) As Integer

Dim b(4) As Integer, max As Integer

Dim i As Integer, j As Integer

For i = 1 To 4

For j = 1 To 4

b(j) = (21)

Next j

Next i

max = b(1)

For i = 2 To 4

If max < b(i) Then max = b(i)

Next i

fan = max

End Function

8.下面程序的功能是,找出仅由数字1、2、3、4组成的4位素数,要求每个素数由4个不同数字组成。算法提示:函数Validate用于验证一个4位数是否由4个不同数字组成。在函数中用A数组的各个元素分别对应数字0~9,只要某数字出现在四位数中,无论几次,均将该数字对应的数组元素值置为1。

Option Explicit

Private Sub Command1_Click()

Dim i As Integer, Flg As Boolean

For i = 1234 To 4321

(22)

Call Prime(i, Flg)

If Flg Then

If Validate(i) Then

Text1 = Text1 & i & vbCrLf

End If

End If

Next i

End Sub

Private Sub Prime(n As Integer, f As Boolean)

Dim k As Integer

For k = 2 To Sqr(n)

(23)

Next k

f = True

End Sub

Private Function Validate(n As Integer) As Boolean

Dim A(0 To 9) As Integer, s As String, i As Integer

Dim s1 As String * 1

(24)

For i = 1 To Len(s)

s1 = Mid(s, i, 1)

(25)

Next i

If A(1) + A(2) + A(3) + A(4) = 4 Then

(26)

End If

End Function

9.下面程序的功能是:首先生成一个由小到大已排好序的整数数组,再输入一个数据,单击“插入”按钮,会自动把这个数据插入到原数组适当的位置,并保持数组的有序性。

Option Explicit

Dim a() As Integer

Private Sub Form_Activate() 生成有序数组

Dim i As Integer

ReDim a(10)

For i = 1 To 10

a(i) = (i - 1) * 10 + 1

Text1 = Text1 & Str(a(i))

Next i

Text2.SetFocus

End Sub

Private Sub Command1_Click()

Dim n As Integer, i As Integer

n = Text2

For i = 1 To UBound(a)

If (27) Then Exit For 确定插入的位置

Next i

(28)

For i = 1 To UBound(a)

Text3 = Text3 & Str(a(i))

Next i

End Sub



Private Sub inst(p() As Integer, n As Integer, k As Integer) 数组元素移位并实现插入

Dim i As Integer

(29)

For i = UBound(p) - 1 To k Step -1

(30)

Next i

p(k) = n

End Sub




--------------------------------------------------------------------------------
  相关文章
没有相关文章
Google
分类: 二级 日期:2008-10-17 查看:1