VB考试题(急)请高手指教3

1. 执行下列的程序段,得到的X的值为
Dim x As String
n = Int(Rnd)*10
Select Case n
Case 10
x = “ 优 ”
Case 9
x = “ 良 ”
Case 8
x = “ 合格 ”
Case Else
x = “ 不合格 ”
End Select

2. 执行下列的程序段,得到的X的值为
Dim x As String
For i = 1 to 3
x = 4
For j = 1 to 4
x = x + 5
Next j
Next i

3. 执行下列的程序段,得到的X的值为
Dim A As String, B As Long, C As Double
A = 100.1; B = 200.2; C = 300.3
X = A + B + C

4. 执行下列的程序段,得到的X的值为
Dim a(10) As integer,p(3) As integer
x = 0
For i = 1 to 10
a(i) = i + 1
Next i
For i = 1 to 3
p(i) = a (i*i)
Next i
For i = 1 to 3
x = x + p(i) * 2
Next i

5. 执行下列的程序段,输出的结果为
Public Sub Swap1(ByVal x As Integer, ByVal y As Integer)
Dim t As Integer
t=x : x=y : y=t
End Sub
Public Sub Swap2(x As Integer,y As Integer)
Dim t As Integer
t=x : x=y : y=t
End Sub
Private Sub Command1_Click()
Dim a As Integer, b As Integer
a=10: b=20
Swap1 a , b
Swap2 a,b
Print a,b
End Sub

第一题
因为int将括号里的随机数转换为整型 随机数是小于1的浮点数 而又因为int有个怪毛病 逢单不四舍五入 逢双才四舍五入 如:Int(0.5)=0
int(1.5)=2 所以这题X值为 不及格
第二题
Dim x As String
For i = 1 To 3 '
x = 4 '外层循环每次都重新赋值x的值~所以只看外层最后一次循环
For j = 1 To 4
x = x + 5 '循环4次~X初始值为4 加了4次5 所以X终止值为24
Next j
Next i
Print x

第三题
'这题注意的是A变量为字符串型~ 而B为长整型 200.2是浮点数所以B值为200
'字符串和数值 用+号连接 那么+号就不是字符串连接符了 应用作数值相加 所以X值为600.4

第四题

Dim a(10) As Integer, p(3) As Integer
x = 0
For i = 1 To 10
a(i) = i + 1
Next i
'a(1)=2
'a(2) = 3
'...
'a(10)=11
For i = 1 To 3
p(i) = a(i * i)
'p(1)=a(1*1)=2
'p(2)=a(2*2)=a(4)=5
'p(3)=a(9)=10
Next i
For i = 1 To 3
x = x + p(i) * 2
'这个循环里初始值X=0 ~循环第一次时x=x+2*2 X=4
'第二次 x=4+p(2)*2=4+5*2=14
'第三次 x=14+ p(3)*2=14+10*2=34 所以X=34
Next i

第五题

Public Sub Swap1(ByVal x As Integer, ByVal y As Integer)
Dim t As Integer
t = x: x = y: y = t
End Sub
Public Sub Swap2(x As Integer, y As Integer)
Dim t As Integer
t = x: x = y: y = t
End Sub
Private Sub Command1_Click()
Dim a As Integer, b As Integer
a = 10: b = 20
Swap1 a, b '调用 自定义过程swap1 因为该过程2个变量都是ByVal按值传递 所以
'经过t = x: x = y: y = t这样的对调后 a,b值保持不变
Swap2 a, b '这里的a,b依旧是10和20 因为Swap2 2个参数 没写传参的方式 默认就为ByRef按地址 会改变变量原有的值
'同样的t = x: x = y: y = t这样的对调后 a,b值就改变了
Print a, b '所以结果为在窗体上打印出20 10
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-03-21
1 不合格
2 24
3 600.4
4 34
5 20 10
相似回答
大家正在搜