在 c++ builder 10.3 类中
class Matrix
{
int **m;
int r,s;
public:
Matrix(){}
Matrix(int st,int rd)
{
r = rd;
s = st;
*m = new int [s];
for(int i=0; i<s; i++)
{
m[i] = new int [r];
for(int j=0; j<r; j++)
{
m[i][j] = 0;
}
}
}
~Matrix()
{
for(int i=0; i<s; i++)
delete [] m[i];
delete [] m;
}
void CreateMatrix(int st,int rd, int ch)
{
//m[st][rd] = ch;
}
};
Matrix matr;
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm5 *Form5;
__fastcall TForm5::TForm5(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm5::Button1Click(TObject *Sender)
{
if(Edit1->Text == "" || Edit2->Text == "") ShowMessage("Заповніть поля" );
else
{
if(StrToInt(Edit2->Text)<1 || StrToInt(Edit1->Text)<1) ShowMessage("Розмір матриці повинен бути більше 0" );
else
{
StringGrid1->Visible = true;
StringGrid1->RowCount = StrToInt(Edit2->Text);
StringGrid1->ColCount = StrToInt(Edit1->Text);
Matrix matr(StrToInt(Edit1->Text),StrToInt(Edit2->Text));
}
}
}
void __fastcall TForm5::Button2Click(TObject *Sender)
{
for(int i=0; i<StrToInt(Edit1->Text); i++)
{
for(int j=0; j<StrToInt(Edit2->Text); j++)
{
matr.CreateMatrix(i,j,StrToInt(StringGrid1->Cells[j][i] ));
}
}
}