distributed-computing/tasks/klementeva-ja/lab_6/Lab6/Controller.cs

96 lines
2.4 KiB
C#
Raw Normal View History

2023-12-16 11:48:57 +04:00
using System.Drawing;
namespace Lab6
{
public class Controller
{
public double[,] ConvertArray(int[,] intArray)
{
int rows = intArray.GetLength(0);
int cols = intArray.GetLength(1);
double[,] doubleArray = new double[rows, cols];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
doubleArray[i, j] = (double)intArray[i, j];
}
}
return doubleArray;
}
public string PrintResultMatrix(int[,] result)
{
string resultString = "";
for (int i = 0; i < result.GetLength(0); i++)
{
for (int j = 0; j < result.GetLength(1); j++)
{
resultString += result[i, j];
if (j != result.GetLength(1) - 1)
{
resultString += " ";
}
}
resultString += Environment.NewLine;
}
return resultString;
}
public int[,] GetMatrixFromTextbox(string inputText)
{
string[] lines = inputText.Split(Environment.NewLine);
int numRows = lines.Length;
int numCol = lines[0].Split(' ').Length;
int[,] matrix = new int[numRows, numCol];
for (int i = 0; i < numRows; i++)
{
string[] elements = lines[i].Split(' ');
for (int j = 0; j < numCol; j++)
{
matrix[i, j] = int.Parse(elements[j]);
}
}
return matrix;
}
public string GetTextFromFile(string filePath)
{
string text = "";
using (StreamReader sr = new StreamReader(filePath))
{
text = sr.ReadToEnd();
}
return text;
}
public int[,] GenerateNewMatrix(int count)
{
Random random = new Random();
int[,] matrix = new int[count, count];
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
matrix[i, j] = random.Next(1, 5);
}
}
return matrix;
}
}
}