第1章 VB开发环境与VB概述 习
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
答案
习题
一、选择题
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
B
A
A
B
D
B
A
A
C
B
11.
12.
13.
14.
C
D
A
D
第2章 常用控件与界面
设计
领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计
习题答案
习题
一、选择题
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
C
B
C
A
A
B
B
B
C
C
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
B
B
D
A
B
B
B
C
C
D
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
B
B
B
C
C
C
A
B
B
C
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
B
C
B
B
D
B
D
D
B
A
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
B
A
B
B
D
A
A
B
D
C
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
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.
2.
3.
4.
5.
6.
7.
8.
9.
10.
D
B
B
D
B
D
D
B
C
A
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
D
D
D
C
D
D
B
A
D
B
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
D
C
D
A
A
B
A
A
C
A
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
B
C
A
D
A
B
B
B
C
D
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
B
C
B
D
C
C
A
D
B
A
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
C
B
D
D
D
A
B
A
A
A
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
B
B
C
A
B
B
D
A
A
A
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
C
B
B
D
D
C
B
D
A
D
81.
82.
83.
84.
85.
86.
87.
88.
89.
C
B
D
B
B
B
A
D
C
填空题
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
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=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、 选择题
1.
2.
3.
4.
5.
6.
7.
8.
9.
C
C
A
D
A
B
B
D
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.
2.
3.
4.
5.
6.
7.
8.
9.
10.
A
C
D
C
B
D
D
B
D
B
11.
12.
B
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.
2.
3.
4.
5.
6.
7.
8.
9.
10.
B
D
C
C
D
B
B
B
A
D
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
D
A
A
A
B
B
D
C
D
B
21.
22.
23.
24.
25.
26.
27.
28.
C
C
B
A
D
D
A
B
二、填空
1(1)
形式 、(2) 实在
2(1)
按地址传递 、(2) ByVal
3(1)
窗体模块 、(2)
标准
excel标准偏差excel标准偏差函数exl标准差函数国标检验抽样标准表免费下载红头文件格式标准下载
模块 、(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
Next I
For I = 80 To 125
If fun(I, P, S1, S2) Then
'If fun(I, P, S1, S2)
Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf
End If
Next I
End Sub
Private Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean
Dim I As Integer, J As Integer
For I = 1 To UBound(P)
For J = 1 To UBound(P) - 1
If N = P(I) * P(J) Then
S1 = P(I)
S2 = P(J)
'fun = True
Exit Function
fun = True
'位置错
End If
Next J
Next I
End Function
3、
Option Explicit
Private Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByVal idx As Integer
Dim Ub As Integer, Counter As Integer, K As Integer
Ub = UBound(Chess)
Chess(idx) = 0
Counter = 1
K = 0
'位置错
Do Until Counter = Ub - 1
Do Until K = 2
idx = idx + 1
If idx > Ub Then idx = 1
K = K + Chess(idx)
Loop
Chess(idx) = 0
Counter = Counter + 1
Loop
For Over = 1 To Ub
If Chess(Over) <> 0 Then Exit For
Next Over
End Sub
Private Sub Command1_Click()
Dim Chess(32) As Integer, I As Integer, J As Integer
Dim K As Integer, idx As Integer
For I = 1 To 32
For J = 1 To 32
Chess(J) = 1
Next J
Call Get_Chess(Chess, I, K)
If K = 23 Then
Text1 = "从第" & Str$(I) & "号棋子开始取"
Exit For
End If
Next I
End Sub
5、
Option Explicit
Private Sub Form_Click()
Dim S As String, Flg As Boolean
Do
S = InputBox("输入一个自然数")
If S = "" Or Not IsNumeric(S) Then
MsgBox "请重新输入", 48 + vbOKOnly
Else
Exit Do
End If
Loop
judge(S, Flg)
' Call judge(S, Flg) 或 judge S, Flg
If Flg Then
Print S; "是回文数"
Else
Print S; "不是回文数"
End If
End Sub
Private Sub judge(Ch As String, F As Boolean)
Dim L As Integer, I As Integer
L = Len(Ch)
F = True
' F = False
For I = 1 To L
If Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub
Next I
F = False
' F = True
End Sub
四、编程题
1、编程验证任一大于2的偶数可以
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
示成两个素数之和。
Private Function Prime(a As Integer) As Boolean
Dim i As Integer
For i = 2 To Sqr(a)
If a Mod i = 0 Then Exit Function
Next i
Prime = True
End Function
'方法一
Private Sub Command1_Click()
Dim m As Integer, i As Integer
m = InputBox("请输入一个大于2 的偶数")
If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub
If Prime(2) And Prime(m - 2) Then
Print m & "=2 +" & m - 2
Else
Do
i = i + 1
If Prime(2 * i + 1) And Prime(m - (2 * i + 1)) Then
Print m & "=" & 2 * i + 1 & "+" & m - (2 * i + 1)
Exit Do
End If
Loop While 2 * i + 1 < m - (2 * i + 1)
End If
End Sub
'方法二
Private Sub Command2_Click()
Dim m As Integer, i As Integer, p() As Integer, n As Integer
Dim flg As Boolean
m = InputBox("请输入大于2的偶数")
If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub
ReDim p(1)
p(1) = 2
n = 1
For i = 3 To m - 2 Step 2
If Prime(i) Then
n = n + 1
ReDim Preserve p(n)
p(n) = i
End If
Next i
For i = 1 To n
For j = 1 To n
If p(i) + p(j) = m Then
Print m & "=" & p(i) & "+" & p(j)
flg = True
Exit For
End If
Next j
If flg = True Then Exit For
Next i
End Sub
2、求组合数
(n>=m),程序中必须包含一个求阶乘的通用过程。
Private Function Fact(a As Integer) As Long
If a = 0 Or a = 1 Then
Fact = 1
Else
Fact = a * Fact(a - 1)
End If
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Integer, result As Single
n = Val(Text1.Text)
m = Val(Text2.Text)
If n >= m Then
resul