资源描述
课后答案网,用心为你服务!
第一章 VB开发环境与VB概述 习题答案
习题
一、选择题
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
B
A
A
B
D
B
A
A
C
B
C
D
A
D
第二章 常用控件与界面设计 习题答案
习题
一、选择题
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
C
B
C
A
A
B
B
B
C
C
B
B
D
A
B
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
B
B
C
C
D
B
B
B
C
C
C
A
B
B
C
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
B
C
B
B
D
B
D
D
B
A
B
A
B
B
D
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
A
A
B
D
C
D
D
C
D
D
C
A
C
C
B
61.
B
第三章实验与习题
实验
实验3_1
‘算术运算
Private Sub Command1_Click()
Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6
Dim x As Single, y As Single, z As Single, m As Single
x = 2: y = 1: z = 1: m = 1
List1.Clear
List1.AddItem a / (b + c / b)
List1.AddItem (x + Sqr(x ^ 2 + 1)) ^ (1 / 3)
List1.AddItem ((2 * y) / (a * x + b * y) * (a * x - b * y))
List1.AddItem 1 + 1 / (1 + 1 / m)
List1.AddItem 1 / 2 * (d / 3) ^ (2 * x)
List1.AddItem Log(y + Cos(x) ^ 2)
List1.AddItem Abs((Exp(x) + Sin(x) ^ 3) / (x + y))
List1.AddItem Log((Exp(x * y) + Abs(1 / Tan(z) + Cos(x) ^ 3)) / (x + y - z))
List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10)) / Sqr(x + y + 1)
List1.AddItem Log(a) / Log(b)
End Sub
‘关系运算
Private Sub Command2_Click()
List1.Clear
List1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12)
List1.AddItem "ABCRG" >= "abcde"
List1.AddItem Int(134.69) >= CInt(134.9)
List1.AddItem 78.9 / 32.77 <= 97.5 / 43.87 And -45.4 > -4.98
List1.AddItem Str(32.345) = CStr(32.345)
End Sub
‘逻辑运算
Private Sub Command3_Click()
Dim x As Integer, y As Integer
Dim C1 As Integer, C2 As Integer, C3 As Integer
C1 = 70: C2 = 80: C3 = 90
x = 9: y = -2
List1.Clear
List1.AddItem x + y < 10 And x - y > 0
List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)
List1.AddItem x = 0 Xor y = 0
List1.AddItem C1 + C2 + C3 >= 255 Or C1 > 90 And C2 > 90 And C3 > 80
End Sub
实验3_2
略
实验3_3
略
实验3_4
‘零售结算
Private Sub Command1_Click()
Dim dj As Single, sl As Single, je As Single, n As Integer
Label1.Caption = "金额:"
dj = InputBox("请输入商品的单价:", "单价框")
sl = InputBox("请输入商品的数量:", "数量框", 1)
je = dj * sl
n = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果")
If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"
End Sub
‘产生随机数
Private Sub Command2_Click()
Dim m As Integer, n As Integer
Dim x1 As Integer, x2 As Integer, x3 As Integer
m = Val(Text1.Text): n = Text2.Text
Randomize
x1 = Int(Rnd * (n - m + 1) + m)
x2 = Int(Rnd * (n - m + 1) + m)
x3 = Int(Rnd * (n - m + 1) + m)
Label4.Caption = "结果为:" & Str(x1) & Str(x2) & Str(x3)
End Sub
‘求逆序数
Private Sub Command3_Click()
Dim a As Integer, h As Integer, t As Integer, n As Integer
Randomize
a = Int(Rnd * (999 - 100 + 1) + 100)
h = Mid(CStr(a), 1, 1)
t = Mid(CStr(a), 2, 1)
n = Right(CStr(a), 1)
Label5.Caption = a & "-->" & Format(n * 100 + t * 10 + h, "000")
End Sub
实验3_5
略
习题
选择题
1-20: DBBDB DDBCA DDDCD DBADB
21-40: DCDAA B_ACA BCADA B_BCD
41-60: BCBDC CADBA CBDDD ABAAA
61-80:BBCAB BDAAA CBBDD CBDAD
81-89:CBDBB BADC
填空题
1、2 -32768~32767
2、整型 长整型 单精度 双精度
3、0 False “”
4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))
x>0 And y>0 Or x<0 And y<0
c>=”a” And c<=”z” Or c>=”A” And c<=”Z”
x>=10 And x<20
x<z Xor y<z
5、False
2
True
False
True
True
True
True
6、188
200100
68.56
876554
7、a=1 b=1
a=2 b=1
a=3 b=1
a=4 b=1
8、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =0
9、He Said, “Good morning”.
10、EDEF
11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))
12、a+b+c+d
(a+b+c+d)/4
sum
aver
13、(f-2*h)/2
(4*h-f)/2
简答题
1、略
2、Private Sub Form_Click()
Const g = 9.8
Dim V0 As Single, t As Single
Dim S As Single
V0 = InputBox("请输入V0的值:")
t = InputBox("请输入时间t的值:")
S = (1 / 2) * g * t ^ 2 + V0 * t
MsgBox ("位移量为:" & S)
End Sub
3、Private Sub Command1_Click()
Dim l As Single, w As Single, h As Single
Dim s As Single
l = Text1.Text
w = Text2.Text
h = Text3.Text
s = (l * w + l * h + w * h) * 2
Label1.Caption = s
End Sub
第四章选择分支与循环
实验答案
实验4-1
方法一: x<=5 ; y
方法二:Is<=2 ;Case Else
实验4-2
Shape1.BackColor=vbRed;
Inter=15;
Inter=Inter-1;
Inter;
实验4-3
b<c
b=a
a=k
实验4-4
方法二: s*n ; t/s<10^-5
实验4-5
方法一:m>=10^-4 ; (-1)^(n+1)*m
实验4-6
x2=x3 ; <10^-6
实验4-7
实验4-8
i+2*j+5*k=10 ; n
实验4-9
题目一:a) 5
b)i=16 p=12 n=5
c)i=9 p=8 n=1
题目二:120 10
实验4-10
N=1 ; S=N& "*3 " & "+1 "
实验4-11
Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St
实验4-12
i\100 ; (i Mod 100)\10
习题
一、 选择题
1.C 2. C 3.A 4. D 5.A 6. B 7. B 8. D 9. B
二、填空题
1. Is=0 ; 1 To 10 ; Is >10
2. 9
3. 3 ; 4 15
4. this is a book ;This Is A Book
5. 3 ; 3 ; 3 5
6. 32 0
7. 4
8. 15 1
9. 1 ; 401 ;104
10. 1 2 3 ;1 3; 1
11. (3)
12. 2 0 24
13. 10 14
14. BAABC CBAABC
15. X Mod P=0 ; X=X+1 ;Find=False
16. abs(t)<10^(-7) ; s+t
17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1)
S=S+1
18. Mid(n,i,1)>Mid(n,i+1,1)
19. "输入n";N/I=0 ;Print I
第五章数组
实验
5_1
Int(90 * Rnd) + 10
a(i) = a(21 - i)
a(21 - i) = t
5_2
k = x Mod 10
i = i + 1
5_3
s
5_4
max < a(i, j)
row = I
col = j
5_5
1
ReDim Preserve prime(m)
prime(j)
5_6
d Mod 2
5_7
Exit For
a(j + 1) = a(j)
5_8
N – I
A(j) = A(j + 1)
5_9
A(i, 1)
J
Min = Max
Not Flag
5_10
ch >= "0" And ch <= "9"
P = P & ch
ReDim Preserve C(k)
5_11
Private Sub Form_Click()
Dim x As Integer, i As Integer, k As Integer, j As Integer
Dim a() As Integer
x = InputBox("输入正整数x=")
i = 2
Print x; "的质因子为:";
Do While x >= i
If x Mod i = 0 Then
k = k + 1
ReDim Preserve a(k)
a(k) = i
x = x \ i
Else
i = i + 1
End If
Loop
For j = 1 To UBound(a)
Print a(j);
Next j
End Sub
习题
一 选择题
1. A
2. C
3. D
4. C
5. B
6. D
7. D
8. B
9. D
10. B
11. B
12. D
二 填空题
1. Variant
2. ReDim A(N)
A(1)
If M < A(I) Then M = A(I)
3. Int(26 * Rnd) + 65
Chr(t)
i + 1 To 10
A(i) > A(j)
4. InStr(s, ",")
Right(s, Len(s) - n)
s
5. 4 5 6
6 5 4
3 2 1
6. T – 1
I + 1
7. k = 6 - i – j
max = m
8. j = a
j = j - 3
9. i + 1
i = i + 1
10. 2
3
7
三 编程题
1.
Option Explicit
Option Base 1
Private Sub Command1_Click()
Dim a(10) As Integer
Dim i As Integer, max As Integer
For i = 1 To 10
a(i) = Int(90 * Rnd) + 10
Print a(i);
Next i
Print
i = 1
max = 0
Do While i <= 10
If a(i) Mod 3 = 0 Then
If a(i) > max Then
max = a(i)
End If
End If
i = i + 1
Loop
If max = 0 Then
Print "无要找的数"
Else
Print max & "是最大的能被3整除的数"
End If
End Sub
2.
Option Explicit
Option Base 1
Private Sub Command1_Click()
Dim A() As Integer
Dim I As Integer, m As Integer
Dim K As Integer
ReDim A(10)
For I = 1 To 10
A(I) = I
Print A(I);
Next I
Print
m = InputBox("ÊäÈëm")
K = 9 + m
ReDim Preserve A(K)
For I = 11 To K
A(I) = A(I - 10)
Next I
For I = 1 To 10
A(I) = A(I + m - 1)
Next I
For I = 1 To 10
Print A(I);
Next I
Print
End Sub
3.
Option Explicit
Private Sub Command1_Click()
Dim I As Integer, J As Integer, K As Integer
Dim a() As Integer, n As Integer, p As Integer
Dim s As String, Flag As Boolean
p = 1
For K = 10 To 100
I = 1
Do While I <= 10 And Not Flag
J = 1
Do While J <= 10 And Not Flag
n = I ^ 2 + J ^ 2
If n = K Then
Flag = True
ReDim Preserve a(p)
a(p) = K
p = p + 1
s = I & Str(J) & Str(K)
List1.AddItem s
End If
J = J + 1
Loop
I = I + 1
Loop
Flag = False
Next K
End Sub
4.
Option Explicit
Private Sub Command1_Click()
Dim A(10) As Integer
Dim B(10) As Integer, S As String
Dim I As Integer, J As Integer, X As Integer
A(1) = Int(90 * Rnd) + 10
S = A(1)
For I = 2 To 10
Do
X = Int(90 * Rnd) + 10
For J = 1 To I - 1
If X = A(J) Then Exit For
Next J
If J = I Then
A(I) = X
S = S & " " & A(I)
Exit Do
End If
Loop
Next I
Text1.Text = S
B(1) = Int(90 * Rnd) + 10
S = B(1)
For I = 2 To 10
Do
X = Int(90 * Rnd) + 10
For J = 1 To I - 1
If X = B(J) Then Exit For
Next J
If J = I Then
B(I) = X
S = S & " " & B(I)
Exit Do
End If
Loop
Next I
Text2.Text = S
S = ""
For I = 1 To 10
For J = 1 To 10
If A(I) = B(J) Then
S = S & " " & A(I)
End If
Next J
Next I
Text3.Text = S
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub
5.
Option Explicit
Private Sub Command1_Click()
Dim I As Integer, J As Integer
Dim a() As Integer, K As Integer, Sum As Integer
K = Val(Text1.Text)
I = 1
Do
J = K Mod 10
ReDim Preserve a(I)
a(I) = J
Sum = Sum + J
K = K \ 10
I = I + 1
Loop Until K = 0
Text2.Text = Sum
End Sub
6.
Option Explicit
Private Sub Command1_Click()
Dim a(100, 2) As Integer, K As Integer
Dim I As Integer, J As Integer
Dim M As Integer, N As Integer
K = 1
For I = 1 To 99
For J = 1 To 99
If I > J Then
M = I - J
N = I + J
If Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) Then
List1.AddItem I & " " & J
a(K, 1) = I
a(K, 2) = J
K = K + 1
End If
End If
Next J
Next I
End Sub
第六章 参考答案
实验
实验6-1
1、 Exit Do
2、 Y(X)
3、 X >= -1
实验6-2
【题目二】42 、26、8
实验6-3
1、 s1, key
2、 s As String
3、 ch >= "a" And ch <= "z"
4、 Mid(s, i, 1) = Chr(Asc(ch) + k - 26)
思考:解密函数
Private Sub dec(s As String, k As Integer) '解密过程
Dim i As Integer, ch As String * 1
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If "A" <= ch And ch <= "Z" Then
If Asc(ch) - k < Asc("A") Then
Mid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26
Else
Mid(s, i, 1) = Chr(Asc(ch) - k)
End If
ElseIf ch >= "a" And ch <= "z" Then '多分支格式,ch介于小写a与z之间
If Asc(ch) - k < Asc("a") Then
Mid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26
Else
Mid(s, i, 1) = Chr(Asc(ch) - k)
End If
End If
Next i
End Sub
实验6-4
1、 b() As Integer, st As String
2、 L <= R
3、 ReDim Preserve b(R)
4、 L = L + 1
辗转相除法求最大公约数函数
Private Function Gcd(ByVal p As Integer, ByVal q As Integer) As Integer
Dim r As Integer
r = p Mod q
Do While r <> 0
p = q
q = r
r = p Mod q
Loop
Gcd = q
End Function
实验 6-5
【题目一】
age = age(n - 1) - 3
【题目二】
1、(Left + Right) / 2
2、Left = Mid + 1
实验6-6
1、3 -1
2、7 4
3、3 -1
4、7 0
实验6-7
【题目一】
1、 Sqr(2 + t)
2、 Abs(a - 1) < eps
【题目二】
1、 Dim X As Integer
2、 "S(" & I & ")=" & S(I)
3、 (j * i + 1)
习题参考答案
一 选择题
1~5: BDCCD 6~10:BBBAD 11~15:DAAAB
16~20:BDCDB 21~25:CCBAD 26~28:DAB
二、填空
1(1) 形式 、(2) 实在
2(1) 按地址传递 、(2) ByVal
3(1) 窗体模块 、(2) 标准模块 、(3) 类模块
4(1) 6
5(1)4 20 101
6(1) 6 26 、(2) -2 98
7(1) 10 6 、(2) 5 -5
8(1) 6 5 、(2) 8 7
9(1) 11 、(2) 7
10(1) Fun(i) 、(2) Fun=p
11(1) 4 、(2) 20.7
12(1) 29 、(2) 28.7
13(1) k = j 、(2) b() As Integer
14(1) gec 、(2) ge 、(3) 3
15(1) p1 = True And p2 = True 或 p1 And p2 、(2) p1 = p2 – 2 、
(3) Isp = True 、(4) m Mod i = 0
16(1) Convert(st) 、(2) Len(s) 、
(3) "A" To "F" 、(4) k = k + p * h
17(1) isualVi 、(2) sualVisu
18(1) s + a 、(2) n + 1 、
(3) x As Single, n As Integer 、(4) p * (x + i) / ((2 * i - 1) * i * x)
三、改错题
1、
Option Base 1
Private Sub Command1_Click()
Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean
Dim K As Integer
ReDim A(1)
A(1) = 50
———————— 'K=1
For I = 51 To 149
K = 1 '位置错
Logic = False
Call Sub1(A, I, Logic)
If Logic Then
K = K + 1
ReDim A(K) 'ReDim Preserve A(K)
A(K) = I
End If
Next I
For I = 1 To UBound(A)
Text1 = Text1 & Str$(A(I))
If I Mod 5 = 0 Then Text1 = Text1 & vbCrLf
Next I
End Sub
Private Sub Sub1(A() As Integer, N As Integer, F As Boolean)
Dim I As Integer, J As Integer, Ub As Integer
Ub = UBound(A)
For I = 1 To Ub
For J = 2 To A(I)
If A(I) Mod J = 0 And N Mod J = 0 Then
Exit For 'Exit Sub
End If
Next J
F = True
Next I
End Sub
2、
Option Explicit
Option Base 1
Private Sub Command1_Click()
Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As Integer
Dim J As Integer, K As Integer, P() As Integer
ReDim P(1)
P(1) = 2
For I = 3 To 150 Step 2
For J = 2 To Sqr(I)
If I Mod J = 0 Then Exit For
Next J
If J > Sqr(I) Then
ReDim Preserve P(UBound(P) + 1)
P(UBound(P) + 1) = I 'P(UBound(P)) = I
End If
Nex
展开阅读全文