VB实验教材的实验与习题答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VB实验教材的实验与习题答案
第一章VB开发环境与VB概述习题答案习题
一、选择题
第二章常用控件与界面设计习题答案
习题
一、选择题
第三章实验与习题
实验
实验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 = V al(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 DB A DB
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<="">
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)
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< p="">
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
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
</c<>。

相关文档
最新文档