Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовая по ООП3 / MATRIX / File1
.cpp#include "Unit1.h"
#include "Unit2.h"
#include "Unit4.h"
//---------------------------------------------------------------------------
TForm1 :: ReadForm()
{
SGRight(1);
SGRight(2);
_Mat1.InitNewMatrix1(_SG1_R, _SG1_C);
for (int i = 0; i < _SG1_R; i++)
for (int j = 0; j < _SG1_C; j++)
_Mat1.InitElem(i, j, StrToInt(StringGrid1->Cells[j + 1][i + 1]));
_Mat2.InitNewMatrix1(_SG2_R, _SG2_C);
for (int i = 0; i < _SG2_R; i++)
for (int j = 0; j < _SG2_C; j++)
_Mat2.InitElem(i, j, StrToInt(StringGrid2->Cells[j + 1][i + 1]));
}
//---------------------------------------------------------------------------
TForm1 :: WriteForm()
{
StringGrid3->RowCount = _Res.GetN1() + 1;
StringGrid3->ColCount = _Res.GetN2() + 1;
Label3_1->Caption = IntToStr(_Res.GetN1());
Label3_2->Caption = IntToStr(_Res.GetN2());
for (int i = 0; i < _Res.GetN1(); i++)
for (int j = 0; j < _Res.GetN2(); j++)
StringGrid3->Cells[j+1][i+1] = IntToStr(_Res.GetElem(i, j));
}
//---------------------------------------------------------------------------
TForm1 :: Print(int Index)
{
if (Index == 1)
{
for (int i = 0; i < _Mat1.GetN1(); i++)
for (int j = 0; j < _Mat1.GetN2(); j++)
StringGrid1->Cells[j+1][i+1] = IntToStr(_Mat1.GetElem(i, j));
}
if (Index == 2)
{
for (int i = 0; i < _Mat2.GetN1(); i++)
for (int j = 0; j < _Mat2.GetN2(); j++)
StringGrid2->Cells[j+1][i+1] = IntToStr(_Mat2.GetElem(i, j));
}
}
//---------------------------------------------------------------------------
TForm1 :: ReadMatrix()
{
try
{
SGRight(_SGFocusInt);
int N1 = _SGFocus->RowCount - 1;
int N2 = _SGFocus->ColCount - 1;
_MatFocus->InitNewMatrix1(N1, N2);
for (int i = 0; i < N1; i++)
for (int j = 0; j < N2; j++)
_MatFocus->InitElem(i, j, StrToInt(_SGFocus->Cells[j + 1][i + 1]));
}
catch (int ExceptCode)
{
ExceptCatch(ExceptCode);
}
}
//---------------------------------------------------------------------------
TForm1 :: WriteMatrix()
{
for (int i = 0; i < _MatFocus->GetN1(); i++)
for (int j = 0; j < _MatFocus->GetN2(); j++)
_SGFocus->Cells[j + 1][i + 1] = IntToStr(_MatFocus->GetElem(i, j));
}
//---------------------------------------------------------------------------
TForm1 :: ReadMemory()
{
SGRight(_SGFocusInt);
int N1 = _SGFocus->RowCount - 1;
int N2 = _SGFocus->ColCount - 1;
_Mem.InitNewMatrix1(N1, N2);
for (int i = 0; i < N1; i++)
for (int j = 0; j < N2; j++)
_Mem.InitElem(i, j, StrToInt(_SGFocus->Cells[j + 1][i + 1]));
}
//---------------------------------------------------------------------------
TForm1 :: WriteMemory()
{
_SGFocus->RowCount = _Mem.GetN1() + 1;
_SGFocus->ColCount = _Mem.GetN2() + 1;
for (int i = 0; i < _MatFocus->GetN1(); i++)
for (int j = 0; j < _MatFocus->GetN2(); j++)
_SGFocus->Cells[j + 1][i + 1] = IntToStr(_Mem.GetElem(i, j));
}
//---------------------------------------------------------------------------
TForm1 :: ExceptCatch(int ErrCode)
{
switch (ErrCode)
{
case 1:
{
AboutBox1->Label1->Caption = "НЕВЕРНЫЙ РАЗМЕР";
AboutBox1->Label2->Caption = "Матрица должна быть квадратной";
}
break;
case 2:
{
AboutBox1->Label1->Caption = "НЕВЕРНЫЙ РАЗМЕР";
AboutBox1->Label2->Caption = "Обе матрицы должны иметь один размер";
}
break;
case 3:
{
AboutBox1->Label1->Caption = "НЕВЕРНЫЕ ДАННЫЕ";
AboutBox1->Label2->Caption = "Элементы матрицы должны быть целыми";
}
break;
case 4:
{
AboutBox1->Label1->Caption = "НЕВЕРНЫЕ ДАННЫЕ";
AboutBox1->Label2->Caption = "Должно быть введено целое число";
AboutBox1->Label3->Caption = "Введите целое значение в поле <Число>";
}
break;
case 5:
{
AboutBox1->Label1->Caption = "НЕВЕРНЫЙ РАЗМЕР";
AboutBox1->Label2->Caption = "Высота 1-й и ширина 2-й матриц не равны";
}
break;
case 6:
{
AboutBox1->Label1->Caption = "НЕВЕРНЫЕ ДАННЫЕ";
AboutBox1->Label2->Caption = "Должно быть введено целое число";
}
break;
case 10:
{
AboutBox1->Label1->Caption = "ВНУТРЕННЯЯ ОШИБКА";
AboutBox1->Label2->Caption = "Просьба обратиться к разработчику";
}
break;
default:
{
AboutBox1->Label1->Caption = "NEW ERROR";
AboutBox1->Label2->Caption = "";
}
break;
}
AboutBox1->ShowModal();
}
//---------------------------------------------------------------------------
TForm1 :: SGRight(int SGNUM)
{
TStringGrid *SG;
AnsiString buf;
int Except = 0;
if (SGNUM == 1) SG = StringGrid1;
if (SGNUM == 2) SG = StringGrid2;
for (int i = 1; i < SG->RowCount; i++)
for (int j = 1; j < SG->RowCount; j++)
{
if (SG->Cells[i][j] == "")
{
SG->Cells[i][j] = "0";
Except = 1;
}
for (int k = 1; k < SG->Cells[i][j].Length() + 1; k++)
{
if (((SG->Cells[i][j])[k] > 57) || ((SG->Cells[i][j])[k] < 48))
if ((SG->Cells[i][j])[k] != 45)
{
SG->Cells[i][j] = "0";
Except = 1;
break;
}
}
}
if (Except) throw 3;
}
//---------------------------------------------------------------------------