. , , ,

,,,

- — ,

:

1.    . 3

2.    4

3.    ..11

4.   

.

.

x n m n , aij ( ), i=1,2,3m; j=1,2,3n. n- x n. , (. . c i != j) . ( ) . , .

= (ij) =(bij) =(ij) , ij=aij+bij , i,j.

=(ij) λ =(bij) , , bij = λ ij, i,j.

= (ij) = (ij) ,

ij = ji , i,j

, (), det .



. , , ; (3/6 1*2/3, ). , , . , .

, . , . , , . , , , .

: Button, RadioButton, String Grid, CSpinEdit, PopupMenu ..

, drob. , , videlen.

class drob

{

public:

int chisl;

int znamen;

int cel;

drob ()

{

chisl=znamen=cel=0;

}

int videlen ()

{

if (!cel && chisl && znamen && abs(chisl)>=abs(znamen))

{

cel=(int)chisl/znamen;

chisl=(int)chisl%(int)znamen;

}

else

if (cel && chisl && znamen && abs(chisl)>=abs(znamen))

{

cel=cel+((int)chisl/znamen);

chisl=(int)chisl%(int)znamen;

}

return 0;

}

};

, . /, , - . (Convert), () (Get), ( , ) (Analiz), (MAIN).

class Analisation

{

char *ptr;

char token [80];

char ttype;

drob vrem;

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

void Analiz(double &result)

{

register char op;

double temp;

Convert(result);

while((op=*token)=='*' || op=='/' )

{

Get();

Convert(temp);

switch (op)

{

case '*':

vrem.cel=result;

break;

case '/':

vrem.chisl=result;

vrem.znamen=temp;

break;

}

}

}

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

void Convert(double &result)

{

result=(double)atof(token);

Get();

return;

}

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

void Get()

{

register char *temp;

ttype=0;

temp=token;

*temp='';

if(!*ptr)return;

while(isspace(*ptr))++ptr;

if(strchr("/*",*ptr))

{

ttype=DELIM;

*temp++=*ptr++;

}

else if(isdigit(*ptr))

{

while(!isdelim(*ptr))*temp++=*ptr++;

ttype=NUMB;

}

*temp='';

}

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

int isdelim(char c)

{

if (strchr("/*",c))return 1;

else return 0;

}

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

public:

Analisation()

{

ptr=NULL;

}

drob MAIN(char*exp)

{

double result;

ptr=exp;

Get();

Analiz(result);

return vrem;

}

};

matrix, :

, ( drob), (det), , StringGrida . , , ..

class matrix

{

protected:

int x,y;

drob det;

public:

drob **matr;

matrix (int x1, int y1);

int Getx () { return x; };

int Gety () { return y; };

void Read (TStringGrid *sg, Analisation &obj);

matrix operator* (drob number);

matrix operator* (int num);

drob Determinant ();

};

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

matrix::matrix (int x1, int y1)

{

x=x1;

y=y1;

det.chisl=det.znamen=det.cel=0;

matr=new drob *[x];

for (int i=0; i

matr[i]=new drob [y];

}

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

void matrix::Read (TStringGrid *sg, Analisation &obj)

{

char ***temp;

temp=new char **[x];

for (int i=0; i

temp[i]=new char *[y];

for (int i=0; i

for (int j=0; j

temp[i][j]=sg->Cells[j][i].c_str();

for (int i=0; i

for (int j=0; j

{

matr[i][j]=obj.MAIN(temp[i][j]);

}

for (int i=0; i

delete temp[i];

delete [] temp;

}

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

matrix matrix::operator* (drob number)

{

matrix res (x,y);

for (int i=0; i

for (int j=0; j

{

res.matr[i][j].chisl=number.chisl*matr[i][j].chisl;

res.matr[i][j].znamen=number.znamen*matr[i][j].znamen;

}

return res;

}

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

matrix matrix::operator* (int num)

{

matrix res (x,y);

for (int i=0; i

for (int j=0; j

{

res.matr[i][j].chisl=num*matr[i][j].chisl;

res.matr[i][j].znamen=matr[i][j].znamen;

}

return res;

}

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

drob matrix::Determinant ()

{

drob det1;

drob det2;

if (x!=y) MessageBox(NULL," :)",

"!!",MB_ICONEXCLAMATION);

if(x==2 && y==2)

{

det1=matr[0][0]*matr[1][1];

det2=matr[0][1]*matr[1][0];

det=det1-det2;

det.videlen();

}

if (x==1 && y==1)

{

det=matr[0][0];

det.videlen();

}

return det; }

:

#include

#include

#pragma hdrstop

#include "matrix.h"

#include "Resultunit.h"

#include "Numberunit.h"

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

#pragma package(smart_init)

#pragma link "CSPIN"

#pragma resource "*.dfm"

TMainForm *MainForm;

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

/// ///

class drob

{

public:

int chisl;

int znamen;

int cel;

drob ()

{

chisl=znamen=cel=0;

}

int videlen ()

{

if (!cel && chisl && znamen && abs(chisl)>=abs(znamen))

{

cel=(int)chisl/znamen;

chisl=(int)chisl%(int)znamen;

}

else

if (cel && chisl && znamen && abs(chisl)>=abs(znamen))

{

cel=cel+((int)chisl/znamen);

chisl=(int)chisl%(int)znamen;

}

return 0;

}

};

drob operator + (drob &m1, drob &m2)

{

drob res;

if (m1.znamen==m2.znamen && m1.znamen!=0)

{

res.chisl=m1.chisl+m2.chisl;

res.znamen=m1.znamen;

}

else

{

res.znamen=m1.znamen*m2.znamen;

res.chisl=(m1.chisl*m2.znamen)+

(m2.chisl*m1.znamen);

}

return res;

}

drob operator - (drob &m1, drob &m2)

{

drob res;

if (m1.znamen==m2.znamen && m1.znamen!=0)

{

res.chisl=m1.chisl-m2.chisl;

res.znamen=m1.znamen;

}

else

{

res.znamen=m1.znamen*m2.znamen;

res.chisl=(m1.chisl*m2.znamen)-

(m2.chisl*m1.znamen);

}

return res;

}

drob operator* (drob &g, drob &h)

{

drob res;

res.chisl=g.chisl*h.chisl;

res.znamen=g.znamen*h.znamen;

return res;

}

drob operator/ (drob &g, drob &h)

{

drob res;

res.chisl=g.chisl*h.znamen;

res.znamen=g.znamen*h.chisl;

return res;

}

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

//////

enum types

{

DELIM=1,NUMB

};

class Analisation

{

char *ptr;

char token [80];

char ttype;

drob vrem;

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

void Analiz(double &result)

{

register char op;

double temp;

Convert(result);

while((op=*token)=='/' )

{

Get();

Convert(temp);

switch (op)

{

case '/':

vrem.chisl=result;

vrem.znamen=temp;

break;

}

}

}

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

void Convert(double &result)

{

result=(double)atof(token);

Get();

return;

}

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

void Get()

{

register char *temp;

ttype=0;

temp=token;

*temp='';

if(!*ptr)return;

while(isspace(*ptr))++ptr;

if(strchr("/*",*ptr))

{

ttype=DELIM;

*temp++=*ptr++;

}

else if(isdigit(*ptr))

{

while(!isdelim(*ptr))*temp++=*ptr++;

ttype=NUMB;

}

*temp='';

}

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

int isdelim(char c)

{

if (strchr("/*",c))return 1;

else return 0;

}

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

public:

Analisation()

{

ptr=NULL;

}

drob MAIN(char*exp)

{

double result;

ptr=exp;

Get();

Analiz(result);

return vrem;

}

};

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

class matrix

{

protected:

int x,y;

drob det;

public:

drob **matr;

matrix (int x1, int y1);

int Getx () { return x; };

int Gety () { return y; };

void Read (TStringGrid *sg, Analisation &obj);

matrix operator* (drob number);

matrix operator* (int num);

drob Determinant ();

};

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

matrix::matrix (int x1, int y1)

{

x=x1;

y=y1;

det.chisl=det.znamen=det.cel=0;

matr=new drob *[x];

for (int i=0; i

matr[i]=new drob [y];

}

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

void matrix::Read (TStringGrid *sg, Analisation &obj)

{

char ***temp;

temp=new char **[x];

for (int i=0; i

temp[i]=new char *[y];

for (int i=0; i

for (int j=0; j

temp[i][j]=sg->Cells[j][i].c_str();

for (int i=0; i

for (int j=0; j

{

matr[i][j]=obj.MAIN(temp[i][j]);

}

for (int i=0; i

delete temp[i];

delete [] temp;

}

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

matrix matrix::operator* (drob number)

{

matrix res (x,y);

for (int i=0; i

for (int j=0; j

{

res.matr[i][j].chisl=number.chisl*matr[i][j].chisl;

res.matr[i][j].znamen=number.znamen*matr[i][j].znamen;

}

return res;

}

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

matrix matrix::operator* (int num)

{

matrix res (x,y);

for (int i=0; i

for (int j=0; j

{

res.matr[i][j].chisl=num*matr[i][j].chisl;

res.matr[i][j].znamen=matr[i][j].znamen;

}

return res;

}

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

drob matrix::Determinant ()

{

drob det1;

drob det2;

if (x!=y) MessageBox(NULL," :)",

"!!",MB_ICONEXCLAMATION);

if(x==2 && y==2)

{

det1=matr[0][0]*matr[1][1];

det2=matr[0][1]*matr[1][0];

det=det1-det2;

det.videlen();

}

if (x==1 && y==1)

{

det=matr[0][0];

det.videlen();

}

return det;

}

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

matrix Transposing (matrix &t)

{

matrix result (t.Gety (), t.Getx());

for (int i=0; i

for (int j=0; j

{

result.matr[i][j].cel=t.matr[j][i].cel;

result.matr[i][j].chisl=t.matr[j][i].chisl;

result.matr[i][j].znamen=t.matr[j][i].znamen;

}

return result;

}

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

matrix operator + (matrix &m1, matrix &m2)

{

matrix res (m1.Getx(),m1.Gety());

for (int i=0; i

for (int j=0; j

{

if (m1.matr[i][j].znamen==m2.matr[i][j].znamen && m1.matr[i][j].znamen!=0)

{

res.matr[i][j].chisl=m1.matr[i][j].chisl+m2.matr[i][j].chisl;

res.matr[i][j].znamen=m1.matr[i][j].znamen;

}

else

{

// res.matr[i][j].cel=m1.matr[i][j].cel+m2.matr[i][j].cel;

res.matr[i][j].znamen=m1.matr[i][j].znamen*m2.matr[i][j].znamen;

res.matr[i][j].chisl=(m1.matr[i][j].chisl*m2.matr[i][j].znamen)+

(m2.matr[i][j].chisl*m1.matr[i][j].znamen);

}

}

return res;

}

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

matrix operator - (matrix &m1, matrix &m2)

{

matrix res (m1.Getx(),m1.Gety());

for (int i=0; i

for (int j=0; j

{

if (m1.matr[i][j].znamen==m2.matr[i][j].znamen && m1.matr[i][j].znamen!=0)

{

res.matr[i][j].chisl=m1.matr[i][j].chisl-m2.matr[i][j].chisl;

res.matr[i][j].znamen=m1.matr[i][j].znamen;

}

else

{

res.matr[i][j].cel=m1.matr[i][j].cel-m2.matr[i][j].cel;

res.matr[i][j].znamen=m1.matr[i][j].znamen*m2.matr[i][j].znamen;

res.matr[i][j].chisl=(m1.matr[i][j].chisl*m2.matr[i][j].znamen)-

(m2.matr[i][j].chisl*m1.matr[i][j].znamen);

}

}

return res;

}

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

drob chislo;

int n=1,m=1;

int k=1,l=1;

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

__fastcall TMainForm::TMainForm(TComponent* Owner)

: TForm(Owner)

{

chislo.chisl=1; //

chislo.znamen=2;

}

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

void __fastcall TMainForm::SEdit1Change(TObject *Sender)

{

if (RBtn1->Checked)

{

n=SEdit1->Text.ToIntDef(5);

sg1->RowCount=n;

}

if (RBtn2->Checked)

{

m=SEdit1->Text.ToIntDef(5);

sg1->ColCount=m;

}

}

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

void __fastcall TMainForm::SEdit2Change(TObject *Sender)

{

if (RBtn3->Checked)

{

k=SEdit2->Text.ToIntDef(5);

sg2->RowCount=k;

}

if (RBtn4->Checked)

{

l=SEdit2->Text.ToIntDef(5);

sg2->ColCount=l;

}

}

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

void __fastcall TMainForm::RBtn1Click(TObject *Sender)

{

SEdit1->Text=IntToStr(1);

}

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

void __fastcall TMainForm::RBtn2Click(TObject *Sender)

{

SEdit1->Text=IntToStr(1);

}

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

void __fastcall TMainForm::RBtn3Click(TObject *Sender)

{

SEdit2->Text=IntToStr(1);

}

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

void __fastcall TMainForm::RBtn4Click(TObject *Sender)

{

SEdit2->Text=IntToStr(1);

}

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

void __fastcall TMainForm::Btn1Click(TObject *Sender)

{

Application->Terminate();

}

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

void __fastcall TMainForm::Btn2Click(TObject *Sender)

{

Analisation ob,ob1;

matrix first (n,m);

matrix second (k,l);

first.Read(sg1,ob);

second.Read(sg2,ob1);

matrix res=Transposing(first);

Resform->sg3->RowCount=res.Getx();

Resform->sg3->ColCount=res.Gety();

for(int i=0; i

for (int j=0; j

res.matr[i][j].videlen();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]=IntToStr(res.matr[i][j].cel)+

"*"+IntToStr(res.matr[i][j].chisl)+

"/"+IntToStr(res.matr[i][j].znamen);

}

Resform->Box1->Visible=true;

Resform->ShowModal();

if (Resform->Box1->Checked)

{

matrix res1=Transposing (second);

Resform->sg3->RowCount=res1.Getx();

Resform->sg3->ColCount=res1.Gety();

for(int i=0; i

for (int j=0; j

res1.matr[i][j].videlen();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]=IntToStr(res1.matr[i][j].cel)+

"*"+IntToStr(res1.matr[i][j].chisl)+

"/"+IntToStr(res1.matr[i][j].znamen);

}

Resform->Box1->Visible=false;

Resform->ShowModal();

}

}

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

void __fastcall TMainForm::Btn3Click(TObject *Sender)

{

Analisation ob,ob1;

matrix first (n,m);

matrix second (k,l);

first.Read(sg1,ob);

second.Read(sg2,ob1);

if (first.Getx()==second.Getx() &&

first.Gety()==second.Gety())

{

matrix res=first+second;

Resform->sg3->RowCount=res.Getx();

Resform->sg3->ColCount=res.Gety();

for (int i=0; i

for (int j=0; j

res.matr[i][j].videlen();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]="";

Resform->sg3->Cells[j][i]=IntToStr(res.matr[i][j].cel)+"*"+

IntToStr(res.matr[i][j].chisl)+

"/"+IntToStr(res.matr[i][j].znamen);

}

Resform->ShowModal();

}

else MessageBox (NULL," ","!!",MB_ICONEXCLAMATION );

}

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

void __fastcall TMainForm::C1Click(TObject *Sender)

{

for (int i=0; iRowCount; i++)

for (int j=0; jColCount; j++)

sg1->Cells[j][i]=IntToStr(1+random(6))+

"/"+IntToStr(1+random(6));

}

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

void __fastcall TMainForm::C2Click(TObject *Sender)

{

for (int i=0; iRowCount; i++)

for (int j=0; jColCount; j++)

sg2->Cells[j][i]=IntToStr(1+random(6))+

"/"+IntToStr(1+random(6));

}

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

void __fastcall TMainForm::Btn4Click(TObject *Sender)

{

Analisation ob,ob1;

matrix first (n,m);

matrix second (k,l);

first.Read(sg1,ob);

second.Read(sg2,ob1);

if (first.Getx()==second.Getx() &&

first.Gety()==second.Gety())

{

matrix res=first-second;

Resform->sg3->RowCount=res.Getx();

Resform->sg3->ColCount=res.Gety();

for (int i=0; i

for (int j=0; j

res.matr[i][j].videlen();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]="";

Resform->sg3->Cells[j][i]=IntToStr(res.matr[i][j].cel)+"*"+

IntToStr(res.matr[i][j].chisl)+

"/"+IntToStr(res.matr[i][j].znamen);

}

Resform->ShowModal();

}

else MessageBox (NULL," ","!!",MB_ICONEXCLAMATION );

}

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

void __fastcall TMainForm::N1Click(TObject *Sender)

{

for (int i=0; iRowCount; i++)

for (int j=0; jColCount; j++)

sg1->Cells[j][i]="";

Panel1->Caption="";

}

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

void __fastcall TMainForm::N2Click(TObject *Sender)

{

for (int i=0; iRowCount; i++)

for (int j=0; jColCount; j++)

sg2->Cells[j][i]="";

Panel2->Caption="";

}

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

void __fastcall TMainForm::Btn5Click(TObject *Sender)

{

Nunit->ShowModal();

Analisation ob,ob1,ob2;

chislo=ob.MAIN(Nunit->Edit->Text.c_str());

matrix first (n,m);

matrix second (k,l);

first.Read(sg1,ob1);

second.Read(sg2,ob2);

matrix res1 (first.Getx(), first.Gety());

matrix res2 (second.Getx(), second.Gety());

if (Nunit->RBtn1->Checked)

{

res1=first.operator *(chislo);

for (int i=0; i

for (int j=0; j

res1.matr[i][j].videlen();

Resform->sg3->RowCount=res1.Getx();

Resform->sg3->ColCount=res1.Gety();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]="";

Resform->sg3->Cells[j][i]=IntToStr(res1.matr[i][j].cel)+

"*"+IntToStr(res1.matr[i][j].chisl)+"/"+

IntToStr(res1.matr[i][j].znamen);

}

Resform->Box1->Visible=true;

Resform->ShowModal();

}

if (Nunit->RBtn2->Checked)

{

res1=first.operator *(Nunit->Edit->Text.ToInt());

for (int i=0; i

for (int j=0; j

res1.matr[i][j].videlen();

Resform->sg3->RowCount=res1.Getx();

Resform->sg3->ColCount=res1.Gety();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]="";

Resform->sg3->Cells[j][i]=IntToStr(res1.matr[i][j].cel)+

"*"+IntToStr(res1.matr[i][j].chisl)+"/"+

IntToStr(res1.matr[i][j].znamen);

}

Resform->Box1->Visible=true;

Resform->ShowModal();

}

if (Resform->Box1->Checked)

{

if (Nunit->RBtn1->Checked)

{

res2=second.operator *(chislo);

for (int i=0; i

for (int j=0; j

res2.matr[i][j].videlen();

Resform->sg3->RowCount=res2.Getx();

Resform->sg3->ColCount=res2.Gety();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]="";

Resform->sg3->Cells[j][i]=IntToStr(res2.matr[i][j].cel)+

"*"+IntToStr(res2.matr[i][j].chisl)+"/"+

IntToStr(res2.matr[i][j].znamen);

}

Resform->Box1->Visible=false;

Resform->ShowModal();

}

if (Nunit->RBtn2->Checked)

{

res2=second.operator *(Nunit->Edit->Text.ToInt());

for (int i=0; i

for (int j=0; j

res2.matr[i][j].videlen();

Resform->sg3->RowCount=res2.Getx();

Resform->sg3->ColCount=res2.Gety();

for (int i=0; i

for (int j=0; j

{

Resform->sg3->Cells[j][i]="";

Resform->sg3->Cells[j][i]=IntToStr(res2.matr[i][j].cel)+

"*"+IntToStr(res2.matr[i][j].chisl)+"/"+

IntToStr(res2.matr[i][j].znamen);

}

Resform->Box1->Visible=false;

Resform->ShowModal();

}

}

}

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

void __fastcall TMainForm::Btn6Click(TObject *Sender)

{

Analisation ob1,ob2;

matrix first (n,m);

matrix second (k,l);

first.Read(sg1,ob1);

second.Read(sg2,ob2);

drob temp1,temp2;

temp1=first.Determinant();

temp2=second.Determinant();

Panel1->Caption=" : "+

IntToStr(temp1.cel)+"*"+IntToStr(temp1.chisl)+"/"

+IntToStr(temp1.znamen);

Panel2->Caption=" : "+

IntToStr(temp2.cel)+"*"+IntToStr(temp2.chisl)+"/"

+IntToStr(temp2.znamen);

}

:

(. 1).

.1

, , 2 3. ( , ).

.2 .3

:

A.   ;

B.    ;

C.   ;

D.   ;

E.    ;

.4 5.

.4

, , ;

.

.5

. 6

.6


(. 7 8)

.7


. 8

9.

: 1. . 3 2. 4 3. ..11 4.

 

 

 

! , , , .
. , :