Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовая по ООП3 / MATRIX / Unit1
.cpp//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "File2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
_Mat1.InitZero();
_Mat2.InitZero();
_SG1_R = 3;
_SG1_C = 3;
_SG2_R = 3;
_SG2_C = 3;
_SGFocus = StringGrid1;
_MatFocus = &_Mat1;
_Memory = 0;
_SGFocusInt = 1;
for (int i = 1; i <= SGMAX; i++)
{
StringGrid1->Cells[i][0] = IntToStr(i);
StringGrid2->Cells[i][0] = IntToStr(i);
StringGrid3->Cells[i][0] = IntToStr(i);
}
for (int i = 1; i <= SGMAX; i++)
{
StringGrid1->Cells[0][i] = IntToStr(i);
StringGrid2->Cells[0][i] = IntToStr(i);
StringGrid3->Cells[0][i] = IntToStr(i);
}
for (int i = 1; i < SGMAX ; i++)
for (int j = 1; j < SGMAX; j++)
{
StringGrid1->Cells[j][i] = "0";
StringGrid2->Cells[j][i] = "0";
StringGrid3->Cells[j][i] = "0";
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
try
{
ReadForm();
_Res.MSumm(_Mat1, _Mat2);
WriteForm();
}
catch (int ExceptCode)
{
ExceptCatch(ExceptCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
try
{
ReadForm();
_Res.MMult(_Mat1, _Mat2);
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
try
{
ReadForm();
_Res.MDiff(_Mat1, _Mat2);
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3_1Click(TObject *Sender)
{
StringGrid1->RowCount = StringGrid3->RowCount;
StringGrid1->ColCount = StringGrid3->ColCount;
Edit1_1->Text = IntToStr(_SG1_R = StringGrid1->RowCount - 1);
Edit1_2->Text = IntToStr(_SG1_C = StringGrid1->ColCount - 1);
_Mat1 = _Res;
Print(1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3_2Click(TObject *Sender)
{
StringGrid2->RowCount = StringGrid3->RowCount;
StringGrid2->ColCount = StringGrid3->ColCount;
Edit2_1->Text = IntToStr(_SG1_R = StringGrid2->RowCount - 1);
Edit2_2->Text = IntToStr(_SG1_C = StringGrid2->ColCount - 1);
_Mat2 = _Res;
Print(2);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonCClick(TObject *Sender)
{
_Res.InitZero();
_Mat1.InitZero();
_Mat2.InitZero();
for (int i = 1; i < SGMAX ; i++)
for (int j = 1; j < SGMAX; j++)
{
StringGrid1->Cells[j][i] = "0";
StringGrid2->Cells[j][i] = "0";
StringGrid3->Cells[j][i] = "0";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button15Click(TObject *Sender)
{
try
{
ReadMatrix();
_Res = *_MatFocus;
if (Edit1->Text != "")
{
for (int k = 1; k < Edit1->Text.Length() + 1; k++)
if ((Edit1->Text[k] > 57) || (Edit1->Text[k] < 48))
if (Edit1->Text[k] != 45)
{
Edit1->Text = "";
throw 4;
}
}
else
throw 4;
_Edit1Num = StrToInt(Edit1->Text);
_Res.MScalMult(_Edit1Num);
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1_1PClick(TObject *Sender)
{
_SG1_R = StrToInt(Edit1_1->Text);
if (_SG1_R + 1 < SGMAX)
Edit1_1->Text = IntToStr(++_SG1_R);
StringGrid1->RowCount = _SG1_R + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1_1MClick(TObject *Sender)
{
_SG1_R = StrToInt(Edit1_1->Text);
if (_SG1_R - 1> SGMIN)
Edit1_1->Text = IntToStr(--_SG1_R);
StringGrid1->RowCount = _SG1_R + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1_2PClick(TObject *Sender)
{
_SG1_C = StrToInt(Edit1_2->Text);
if (_SG1_C + 1< SGMAX)
Edit1_2->Text = IntToStr(++_SG1_C);
StringGrid1->ColCount = _SG1_C + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1_2MClick(TObject *Sender)
{
_SG1_C = StrToInt(Edit1_2->Text);
if (_SG1_C - 1> SGMIN)
Edit1_2->Text = IntToStr(--_SG1_C);
StringGrid1->ColCount = _SG1_C + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2_1PClick(TObject *Sender)
{
_SG2_R = StrToInt(Edit2_1->Text);
if (_SG2_R + 1 < SGMAX)
Edit2_1->Text = IntToStr(++_SG2_R);
StringGrid2->RowCount = _SG2_R + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2_1MClick(TObject *Sender)
{
_SG2_R = StrToInt(Edit2_1->Text);
if (_SG2_R - 1> SGMIN)
Edit2_1->Text = IntToStr(--_SG2_R);
StringGrid2->RowCount = _SG2_R + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2_2PClick(TObject *Sender)
{
_SG2_C = StrToInt(Edit2_2->Text);
if (_SG2_C + 1< SGMAX)
Edit2_2->Text = IntToStr(++_SG2_C);
StringGrid2->ColCount = _SG2_C + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2_2MClick(TObject *Sender)
{
_SG2_C = StrToInt(Edit2_2->Text);
if (_SG2_C - 1> SGMIN)
Edit2_2->Text = IntToStr(--_SG2_C);
StringGrid2->ColCount = _SG2_C + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1Click(TObject *Sender)
{
_SGFocus = StringGrid1;
_MatFocus = &_Mat1;
_SGFocusInt = 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid2Click(TObject *Sender)
{
_SGFocus = StringGrid2;
_MatFocus = &_Mat2;
_SGFocusInt = 2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1Exit(TObject *Sender)
{
for (int i = 1; i < StringGrid1->RowCount; i++)
for (int j = 1; j < StringGrid1->ColCount; j++)
if (StringGrid1->Cells[j][i] == "")
StringGrid1->Cells[j][i] == "0";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid2Exit(TObject *Sender)
{
for (int i = 1; i < StringGrid1->RowCount; i++)
for (int j = 1; j < StringGrid1->ColCount; j++)
if (StringGrid1->Cells[j][i] == "")
StringGrid1->Cells[j][i] == "0";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button16Click(TObject *Sender)
{
try
{
ReadMatrix();
_Res = *_MatFocus;
_Res.MTrans();
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)
{
try
{
ReadMatrix();
_MatFocus->InitE();
WriteMatrix();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject *Sender)
{
ReadMatrix();
_MatFocus->InitZero();
WriteMatrix();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
_MatFocus->InitNewMatrix1(_SGFocus->RowCount, _SGFocus->ColCount);
_MatFocus->InitRandom();
WriteMatrix();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button17Click(TObject *Sender)
{
try
{
ReadMatrix();
_Res = *_MatFocus;
if (Edit1->Text != "")
{
for (int k = 1; k < Edit1->Text.Length() + 1; k++)
if ((Edit1->Text[k] > 57) || (Edit1->Text[k] < 48))
if (Edit1->Text[k] != 45)
{
Edit1->Text = "";
throw 4;
}
}
else
throw 4;
_Edit1Num = StrToInt(Edit1->Text);
TMatrix buf;
buf = _Res;
for (int i = 1; i < _Edit1Num; i++)
_Res.MMult(_Res, buf);
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
_Memory = 1;
ReadMemory();
Label3->Caption = "M";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
if (_Memory == 0)
return;
WriteMemory();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
_Memory = 0;
Label3->Caption = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ReadMatrix();
_MatFocus->MNegative();
WriteMatrix();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button0Click(TObject *Sender)
{
AboutBox->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
try
{
ReadMatrix();
int res = _MatFocus->MMod();
Edit1->Text = IntToStr(res);
}
catch (int ExceptCode)
{
ExceptCatch(ExceptCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button23Click(TObject *Sender)
{
try
{
_MatFocus->InitNewMatrix1(_SGFocus->RowCount, _SGFocus->ColCount);
if (Edit1->Text == "")
throw 6;
for (int k = 1; k < Edit1->Text.Length(); k++)
if ((Edit1->Text[k] > 57) || (Edit1->Text[k] < 48))
if (Edit1->Text[k] != 45)
{
Edit1->Text = "";
throw 6;
}
_MatFocus->InitInt(StrToInt(Edit1->Text));
WriteMatrix();
}
catch (int ExceptCode)
{
ExceptCatch(ExceptCode);
}
}
//---------------------------------------------------------------------------
Соседние файлы в папке MATRIX