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

ClientHeight = 4350 ClientLeft = 60 ClientTop = 450 ClientWidth = 7005 LinkTopic = \ ScaleHeight = 4350 ScaleWidth = 7005

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495 Left = 5280 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(), i%, j%, m%, n% m = InputBox(\ n = InputBox(\

ReDim a(1 To m, 1 To n)

For i = 1 To m For j = 1 To n

a(i, j) = Int(Rnd * 100) Print a(i, j); Next j Print Next i

Dim max%, imax%, jmax%

max = a(1, 1): imax = 1: jmax = 1 For i = 1 To m For j = 1 To n

If a(i, j) > max Then max = a(i, j) imax = i

jmax = j End If Next j Next i

Print \ Print max, imax, jmax End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 4935 ClientLeft = 60 ClientTop = 450 ClientWidth = 7155 LinkTopic = \ ScaleHeight = 4935 ScaleWidth = 7155

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495 Left = 4920 TabIndex = 0 Top = 3600 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(), i%, j%, m%, n% m = InputBox(\ n = InputBox(\

ReDim a(1 To m, 1 To n)

For i = 1 To m For j = 1 To n

a(i, j) = Int(Rnd * 100) Print a(i, j); Next j

Print Next i

Print \ ReDim Preserve a(1 To m, 1 To n + 1)

'计算i行的和,放入第n+1列

For i = 1 To m

a(i, n + 1) = 0 For j = 1 To n

a(i, n + 1) = a(i, n + 1) + a(i, j) Next j Next i

For i = 1 To m

For j = 1 To n + 1 Print a(i, j); Next j Print Next i End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 4725 ClientLeft = 60 ClientTop = 450 ClientWidth = 6990 BeginProperty Font

Name = \宋体\ Size = 10.5 Charset = 134 Weight = 400

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

LinkTopic = \ ScaleHeight = 4725 ScaleWidth = 6990

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ BeginProperty Font

Name = \宋体\ Size = 9 Charset = 134 Weight = 400

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Height = 495 Left = 5040 TabIndex = 0 Top = 3480 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 n%, a%(), i% n = InputBox(\ ReDim a(1 To n)

Print \初值-----------------\ For i = 1 To n '赋值 a(i) = Int(Rnd * 21 - 10) Print a(i); Next i Print

For i = 1 To n - 1 '将相同值的数改为99 If a(i) <> 99 Then For j = i + 1 To n

If a(j) = a(i) Then a(j) = 99 Next j End If Next i

Print \重复的数值已经修改为99----------\ For i = 1 To n '赋值 Print a(i); Next i Print

Print \删除了重复数后的结果------------\

'下面的代码将值为99的数组元素过滤掉 k = 0

For i = 1 To n

If a(i) <> 99 Then k = k + 1 a(k) = a(i) End If Next i

'打印剩余的k个不重复数 ReDim Preserve a(1 To k) For i = 1 To k Print a(i); Next i End Sub

实验7

VERSION 5.00

Begin VB.Form Form1

AutoRedraw = -1 'True Caption = \ ClientHeight = 3555 ClientLeft = 60 ClientTop = 450 ClientWidth = 5760 LinkTopic = \ ScaleHeight = 3555 ScaleWidth = 5760

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

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4