Поможем написать учебную работу
Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.
Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.
Задание
Требования к программе:
Изменённые свойства приложения
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Задание №46"
ClientHeight = 5550
ClientLeft = 45
ClientTop = 435
ClientWidth = 7575
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 5550
ScaleWidth = 7575
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox txtOriginal
Height = 1875
Left = 90
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 1350
Width = 7365
End
Begin VB.Frame Frame1
Caption = "Управление размерностью матрицы"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 204
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 885
Left = 90
TabIndex = 7
Top = 120
Width = 7365
Begin VB.TextBox txtN
Alignment = 2 'Center
Height = 285
Left = 3150
MaxLength = 4
TabIndex = 0
Top = 390
Width = 1335
End
Begin VB.CommandButton cmdRun
Caption = "&Решение"
Default = -1 'True
Enabled = 0 'False
Height = 375
Left = 4650
TabIndex = 1
Top = 360
Width = 1245
End
Begin VB.CommandButton cmdExit
Cancel = -1 'True
Caption = "&Выход"
Height = 375
Left = 5970
TabIndex = 2
Top = 360
Width = 1245
End
Begin VB.Label Label2
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "Введите размерность матрицы"
Height = 255
Left = 150
TabIndex = 8
Top = 390
Width = 2895
End
End
Begin VB.TextBox txtResult
Height = 1875
Left = 90
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 4
Top = 3570
Width = 7365
End
Begin VB.Label Label3
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "Полученная матрица"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 204
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 90
TabIndex = 6
Top = 3270
Width = 7365
End
Begin VB.Label Label1
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "Оригинальная матрица"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 204
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 90
TabIndex = 5
Top = 1050
Width = 7365
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Текст программы на языке Microsoft Visual Basic 6.00
Option Explicit
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdPrint_Click()
Me.PrintForm
End Sub
Private Sub cmdRun_Click()
txtN.Enabled = False
Dim pi As Integer, pj As Integer
Dim i As Integer, j As Integer
Dim t As Integer, n As Integer
Dim k As Integer, p As Integer
n = Val(txtN.Text)
txtOriginal.Text = Empty
ReDim a(n, n) As Integer
For i = 1 To n
For j = 1 To n
a(i, j) = Int(Rnd * 90) + 10
txtOriginal.Text = txtOriginal.Text & Str(a(i, j)) & " "
Next j
txtOriginal.Text = txtOriginal.Text & vbCrLf
Next i
ReDim x(n ^ 2) As Integer
k = 0
p = n / 2 * 11
pi = Int(p / 10)
pj = p - pi * 10
k = k + 1
x(k) = a(pi, pj)
For i = 1 To n - 1
For t = 1 To 10 Step 9
For j = 1 To i
p = p + (-1) ^ (i + 1) * t
pi = Int(p / 10)
pj = p - pi * 10
k = k + 1
x(k) = a(pi, pj)
Next j
Next t
Next i
For i = 1 To n - 1
p = p - 1
pi = Int(p / 10)
pj = p - pi * 10
k = k + 1
x(k) = a(pi, pj)
Next i
For t = 1 To n ^ 2
For i = 1 To n ^ 2 - 1
If x(i) > x(i + 1) Then
k = x(i)
x(i) = x(i + 1)
x(i + 1) = k
End If
Next i
Next t
k = 0
p = n / 2 * 11
pi = Int(p / 10)
pj = p - pi * 10
k = k + 1
a(pi, pj) = x(k)
For i = 1 To n - 1
For t = 1 To 10 Step 9
For j = 1 To i
p = p + (-1) ^ (i + 1) * t
pi = Int(p / 10)
pj = p - pi * 10
k = k + 1
a(pi, pj) = x(k)
Next j
Next t
Next i
For i = 1 To n - 1
p = p - 1
pi = Int(p / 10)
pj = p - pi * 10
k = k + 1
a(pi, pj) = x(k)
Next i
txtResult.Text = Empty
For i = 1 To n
For j = 1 To n
txtResult.Text = txtResult.Text & Str(a(i, j)) & " "
Next j
txtResult.Text = txtResult.Text & vbCrLf
Next i
cmdPrint.Enabled = True
cmdSave.Enabled = True
End Sub
Private Sub cmdSave_Click()
Open App.Path & "\Result.txt" For Output As #1
Print #1, "Задание №46" & vbCrLf & vbCrLf
Print #1, "Исходная матрица:" & vbCrLf
Print #1, txtOriginal.Text & vbCrLf
Print #1, "Полученная матрица:" & vbCrLf
Print #1, txtResult.Text
Close #1
End Sub
Private Sub txtN_Change()
If Val(txtN.Text) > 8 Or Val(txtN.Text) = 0 Or Val(txtN.Text) Mod 2 <> 0 Then
cmdRun.Enabled = False
Else
cmdRun.Enabled = True
End If
End Sub
Private Sub txtN_KeyPress(KeyAscii As Integer)
If KeyAscii < 26 Then Exit Sub
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
End Sub
Внешний вид приложения:
Результат работы приложения: