(3) (4) (5) (6) (7) (8) (9) (10) (11) (12)
试题7(28分)
√ √ √ √ √ √ √ √ √ √ (15) (16) (17) (18) (19) (20) (21) (22) (23) (24) √ √ √ √ √ √ √ √ √ √ Dim a() As Single, n As Integer Private Sub Form_Load()
Command1.Caption = \数据输入\分) Command2.Caption = \计算\分) End Sub
Private Sub Command1_Click() '数据输入
Dim i As Integer (2分) n = Text1.Text (2分) ReDim a(n) (3分) For i = 1 To n
a(i) = InputBox(\分) Next i End Sub
Private Sub Command2_Click()
Dim y As Single, i As Integer, x As Single (1分) x = Text2.Text (1分) y = a(1) (1分) For i = 2 To n
y = y + a(i) * x ^ (i - 1) (7分) Next i
Label3.Caption = y (2分) End Sub
2007年春浙江省高等学校计算机等级考试参考答案(二级 VB)
试题1~6 (每小题3分)
⑴ B ⑵ A ⑶ D ⑷ C ⑸ D ⑹ C ⑺ B ⑻ A ⑼ A ⑽ B ⑾ B ⑿ D ⒀ A ⒁ A ⒂ D ⒃ B ⒄ D ⒅ C ⒆ C ⒇ B (21)C (22)A (23)A (24)D 试题7 (28分)
Private Function sum(Byval n As Integer) As Integer sum=0: n=Abs(n) while n>0
sum = sum + n mod 10: n=n\\10 Wend
End Function
Private Sub Command1_Click()
Dim a(10) As Integer, b(10) As Integer, i As Integer For i = 1 To 10
a(i) = InputBox(\ Next i
For i=1 To 8: Printf a(i); \ Print
For i=1 To 8: Printf b(i); \End Sub
VB上机考试程序调试题样题(填空)参考答案
[题1] [题2] [题3] [题4] [题5] [题6] [题7] [题8] [题9] 1. dalt>0 2. dalt=0 3. Sqr(-dalt) 1. start = Space(21 - i) 2. Count = 19 - 2 * i 3. Form1.Print start; 4. Form1.Print 1. 5 2. num 3. Trim(i); 1.number(i) 2.n as integer 3.number=number*10+7 1. 1 2. -1 3. x=(x+1)*2 1. 2 2. b = False 3. k = k + 1 4. b 或 b = True 1.do while x<4 or x mod 2<>0 2.if isprime(i) and isprime(x-i) then 3.isprime=true 4.if x mod I=0 then 1. n+1 2. n Mod 3=1 and n Mod 5=1 and n Mod 7=1 3. While countN<5 1. Not isLeapYear(year) 2. y Mod 4 <> 0 3. y Mod 100 = 0 4. y Mod 400 <> 0 [题10] [题11] [题12] [题13] [题14] [题15] [题16] [题17] [题18] [题19] [题20]
1.trim(str(i)) 2.trim(str(i^2)) 3.x1=right(x2,len(x1)) 1. i\\100 2. i mod 10 3.i=hundred^3+ten^3+one^3 1. i,n 2.if i=s then 3.for I=2 to x-1或for i=2 to x\\2 4.a(k)=i 1. s = 1 2. Do While s < 1E+16 3. i = i + 1 1. s < 1000 2. x 3. n + 1 4. n - 2 1.sign=-1 2.19 3.sign=-sign 1.temp=1 2.temp 3.nfactor(i) 4.sum 1. 1 To Len(a) 2. n + fact(p) 3. fact = y 1.len(oldsen) 2.lastchar=\1. salary(i) 2. temp - hundred * 100 3. temp 4. totalsalary + salary(i) 1.Len(str1) 2.length-1 3.mid(str1,I,2) 4.sum=0 VB上机考试程序调试题样题(改错)参考答案
[题1] [题2] [题3] [题4] [题5] [题6] [题7] 1.for i=9 to 1 step –1 2. Form1.Print Trim(Str(i)); 3. End Sub 1.for two=1 to n-one 2.if one+two*2+five*5=60 then 3.next two 4.next one 1.dim k as single 2.for i=1 to 100 step2 3.k=-1/(i+1) 1.cmn=nfactor(m)/(nfactor(n)*nfactor(m-n)) 2.nfactor=temp 3.End function 1.length=len(str1) 2. strright=mid(str1,k,1) 3. strleft=mid(str1,length-k+1,1) 4. If strleft <>strright Then 1.case is>r 2.Loop until times>5 或 Loop While times <= 5 3.Form1.print “正确答案为”& str(r) 1.n=len(Hex) 2.temp=Mid(Hex,n-i,1) 3.Form1.print Hex + “转换为十进制数为” + str(Dec) 或 Form1.print Hex & “转换为十进制数为” & Dec 或Form1.print Hex ;“转换为十进制数为” ; Dec 1. For i = 0 To 9 2. n = Int(Rnd * 90) + 10 3. MsgBox \偶数个数:\1.a(i)=int(Rnd*100) 2.p=a(i) mod 10 3.x(p)=x(p)+1 4.Form1.print “个位数为”+str(p)+”共”+str(x(i)) + \个\1.Swap a(j),a(i) 2.Loop while i
1. 新建一个工程,完成“加法器”程序的设计。 参考答案:
Private Sub Command1_Click()
Text3.Text = Str(Val(Text1.Text) + Val(Text2.Text)) End Sub
Private Sub Command2_Click() Text1.Text = \ Text2.Text = \ Text3.Text = \ Text1.SetFocus End Sub
Private Sub Form_Load()
Form1.Caption = \加法器\ '文本框清空 Text1.Text = \ Text2.Text = \ Text3.Text = \ '设置文本框右对齐 Text1.Alignment = 1 Text2.Alignment = 1 Text3.Alignment = 1 '屏蔽对Text3的编辑 Text3.Locked = True Label1.Caption = \ Command1.Caption = \=\ Command2.Caption = \清空\End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48) Or (KeyAscii > 57) Then KeyAscii = 0 End If End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer) If (KeyAscii < 48) Or (KeyAscii > 57) Then KeyAscii = 0 End If End Sub
2. 新建一个工程,完成“健康称”程序的设计。具体要求如下: 参考答案:
Private Sub Command1_Click() Dim bzh As Single
bzh = Val(Text1.Text) - 105
If Val(Text2.Text) > bzh * 1.1 Then
Label5.Caption = \偏胖,注意饮食\
ElseIf Val(Text2.Text) < bzh * 0.9 Then Label5.Caption = \偏瘦,增加营养\ Else
Label5.Caption = \正常,继续保持\ End If End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then '输入非数字 KeyAscii=0 End If End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then '输入非数字 KeyAscii=0 End If End Sub
3. 新建一个工程,完成应用程序的设计,具体要求如下:
参考答案:
Private Sub Command1_Click() If Form1.WindowState = 0 Then Command1.Caption = \最小化(&B)\Form1.WindowState = 2
Command1.Left = (Form1.Width - Command1.Width) / 2
Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2 Else
Form1.WindowState = 0
Command1.Caption = \最大化(&L)\
Command1.Left = (Form1.Width - Command1.Width) / 2
Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2 End If End Sub
(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)



