好文档 - 专业文书写作范文服务资料分享网站

VB程序设计教程(第3版)课后实验答案 

天下 分享 时间: 加入收藏 我要投稿 点赞

KeyAscii = 0 End Select

If KeyAscii = 13 Then

Combo1.AddItem Combo1.Text Combo1.Text = \ End If End Sub

Private Sub Command1_Click() Dim min%, max%

min = Val(Combo1.List(0)) max = Val(Combo1.List(0)) imin = 0 imax = 0

For i = 1 To Combo1.ListCount - 1 If Val(Combo1.List(i)) > max Then imax = i

max = Combo1.List(i)

ElseIf Val(Combo1.List(i)) < min Then imin = i

min = Combo1.List(i) End If Next i

t = Combo1.List(0)

Combo1.List(0) = Combo1.List(imin) Combo1.List(imin) = t

t = Combo1.List(Combo1.ListCount - 1)

Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax) Combo1.List(imax) = t End Sub

E.9

Private Sub Form_Click()

For i = 0 To Screen.FontCount - 1

If Asc(Left(Screen.Fonts(i), 1)) < 0 Then Picture1.Print Screen.Fonts(i)

Picture2.FontName = Screen.Fonts(i) Picture2.Print \商丘师范学院\ End If Next i End Sub

E.10

Private Type clerk

number As String * 3 name As String * 5 salary As Integer End Type

Dim a(0 To 4) As clerk, n%

Private Sub Command1_Click() If n >= 5 Then

MsgBox (\输入人数超过数组声明的个数\Else

With a(n)

.number = Text1 .name = Text2 .salary = Text3

Picture1.Print a(n).number, a(n).name, a(n).salary Print End With n = n + 1 Text1 = \ Text2 = \ Text3 = \End If End Sub

Private Sub Command2_Click() Dim t As clerk, i%, j% For i = 0 To n - 1 For j = i To n - 1

If a(i).salary < a(j + 1).salary Then t = a(i): a(i) = a(j + 1): a(j + 1) = t End If Next j Next i

Picture1.Cls

Picture1.Print \工号 姓名 工资\For i = 0 To n - 1

Picture1.Print a(i).number, a(i).name, a(i).salary Print Next i End Sub

F.1

Private Sub Form_Click() Dim a(1 To 10), amin, i%

For i = 1 To 10

a(i) = -Int(Rnd * 101 + 300) Print a(i); Next i

Call s(a(), amin) Print

Print \End Sub

Sub s(b(), min) Dim i%

min = b(LBound(b))

For i = LBound(b) + 1 To UBound(b) If b(i) < min Then min = b(i) Next i End Sub

F.2

Private Sub Command1_Click() Dim mm%, nn% mm = Val(Text1) nn = Val(Text2)

Picture1.Print mm; Tab(6); nn; Tab(12); gcd(mm, nn) End Sub

Function gcd%(ByVal m%, ByVal n%) If m < n Then t = m: m = n: n = t r = m Mod n

Do While (r <> 0)

m = n: n = r: r = m Mod n Loop gcd = n End Function

F.3

Dim x!

Private Sub Command1_Click()

Print \调用标准函数Sin的结果\End Sub

Private Sub Command2_Click()

Print \调用自定义函数 MySin的结果\End Sub

Function MySin(x!) As Double Dim i%, t!, s! t = x

s = t i = 1

Do While Abs(t) > 0.00001

t = -1 * t * x * x / ((i + 1) * (i + 2)) s = s + t i = i + 2 Loop

MySin = s End Function

Private Sub Command3_Click()

x = InputBox(\输入要计算正弦函数的角度值x\x = x * 3.14 / 180 End Sub

F.4

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then

If Not IsNumeric(Text1) Then

MsgBox \输入非数字串,重新输入\ Text1.Text = \ Text1.SetFocus Else

If IsH(Text1) Then

Picture1.Print Text1; \★ \ Else

Picture1.Print Text1 End If Text1 = \ End If End If End Sub

Function IsH(ss As String) As Boolean Dim i%, Ls% IsH = True ss = Trim(ss) Ls = Len(ss)

For i = 1 To Ls \\ 2

If Mid(ss, i, 1) <> Mid(ss, Ls + 1 - i, 1) Then IsH = False Exit Function End If Next i End Function

F.5

Function prime(ByVal m As Integer) As Boolean prime = True Dim i%

For i = 2 To m - 1

If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit的范围 Next i

End Function

Private Sub Command1_Click() n = 0

For i = 6 To 100 Step 2 For j = 3 To i \\ 2 If prime(j) Then If prime(i - j) Then

List1.AddItem i & \n = n + 1 End If End If Next j Next i

Picture1.Print \和100之间共有\对素数和\End Sub

F.6

Dim a%()

Private Sub Form_Click()

Print \以内的完数为:\ For i = 1 To 1000 If IsWs(i) Then Print i; \

For j = 1 To UBound(a) Print \ Next j Print End If Next i End Sub

Function IsWs(m) As Boolean Dim s% s = 0

For i = 1 To m \\ 2

If m Mod i = 0 Then ReDim Preserve a(j) a(j) = i

VB程序设计教程(第3版)课后实验答案 

KeyAscii=0EndSelectIfKeyAscii=13ThenCombo1.AddItemCombo1.TextCombo1.Text=\EndIfEndSubPrivateSubCommand1_Click()Dimmin%,max
推荐度:
点击下载文档文档为doc格式
8q0098uzgc4ddq243gyf
领取福利

微信扫码领取福利

微信扫码分享