VisualBasic程序设计—实验报告册-参考答案 下载本文

ClientTop = 450 ClientWidth = 4680 LinkTopic = \ ScaleHeight = 3090 ScaleWidth = 4680

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495 Left = 2160 TabIndex = 0 Top = 1800 Width = 1215 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() For n = 999 To 100 Step -1 For i = 2 To n - 1

If n Mod i = 0 Then Exit For Next i

If i = n Then Print n k = k + 1 End If

If k = 3 Then Exit For Next n End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 8025 LinkTopic = \ ScaleHeight = 3090 ScaleWidth = 8025

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495 Left = 1800 TabIndex = 0 Top = 1320 Width = 1215 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False

Private Sub Command1_Click() s = 0: Max = 0: Min = 1000 For i = 1 To 20 Randomize

x = Int(Rnd * 49 + 51) Print x;

If x > Max Then Max = x If x < Min Then Min = x s = s + x Next i

aver = s / 20 Print

Print \End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = \ ScaleHeight = 3090 ScaleWidth = 4680

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command2

Caption = \方法2:双循环\ Height = 495

Left = 2640 TabIndex = 1 Top = 1800 Width = 1575 End

Begin VB.CommandButton Command1

Caption = \方法1:单循环\ Height = 495 Left = 600 TabIndex = 0 Top = 1800 Width = 1455 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() For i = 1 To 4

Print Tab(20 - i); String(2 * i - 1, \Next End Sub

Private Sub Command2_Click() For i = 1 To 4

Print Tab(30 - i); For j = 1 To 2 * i - 1 Print \ Next Print Next

End Sub

实验6

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 3990 ClientLeft = 60 ClientTop = 450 ClientWidth = 7095

LinkTopic = \ ScaleHeight = 3990 ScaleWidth = 7095

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495 Left = 4680 TabIndex = 0 Top = 2880 Width = 1215 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click()

Dim i%, a%(1 To 10), max%, min%, avg! max = 0: min = 100: avg = 0 For i = 1 To 10

a(i) = Int(Rnd * 51 + 50) Print a(i);

If a(i) > max Then max = a(i) If a(i) < min Then min = a(i) avg = avg + a(i) Next i Print

Print \ Print max, min, avg / 10 End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 4155 ClientLeft = 60 ClientTop = 450 ClientWidth = 6525 LinkTopic = \ ScaleHeight = 4155 ScaleWidth = 6525

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1

Caption = \ Height = 495 Left = 4680 TabIndex = 0 Top = 3120 Width = 1215 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click()

Dim a%(1 To 20), i%, y%, l%, z%, j%, b% For i = 1 To 20

a(i) = Int(Rnd * 101) Print a(i);

If i Mod 10 = 0 Then Print Select Case a(i) Case 90 To 100 y = y + 1 Case 80 To 89 l = l + 1 Case Is >= 70 z = z + 1 Case Is >= 60 j = j + 1 Case Else b = b + 1 End Select Next i

Print \优秀:\ Print \良好:\ Print \中:\ Print \及格:\ Print \不及格:\End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 4320 ClientLeft = 60 ClientTop = 450