1
0
This commit is contained in:
Debug_pro
2026-02-12 01:01:44 +03:00
commit 43d7845cf1
23 changed files with 1353 additions and 0 deletions

94
MatrixFlipWindow.xaml.cs Normal file
View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Lab
{
/// <summary>
/// Interaction logic for MatrixFlipWindow.xaml
/// </summary>
public partial class MatrixFlipWindow : Window
{
private DataTable? _src;
private DataTable? _dst;
private void ClickBack(object sender, RoutedEventArgs e) => Close();
private bool TryGetSize(out int rows, out int cols)
{
rows = 0;
cols = 0;
if (!Parsers.TryParseInt(RowsBox.Text, out rows) || !Parsers.TryParseInt(ColsBox.Text, out cols)) {
FlipInfoText.Text = "Размеры должны быть целыми числами.";
return false;
}
if (rows < 1 || cols < 1)
{
FlipInfoText.Text = "Размеры должны быть больше 1";
return false;
}
return true;
}
private void ClickCreate(object sender, RoutedEventArgs e)
{
if (!TryGetSize(out int rows, out int cols)) return;
_src = Matrices.CreateMatrixInts(rows, cols, "A");
Matrices.RandomFill(_src, 0, 100);
GridSrc.ItemsSource = _src.DefaultView;
_dst = Matrices.CreateMatrixInts(rows, cols, "B");
GridDst.ItemsSource = _dst.DefaultView;
FlipInfoText.Text = $"Создана матрица {rows}×{cols}, заполнена числами 0..100.";
}
private void ClickFlip(object sender, RoutedEventArgs e)
{
if (_src is null)
{
FlipInfoText.Text = "Сначала создайте матрицу.";
return;
}
var a = Matrices.ToArray(_src);
int rows = a.GetLength(0);
int cols = a.GetLength(1);
var b = new int[rows, cols];
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
{
b[rows - 1 - row, col] = a[row, col];
}
}
_dst = Matrices.FromArray(b, "B");
GridDst.ItemsSource = _dst.DefaultView;
FlipInfoText.Text = "Готово: строки перевёрнуты (отражение по горизонтальной оси).";
}
public MatrixFlipWindow()
{
InitializeComponent();
}
}
}