《VB语言程序设计 实验指导与习题解答》这本书的测试题的答案在哪里?急求啊
发布网友
发布时间:2022-05-02 01:13
我来回答
共1个回答
热心网友
时间:2023-10-08 23:23
《VB语言程序设计》习 题 参 考 答 案
第1章习题
一、单选题
1.D 2.B 3.C 4.A 5.C 6. A
7.A 8.B 9.C 10.(1)A (2)B
二、多选题
1.ACDE 2.BCDE 3.CD 4. CE
三、填空题
1.事件驱动 2.解释,编译 3.设计,运行,中断
4. 属性,方法,事件 5. Command2_Click 6. *,代码
7.MyForm.frm 8. (1)Cmd1_Click() (2)Print "VB语言程序设计"
编程及上机调试
1. 按要求设置窗体属性
2.在窗体上建立一个标签Label1。程序代码如下:
Private Sub Form_Click()
Label1.Caption = "你单击了窗体"
End Sub
Private Sub Form_DblClick()
Label1.Caption = "你双击了窗体"
End Sub
3. 在窗体上建立两个文本框Text1(输入数)、Text2(输出数)和一个命令按钮Command1。两个文本框的Text属性均为空。
Private Sub Command1_Click()
Dim x As Single
x = Val(Text1.Text)
Text2.Text = 15 * x
End Sub
第2章习题
一、单选题
1.①D,②D 2.①A,②C 3.A 4.B5.B 6.B
7.C 8.D 9.B 10.B 11.A 12.A
13.B 14.A 15.B 16.A 17.B
二、多选题
1.BD 2.CD 3.AC 4. AD
三、填空题
1.(1) Sin(50*3.14159/180) (2) (2+x*y)/(2–y*y)
(3) a*a–3*a*b/(3+a) (4) x^(3/8)+Sqr(y*y+4*a*a/(x+y^3))
2.Int(50+6*Rnd)
3.(1)138 (2)3 (3)214 (4) "inchina" (5)70 (6) "45"
(7)0
4. "系统管理数据库"
编程及上机调试
1~3题:按要求完成操作练习。
4. Private Sub Command1_Click() '"最大化"按钮
Form1.WindowState = 2 '最大化
End Sub
Private Sub Command2_Click() '"还原"按钮
Form1.WindowState = 0 '还原
End Sub
Private Sub Command3_Click() '"最小化"按钮
Form1.WindowState = 1 '最小化
End Sub
5.在窗体上建立三个文本框Text1(第一个数)、Text2(第二个数)、Text3(计算结果)和一个命令按钮Command1(“计算”)。
Private Sub Command1_Click()
Dim x As Single
Dim y As Single
x = Val(Text1.Text)
y = Val(Text2.Text)
Text3.Text = x * x + y * y
End Sub
6. 在窗体上建立两个文本框Text1(输入一串字符)、Text2(输出结果)和一个命令按钮Command1。
Private Sub Command1_Click()
Dim x As String
x = Left(Text1.Text, 1) + Right(Text1.Text, 1)
Text2.Text = x
End Sub
第3章习题
一、单选题
1.C 2.B 3.D 4.D 5.B 6.C
7.B 8.D 9.D 10.A 11.A 12.C
13.C 14.B 15.(1)A (2)C 16.A 17.B
18.(1)D (2)B (3)C 19.D
二、多选题
1.AC 2.AC 3.ABCF
三、填空题
1. $000,124 2.Label1.Caption="a*b=" 3.Height,Width
4.2 5.Text1.SetFocus
6.Multiline, ScrollBars, 2 7.编程技术,程序设计
8.Private Sub Text2_Change() ´当文本框Text2中的文本内容发生变动时,执行该事件过程
Label1.Caption=Text1.Text ´把文本框Text1中的文本内容作为标签Label1的标题
End Sub
Private Sub Text1_GotFocus() ´当文本框Text1获得焦点时,执行该事件过程
Text1.SelStart = 0 ´选定文本框Text1中的所有文本内容
Text1.SelLength=Len(Text1.Text)
End Sub
编程及上机调试
1.在窗体上建立一个文本框Text1(输入n值)、三个标签Label1(第一个随机数)、Label2(第二个随机数)和Label3(第三个随机数),以及一个命令按钮Command1。
Private Sub Command1_Click()
n = Val(Text1.Text)
Randomize
x = Int(1 + n * Rnd)
Label1.Caption = "第一个随机数" + Str(x)
x = Int(1 + n * Rnd)
Label2.Caption = "第二个随机数" + Str(x)
x = Int(1 + n * Rnd)
Label3.Caption = "第三个随机数" + Str(x)
End Sub
2.在窗体上建立了四个文本框Text1、Text2、Text3和Text4,以及一个命令按钮Command1(“交换”)和Command2(“合并”)。
Private Sub Command1_Click() '“交换”
t = Text1.Text
Text1.Text = Text2.Text
Text2.Text = Text3.Text
Text3.Text = t
End Sub
Private Sub Command2_Click() '“合并”
t = Text1.Text + Text2.Text + Text3.Text
Text4.Text = t
End Sub
3. (1) Rnd * 9000 + 1000 (2) Str(x) (3) Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1)
4. Private Sub Command1_Click() '往左
Text1.Left = 0
End Sub
Private Sub Command2_Click() '往右
Text1.Left = Form1.Width - Text1.Width
End Sub
Private Sub Command3_Click() '居中
Text1.Left = (Form1.Width - Text1.Width) / 2
End Sub
5. Private Sub Cmd1_Click()
Lab1.Visible = True
Lab1.Caption = "您已下达显示命令"
End Sub
Private Sub Form_Click()
Cmd1.Visible = True
End Sub
6. Private Sub Form_KeyPress(KeyAscii As Integer)
Show
Print "输入字符:"; Chr(KeyAscii), "ASCII码为;"; KeyAscii
End Sub
Private Sub Form_DblClick()
Cls
End Sub
7. 产生这三个消息框的相应语句是:
产生第1个消息框:x = MsgBox("在这里显示提示信息", 4 + 0, "请确认")
产生第2个消息框:x = MsgBox("在这里显示" + Chr(13) + "提示信息",3 + 0,"请确认")
产生第3个消息框:x = MsgBox("在这里显示"+Chr(13)+"提示信息",2 + 16 + 0,"请确认")
第4章习题
一、单选题
1.C 2.A 3.C 4.C 5. B 6. A
7.D 8.B 9.B 10.(1)D (2)A (3)B
二、多选题
1.ABCFGHJ 2.BE 3.CD 4. CDE 5. AE
三、填空题
1.(S And (A>=18 And A <=20) And H>=1.65) Or (Not S And (A>=16 And Age<=18) And H>=1.60)
2. 60000 3. (1) "0" To "9" (2) "a" To "z","A" To "Z" (3) Else
4.(1)6 (2)-2 (3)2
5. Select Case x Case Is < 20
Case Is <= 0 y = 2
y = 4 Case Is <= 30
Case Is < 10 y = 3
y = 0 Case Else
Case Is < 15 y = 4
y = 1 End Select
6.(1) (x>100) And (x Mod 5=0) (2) 0
(3) Len(Text1.Text) (4) Text1.SelText
编程及上机调试
1. 在窗体上建立两个文本框Text1(输入数)及Text2(显示结果),一个命令按钮Command1(“判断”)。
Private Sub Command1_Click() '“判断”
x = Val(Text1.Text)
If x Mod 2 = 0 Then
Text2.Text = "偶数"
Else消息
Text2.Text = "奇数"
End If
End Sub
2.窗体上建立了一个文本框Text1,用于显示结果。
Private Sub Form_Load()
x = Val(InputBox("请输入星期几(0~6)"))
Select Case x
Case Is = 0
Text1.Text = "星期日(Sunday)"
Case Is = 1
Text1.Text = "星期一(Monday)"
Case Is = 2
Text1.Text = "星期二(Tuesday)"
Case Is = 3
Text1.Text = "星期三(Wednesday)"
Case Is = 4
Text1.Text = "星期四(Thursday)"
Case Is = 5
Text1.Text = "星期五(Friday)"
Case Is = 6
Text1.Text = "星期六(Saturday)"
Case Else
Text1.Text = "输入错误"
End Select
End Sub
3.窗体上建立了一个文本框Text1(“输入口令”)和一个命令按钮Command1(“检查”)。
Private Sub Command1_Click() '“检查”
x = Text1.Text
If x = "12345678" Then
MsgBox ("欢迎你用机!")
Else
MsgBox ("对不起,口令错")
End If
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text1.MaxLength = 8
Text1.PasswordChar = "*"
End Sub
4.窗体上建立了两个文本框Text1(输入字符串)及Text2(转换结果),一个命令按钮Command1(“清除”)。
Private Sub Command1_Click() '“清除”
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim s As String * 1
s = Chr(KeyAscii)
Select Case s
Case "A" To "Z"
s = LCase(s)
Case "a" To "z"
s = UCase(s)
Case Else
s = "*"
End Select
Text2.Text = Text2.Text + s
End Sub
5. 分别选择”红”、 ”绿”、 ”蓝”复选框后,单击命令按钮Command1时,通过RGB函数调配的颜色作为一个标签的背景色(BackColor)。
Private Sub Command1_Click()
r = 0: g = 0: b = 0
If Check1.Value = 1 Then '”红”复选框
r = 255
End If
If Check2.Value = 1 Then '”绿”复选框
g = 255
End If
If Check3.Value = 1 Then '”蓝”复选框
b = 255
End If
Label1.BackColor = RGB(r, g, b)
End Sub
6.程序代码如下:
Private Sub Form_Load()
LabClk.Caption = "0"
LabClk.Alignment = 1
LabClk.BorderStyle = 1
LabClk.FontSize = 22
LabClk.FontName = "黑体"
TimClk.Interval = 1000
End Sub
Private Sub TimClk_Timer()
LabClk.Caption = Val(LabClk.Caption) + 1
End Sub
7. (1) Chr(KeyAscii) (2) ElseIf Chr(KeyAscii)
(3) CheC = CheC - 1 (4) CheC (5) Is > 0 或 Else
第5章习题
一、单选题
1.A 2. B 3.(1)C,(2)B 4.B 5.C 6.A
7.(1)B,(2)C,(3)B 8. B 9. B 10. B
二、填空题
1.(1)4次,n=13 (2)3次,n=8 (3)3次,n=27 (4)3次,n=10 (5)1次,n=12
2.(1) Len(s) (2) Mid(s, k, 1) (3) c + t (4) Text2.Text
3.(1) t = 1 (2) n = n + 1 (3) t = t * 2
4. 0 5. Text 6. 下拉列表框 7. AddItem ,RemoveItem或Clear
8.(1)ItemA (2) ItemD (3) ItemD (4) ItemA
9.(1) Mid(x, p + 3) (2) p + 4 (3) InStr(p, x, "123")
编程及上机调试
1. 和数为:1.21。程序代码如下:
Private Sub Form_Load()
Show
s = 0
For k = 1 To 100
s = s + 1 / (1 + k * 4)
Next k
Print s
End Sub
2. 程序代码如下:
Private Sub Form_Load()
Dim i As Integer, a As Integer, b As Integer, c As Integer
Show
For i = 100 To 999
a = Int(i / 100)
b = Int((i - 100 * a) / 10)
c = i - 100 * a - 10 * b
If a * a * a + b * b * b + c * c * c = i Then
Print i
End If
Next i
End Sub
3. 在窗体上建立一个文本框Text1(初始值)、一个列表框List1(显示结果)和一个命令按钮Comd1(“查找”)。
Private Sub Comd1_Click() '“查找”
Dim n As Integer
n = Val(Text1.Text)
List1.Clear:k = 0
Do While k <= 99
If Not (n Mod 7 = 0) Then
List1.AddItem n
k = k + 1
End If
n = n + 1
Loop
End Sub
4. 程序代码如下:
Private Sub Form_Load()
Show
n = Val(InputBox("正整数n="))
For i = 1 To n
For j = i + 1 To n
For k = j + 1 To n
If i * i + j * j = k * k Then
Print "("; i; ","; j; ","; k; ")"
End If
Next k
Next j
Next i
End Sub
5.在窗体上建立一个列表框List1和一个“显示表项”命令按钮Command1。程序代码如下:
Private Sub Command1_click() '"显示表项"按钮单击事件
FontSize = 12
Cls
For i = 0 To List1.ListCount - 1 '逐项判断
If List1.Selected(i) Then '真时为选中
Print List1.List(i)
End If
Next i
End Sub
6.(1) Text1.Text (2) UCase(x) (3) t >= "A" And t <= "Z" (4) y + x
7.程序代码如下:
Private Sub Form_Load()
Show
Dim a As Single, xn0 As Single, xn1 As Single
a = Val(InputBox("请输入一个正数"))
xn1 = a
Do