StringGrid 1 ColCount RowCount , , 3 , FixedCols FixedRows 1.
StringGrid 2 StringGrid 3 , ColCount = 1, RowCount = 3, FixedCols = 0 FixedRows = 1.
Options goEditing StringGrid 1 StringGrid 2 true.
n - EditChange, Edit.
. 6.1
:
...
int n = 3; // n
//---------------------------------------------------------------------------
void __fastcall TForm1:: FormCreate (TObject *Sender)
{
Edit1->Text=IntToStr(n);
StringGrid1->ColCount = n+1; StringGrid1->RowCount = n+1;
StringGrid2->RowCount = n+1; StringGrid3->RowCount = n+1;
//---------- -----------
StringGrid1->Cells[0][0] = " A";
StringGrid2->Cells[0][0] = " B";
StringGrid3->Cells[0][0] = " Y";
for(int i=1; i<=n;i++){
StringGrid1->Cells[0][i]="i="+IntToStr(i);
StringGrid1->Cells[i][0]="j="+IntToStr(i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1:: Edit1Change (TObject *Sender)
{
int i;
n=StrToInt(Edit1->Text);
StringGrid1->ColCount = n+1;
StringGrid1->RowCount = n+1;
StringGrid2->RowCount = n+1;
StringGrid3->RowCount = n+1;
for(i=1; i<=n;i++){
StringGrid1->Cells[0][i]="i="+IntToStr(i);
StringGrid1->Cells[i][0]="j="+IntToStr(i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1:: Button1Click (TObject *Sender)
{
double **a, *b, s; //
int i, j;
a = new double*[n]; //
for(i=0; i<n;i++)
a[i] = new double[n]; //
b = new double[n];
// StringGrid1 StringGrid2
for(i=0; i<n;i++) {
for(j=0; j<n;j++)
a[i][j]=StrToFloat(StringGrid1->Cells[j+1][i+1]);
b[i]=StrToFloat(StringGrid2->Cells[0][i+1]);
}
// s StringGrid3
for(i=0; i<n;i++){
for(s=0, j=0; j<n;j++)
s += a[i][j]*b[j];
StringGrid3->Cells[0][i+1] = FloatToStrF(s, ffFixed,8,2);
}
for(i=0; i<n;i++) delete []a[i];
delete []a;
delete []b;
}
//---------------------------------------------------------------------------
void __fastcall TForm1:: Button2Click (TObject *Sender)
{
Close();
}