Расчетно-графическая работа по программированию

Реферат - Компьютеры, программирование

Другие рефераты по предмету Компьютеры, программирование

for (int i=0; i<x; i++)

for (int j=0; j<y; 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<x; i++)

for (int j=0; j<y; 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<t.Gety(); i++)

for (int j=0; j<t.Getx(); 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<res.Getx(); i++)

for (int j=0; j<res.Gety(); 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<res.Getx(); i++)

for (int j=0; j<res.Gety(); 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)

{

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

sg1->RowCount=n;

}

if (RBtn2->Checked)

{

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

sg1->ColCount=m;

}

}

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

void __fastcall TMainForm::SEdit2Change(TObject *Sender)

{

if (RBtn3->Checked)

{

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

sg2->RowCount=k;

}

if (RBtn4->Checked)

{

Text.ToIntDef(5);"> 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);

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

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

for(int i=0; i<res.Getx(); i++)

for (int j=0; j<res.Gety(); j++)

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

for (int i=0; i<res.Getx(); i++)

for (int j=0; j<res.Gety(); j++)

{

sg3->Cells[j][i]=IntToStr(res.matr[i][j].cel)+"> 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);

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

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

for(int i=0; i<res1.Getx(); i++)

for (int j=0; j<res1.Gety(); j++)

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

for (int i=0; i<res1.Getx(); i++)

for (int j=0; j<res1.Gety(); j++)

{

sg3->Cells[j][i]=IntToStr(res1.matr[i][j].cel)+"> 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;

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

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

for (int i=0; i<res.Getx(); i++)

for (int j=0; j<res.Gety(); j++)

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

for (int i=0; i<res.Getx(); i++)

for (int j=0; j<res.Gety(); j++)

{

Resform->sg3->Cells[j][i