Составление программы на алгоритмическом языке, выполняющей указанные преобразования с матрицами

Ñîñòàâëåíèå ïðîãðàììû íà àëãîðèòìè÷åñêîì ÿçûêå, âûïîëíÿþùåé óêàçàííûå ïðåîáðàçîâàíèÿ ñ ìàòðèöàìè

Çàäàíèå ¹37

Ðàñïîëîæèòü â ìàòðèöå A(N,N) ýëåìåíòû â ïîñëåäîâàòåëüíîñòè óêàçàííîé íà ðèñóíêå.





Òðåáîâàíèÿ ê ïðîãðàììå:

1.    Ñîñòàâèòü ïðîãðàììó íà àëãîðèòìè÷åñêîì ÿçûêå, âûïîëíÿþùóþ óêàçàííûå ïðåîáðàçîâàíèÿ ñ ìàòðèöàìè;

2.    Âûâåñòè âåêòîð, ïîëó÷åííûé ñëó÷àéíî;

3.    Âûâåñòè ïðåîáðàçîâàííóþ ìàòðèöó ñ íîâûì ñîäåðæèìûì âåêòîðà;

4.    Ïðîãðàììà äîëæíà ñòðîèòüñÿ òàêèì îáðàçîì, ÷òîáû ñóùåñòâîâàëà âîçìîæíîñòü å¸ èñïîëüçîâàíèÿ ñ ìàññèâàìè ëþáîé ðàçìåðíîñòè, ñîäåðæàùèìè ïðîèçâîëüíûå ýëåìåíòû;

5.    Â ïðîãðàììå äîëæíà áûòü ïðåäóñìîòðåíà âûäà÷à íà ïå÷àòü èñõîäíûõ è ïðåîáðàçîâàííûõ ìàòðèö;

6.    Ïîëó÷åííûå ðåçóëüòàòû äîëæíû áûòü çàíåñåíû â ôàéë ïîñëåäîâàòåëüíîãî äîñòóïà è äîñòóïíû äëÿ ïðîñìîòðà èç íåãî.

Èçìåí¸ííûå ñâîéñòâà ïðèëîæåíèÿ

Begin VB.Form frmMain

BorderStyle = 1 'Fixed Single

Caption = "Çàäàíèå ¹37"

ClientHeight = 4365

ClientLeft = 45

ClientTop = 435

ClientWidth = 6180

LinkTopic = "Form1"

MaxButton = 0 'False

ScaleHeight = 4365

ScaleWidth = 6180

StartUpPosition = 2 'CenterScreen

Begin VB.Frame Frame2

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 = 4125

Left = 4590

TabIndex = 7

Top = 120

Width = 1485

Begin VB.CommandButton cmdSave

Caption = "&Ñîõðàíåíèå"

Enabled = 0 'False

Height = 375

Left = 120

TabIndex = 11

Top = 1530

Width = 1245

End

Begin VB.CommandButton cmdPrint

Caption = "&Ïå÷àòü"

Enabled = 0 'False

Height = 375

Left = 120

TabIndex = 10

Top = 930

Width = 1245

End

Begin VB.CommandButton cmdExit

Cancel = -1 'True

Caption = "&Âûõîä"

Height = 375

Left = 120

TabIndex = 9

Top = 3630

Width = 1245

End

Begin VB.CommandButton cmdRun

Caption = "&Ðåøåíèå"

Default = -1 'True

Enabled = 0 'False

Height = 375

Left = 120

TabIndex = 8

Top = 330

Width = 1245

End

End

Begin VB.TextBox txtOriginal

Height = 675

Left = 90

Locked = -1 'True

MultiLine = -1 'True

ScrollBars = 2 'Vertical

TabIndex = 1

Top = 1350

Width = 4485

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 = 5

Top = 120

Width = 4515

Begin VB.TextBox txtN

Alignment = 2 'Center

Height = 285

Left = 3150

MaxLength = 4

TabIndex = 0

Top = 360

Width = 1215

End

Begin VB.Label Label2

Caption = "×¸òíàÿ ðàçìåðíîñòü ìàòðèöû"

Height = 255

Left = 150

TabIndex = 6

Top = 390

Width = 2895

End

End

Begin VB.TextBox txtResult

Height = 1875

Left = 90

Locked = -1 'True

MultiLine = -1 'True

ScrollBars = 2 'Vertical

TabIndex = 2

Top = 2370

Width = 4485

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 = 4

Top = 2070

Width = 4485

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 = 3

Top = 1050

Width = 4485

End

End

Attribute VB_Name = "frmMain"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Òåêñò ïðîãðàììû íà ÿçûêå Microsoft Visual Basic 6.00 Ext

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 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 = Empty

Dim MV As Integer

MV = n ^ 2 / 2 + n

ReDim a(n, n) As Integer

ReDim x(MV) As Integer

Randomize Timer

For i = 1 To MV

x(i) = Int(Rnd * 90) + 10

txtOriginal = txtOriginal & Str(x(i)) & " "

Next i

k = 0

For i = n To n / 2 - 1 Step -1

If i / 2 = Int(i / 2) Then

For j = n - i + 1 To i

k = k + 1: a(i, j) = x(k)

Next j

Else

For j = i To n - i + 1 Step -1

k = k + 1: a(i, j) = x(k)

Next j

End If

Next i

For i = n / 2 To 1 Step -1

If i / 2 = Int(i / 2) Then

For j = n - i + 1 To i Step -1

k = k + 1

a(i, j) = x(k)

Next j

Else

For j = i To n - i + 1

k = k + 1

a(i, j) = x(k)

Next j

End If

Next i

For i = 1 To n

For j = 1 To n

txtResult = txtResult & Format(a(i, j), "00") & " "

Next j

txtResult = txtResult & vbCrLf

Next i

cmdPrint.Enabled = True

cmdSave.Enabled = True

End Sub

Private Sub cmdSave_Click()

On Error GoTo Err_Lbl:

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

Exit Sub

Err_Lbl:

MsgBox "Ïðîèçîøëà îøèáêà çàïèñè", vbCritical, "Âíèìàíèå"

End Sub

Private Sub txtN_Change()

If Val(txtN) > 8 Or Val(txtN) = 0 Or Val(txtN) 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

Âíåøíèé âèä ïðèëîæåíèÿ:





Ðåçóëüòàò ðàáîòû ïðèëîæåíèÿ:





Ïðèëîæåíèå 1

 

Form1

VERSION 5.00

Begin VB.Form frmMain

BorderStyle = 1 'Fixed Single

Caption = "Çàäàíèå ¹37"

ClientHeight = 4365

ClientLeft = 45

ClientTop = 435

ClientWidth = 6180

LinkTopic = "Form1"

MaxButton = 0 'False

ScaleHeight = 4365

ScaleWidth = 6180

StartUpPosition = 2 'CenterScreen

Begin VB.Frame Frame2

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 = 4125

Left = 4590

TabIndex = 7

Top = 120

Width = 1485

Begin VB.CommandButton cmdSave

Caption = "&Ñîõðàíåíèå"

Enabled = 0 'False

Height = 375

Left = 120

TabIndex = 11

Top = 1530

Width = 1245

End

Begin VB.CommandButton cmdPrint

Caption = "&Ïå÷àòü"

Enabled = 0 'False

Height = 375

Left = 120

TabIndex = 10

Top = 930

Width = 1245

End

Begin VB.CommandButton cmdExit

Cancel = -1 'True

Caption = "&Âûõîä"

Height = 375

Left = 120

TabIndex = 9

Top = 3630

Width = 1245

End

Begin VB.CommandButton cmdRun

Caption = "&Ðåøåíèå"

Default = -1 'True

Enabled = 0 'False

Height = 375

Left = 120

TabIndex = 8

Top = 330

Width = 1245 End

End

Begin VB.TextBox txtOriginal

Height = 675

Left = 90

Locked = -1 'True

MultiLine = -1 'True

ScrollBars = 2 'Vertical

TabIndex = 1

Top = 1350

Width = 4485

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 = 5

Top = 120

Width = 4515

Begin VB.TextBox txtN

Alignment = 2 'Center

Height = 285

Left = 3150

MaxLength = 4

TabIndex = 0

Top = 360

Width = 1215

End

Begin VB.Label Label2

Alignment = 2 'Center

BorderStyle = 1 'Fixed Single

Caption = "×¸òíàÿ ðàçìåðíîñòü ìàòðèöû"

Height = 255

Left = 150

TabIndex = 6

Top = 390

Width = 2895

End

End

Begin VB.TextBox txtResult

Height = 1875

Left = 90

Locked = -1 'True

MultiLine = -1 'True

ScrollBars = 2 'Vertical

TabIndex = 2

Top = 2370

Width = 4485

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 = 4

Top = 2070

Width = 4485

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 = 3

Top = 1050

Width = 4485

End

End

Attribute VB_Name = "frmMain"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

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 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 = Empty

Dim MV As Integer

MV = n ^ 2 / 2 + n

ReDim a(n, n) As Integer

ReDim x(MV) As Integer

Randomize Timer

For i = 1 To MV

x(i) = Int(Rnd * 90) + 10

txtOriginal = txtOriginal & Str(x(i)) & " "

Next i

k = 0

For i = n To n / 2 - 1 Step -1

If i / 2 = Int(i / 2) Then

For j = n - i + 1 To i

k = k + 1

a(i, j) = x(k)

Next j

Else

For j = i To n - i + 1 Step -1

k = k + 1

a(i, j) = x(k)

Next j

End If

Next i

For i = n / 2 To 1 Step -1

If i / 2 = Int(i / 2) Then

For j = n - i + 1 To i Step -1

k = k + 1

a(i, j) = x(k)

Next j

Else

For j = i To n - i + 1

k = k + 1

a(i, j) = x(k)

Next j

End If

Next i

For i = 1 To n

For j = 1 To n

txtResult = txtResult & Format(a(i, j), "00") & " "

Next j

txtResult = txtResult & vbCrLf

Next i

cmdPrint.Enabled = True

cmdSave.Enabled = True

End Sub

Private Sub cmdSave_Click()

On Error GoTo Err_Lbl:

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

Exit Sub

Err_Lbl:

MsgBox "Ïðîèçîøëà îøèáêà çàïèñè", vbCritical, "Âíèìàíèå"

End Sub

Private Sub txtN_Change()

If Val(txtN) > 8 Or Val(txtN) = 0 Or Val(txtN) 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



Ïðèëîæåíèå 2

 

Çàäàíèå ¹46

Èñõîäíàÿ ìàòðèöà:

39 41 16 98 68 47 13 87 94 12 12 69 59 46 52 85 71 38 18 19 77 81 92 26 23 94 66 83 28 23 23 15 39 50 51 78 58 22 73 41 

Ïîëó÷åííàÿ ìàòðèöà:

39 50 51 78 58 22 73 41 

00 15 23 23 28 83 66 00 

00 00 92 26 23 94 00 00 

00 00 00 81 77 00 00 00 

00 00 00 19 18 00 00 00 

00 00 52 85 71 38 00 00 

00 46 59 69 12 12 94 00 

39 41 16 98 68 47 13 87