Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Курсовая работа (1,08 МБ).docx
Скачиваний:
2
Добавлен:
17.09.2019
Размер:
1.14 Mб
Скачать
    1. Класс чтения матриц из файла (Re.Cs)

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Windows;

using Microsoft.Win32;

namespace Матрица_1_0

{

class RE

{

public int a = 0, b;

public void Read(int ind, Cache ch)

{

Encoding en = Encoding.GetEncoding(1251);

char[] ca = { ' ', ','};

string[] strarray;

string strline;

List<string> mas = new List<string>();

Stream myStream = null;

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\";

openFileDialog1.Filter = "matr files (*.matr)|*.matr|All files (*.*)|*.*";

openFileDialog1.FilterIndex = 1;

openFileDialog1.RestoreDirectory = true;

int vrem = 0;

if (openFileDialog1.ShowDialog() != null)

{

try

{

if ((myStream = openFileDialog1.OpenFile()) != null)

{

using (myStream)

{

StreamReader sr = new StreamReader(myStream, en);

strline = sr.ReadLine();

int k = 0;

while (strline != null)

{

strarray = strline.Split(ca);

b = strarray.Length;

mas.Add(strline);

strline = sr.ReadLine();

if (k == 0)

{

vrem = b;

if (vrem < 3)

{

string[] strarray2 = mas[0].Split(ca);

ch.name = strarray2[0];

ch.fam = strarray2[1];

a--;

k++;

}

else

{

ch.name = "Автор";

ch.fam = "отсутствует";

k++;

}

}

a++;

}

}

myStream.Close();

}

}

catch

{

MessageBox.Show("Ошибка! Вы не выбрали файл.");

}

}

int l = 0;

double[,] matr = new double[a, b];

for (int i = 0; i < a+l; i++)

{

if (vrem < 3&&l==0)

{

i = 1;

l++;

}

strarray = (mas[i].Split(ca));

for (int j = 0; j < b; j++)

{

if (vrem < 3)

{

matr[i - 1, j] = Convert.ToDouble(strarray[j]);

}

else

{

matr[i, j] = Convert.ToDouble(strarray[j]);

}

}

}

if (ind == 1)

{

ch.c = a;

ch.d = b;

ch.matr1 = matr;

}

if (ind == 2)

{

ch.e = a;

ch.f = b;

ch.matr2 = matr;

}

}

}

}