Скачайте в формате документа WORD

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

Содержание:

1.    Теоретический материал. Матрицы3 стр

2.    Описание программы4 стр

3.    Текст программы..11 стр

4.    Примеры

Теоретический материал. Матрицы

Основные определения.

Матрицей А размера т x n называется прямоугольная таблица из m строк и n столбцов, состоящая из чисел или иных математических выражений aijа (называемых элементами матрицы), i=1,2,Еm; j=1,2,Еn. Квадратной матрицей 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 А.

br>

Описание программы

Данная программа предназначена для работы с матрицами. Можно заполнять их самостоятельно, можно случайным образом, автоматически; причем имеются ввиду дробные числа типа (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='\0';

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='\0';

}

//------------------------------------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<x; i++)

matr[i]=new drob [y];

}

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

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

{

char ***temp;

temp=new char **[x];

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

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

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

for (int j=0; j<y; j++)

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

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

for (int j=0; j<y; j++)

{

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

}

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

delete temp[i];

delete [] temp;

}

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

matrix matrix::operator* (drob number)

{

matrix res (x,y);

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

Текст программы:

#include <vcl.h>

#include <fstream.h>

#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='\0';

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='\0';

}

//------------------------------------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<x; i++)

matr[i]=new drob [y];

}

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

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

{

char ***temp;

temp=new char **[x];

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

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

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

for (int j=0; j<y; j++)

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

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

for (int j=0; j<y; j++)

{

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

}

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

delete temp[i];

delete [] temp;

}

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

matrix matrix::operator* (drob number)

{

matrix res (x,y);

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;

}

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

oid __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;

}

}

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

oid __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;

}

}

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

oid __fastcall TMainForm::RBtn1Click(TObject *Sender)

{

SEdit1->Text=IntToStr(1);

}

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

oid __fastcall TMainForm::RBtn2Click(TObject *Sender)

{

SEdit1->Text=IntToStr(1);

}

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

oid __fastcall TMainForm::RBtn3Click(TObject *Sender)

{

SEdit2->Text=IntToStr(1);

}

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

oid __fastcall TMainForm::RBtn4Click(TObject *Sender)

{

SEdit2->Text=IntToStr(1);

}

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

oid __fastcall TMainForm::Btn1Click(TObject *Sender)

{

Application->Terminate();

}

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

oid __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<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]=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<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++)

{

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

}

}

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

oid __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<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]="";

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

}

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

oid __fastcall TMainForm::C1Click(TObject *Sender)

{

for (int i=0; i<sg1->RowCount; i++)

for (int j=0; j<sg1->ColCount; j++)

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

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

}

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

oid __fastcall TMainForm::C2Click(TObject *Sender)

{

for (int i=0; i<sg2->RowCount; i++)

for (int j=0; j<sg2->ColCount; j++)

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

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

}

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

oid __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<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]="";

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

}

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

oid __fastcall TMainForm::N1Click(TObject *Sender)

{

for (int i=0; i<sg1->RowCount; i++)

for (int j=0; j<sg1->ColCount; j++)

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

Panel1->Caption="";

}

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

oid __fastcall TMainForm::N2Click(TObject *Sender)

{

for (int i=0; i<sg2->RowCount; i++)

for (int j=0; j<sg2->ColCount; j++)

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

Panel2->Caption="";

}

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

oid __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<res1.Getx(); i++)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

}

}

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

oid __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.