Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Архив3 / OOP_kursach / ООП_курсач.doc
Скачиваний:
96
Добавлен:
07.08.2013
Размер:
393.73 Кб
Скачать

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._NNUM1 + 1;

StringGrid3->ColCount = _Res._NNUM2 + 1;

Label3_1->Caption = IntToStr(_Res._NNUM1);

Label3_2->Caption = IntToStr(_Res._NNUM2);

for (int i = 0; i < _Res._NNUM1; i++)

for (int j = 0; j < _Res._NNUM2; 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._NNUM1; i++)

for (int j = 0; j < _Mat1._NNUM2; j++)

StringGrid1->Cells[j+1][i+1] = IntToStr(_Mat1.GetElem(i, j));

}

if (Index == 2)

{

for (int i = 0; i < _Mat2._NNUM1; i++)

for (int j = 0; j < _Mat2._NNUM2; j++)

StringGrid2->Cells[j+1][i+1] = IntToStr(_Mat2.GetElem(i, j));

}

}

//---------------------------------------------------------------------------

TForm1 :: ReadMatrix()

{

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]));

}

//---------------------------------------------------------------------------

TForm1 :: WriteMatrix()

{

for (int i = 0; i < _MatFocus->_NNUM1; i++)

for (int j = 0; j < _MatFocus->_NNUM2; 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._NNUM1 + 1;

_SGFocus->ColCount = _Mem._NNUM2 + 1;

for (int i = 0; i < _MatFocus->_NNUM1; i++)

for (int j = 0; j < _MatFocus->_NNUM2; j++)

_SGFocus->Cells[j + 1][i + 1] = IntToStr(_Mem.GetElem(i, j));

}

//---------------------------------------------------------------------------

TForm1 :: ExceptCatch(int ErrCode)

{

switch (ErrCode)

{

case 1:

{

AboutBox1->Label1->Caption = "WRONG SIZE";

AboutBox1->Label2->Caption = "The matrix must be square";

}

break;

case 2:

{

AboutBox1->Label1->Caption = "WRONG SIZE";

AboutBox1->Label2->Caption = "Both matrixes must have same size";

}

break;

case 3:

{

AboutBox1->Label1->Caption = "WRONG DATA";

AboutBox1->Label2->Caption = "The matrix must have only integers";

}

break;

case 4:

{

AboutBox1->Label1->Caption = "WRONG DATA";

AboutBox1->Label2->Caption = "The edit area must have an integer";

}

break;

case 5:

{

AboutBox1->Label1->Caption = "WRONG SIZE";

AboutBox1->Label2->Caption = "Bad size of second matrix";

}

break;

case 10:

{

AboutBox1->Label1->Caption = "INSIDE ERROR";

AboutBox1->Label2->Caption = "Bad index";

}

break;

default:

{

AboutBox1->Label1->Caption = "NEW ERROR";

AboutBox1->Label2->Caption = "";

}

break;

}

AboutBox1->ShowModal();

}

//---------------------------------------------------------------------------

TForm1 :: SGRight(int SGNUM)

{

TStringGrid *SG;

AnsiString buf;

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";

throw 3;

}

for (int k = 1; k < SG->Cells[i][j].Length(); 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";

throw 3;

}

}

}

}

//---------------------------------------------------------------------------