All pastes #25972 Raw Edit

Something

public text v1 · immutable
#25972 ·published 2005-10-19 15:51 UTC
rendered paste body
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Barys_ND_2.h"
#include <math.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormActivate(TObject *Sender)
{
Memo1->Clear();
FILE *FR;
FR = fopen(CRez, "w");
fclose(FR);
n = m = 0;
Skaityti();
Memo1->Lines->Add("Duomenys ávesti ið failo: " + AnsiString(CDuom));
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Skaiciuoti();
Label1->Visible = true;
Label2->Visible = true;
StringGrid1->Enabled = true;
ListBox1->Enabled = true;
Rodyti1();
Memo1->Lines->Add("Matrica A apskaièiuota")
Rodyti2();
Memo1->Lines->Add("Matrica X apskaièiuota")
Rodyti3();
Memo1->Lines->Add("Matrica Y apskaièiuota")
Button1->Enabled = false;
Button2->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
MatricaIfaila("Matricos");
Memo1->Lines->Add("Matricos ásimintos faile: " + AnsiString(CRez));
Button2->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
AtmintisAtiduota();
Close();
}
//---------------------------------------------------------------------------
void TForm1::Skaityti()
{
  int i, j;
  FILE *FR;
  if ((FR = fopen(CDuom, "r")) !=NULL
    {
    fscanf(FR, "%d%d\n", &n, &m);
    if (AtmintisSkirta())
    {
    Memo1->Lines->Add("Atmintis matricai skirta.");
    for (i = 0, i < n, i++)
      for (j = 0, j < m, j++)
        fscanf(FR, "%f", &Y[i][j];
    fclose(FR);
    }
    else
    {
    ShowMessage("Nepakanka atminties!");
    Close();
    }
    }
    else
    {
    ShowMessage("Failas" + String(CDuom) + " nerastas");
    Close();
    }
}
//---------------------------------------------------------------------------
bool TForm1::AtmintisSkirta()
{
try
  {
  Y = new float *[n];
  for (int i = 0; i < n; i++)
    Y[i] = new float[m];
  return true;
  }
catch(...)
  {
  return false;
  }
}
//---------------------------------------------------------------------------
void TForm1::AtmintisAtiduota()
{
  for(int i = 0; i < n; i++)
    delete [] Y[i];
  delete [] Y;
}
//---------------------------------------------------------------------------
void TForm1::Rodyti1()
{
  ListBox1->Items->Clear();
  for (int i = 0; i < n; i++)
    ListBox1->Items->Add(IntToStr(A[i]));
}
//---------------------------------------------------------------------------
void TForm1::Rodyti2()
{
  ListBox1->Items->Clear();
  for (int j = 0; j < n; j++)
    ListBox1->Items->Add(IntToStr(X[j]));
}
//---------------------------------------------------------------------------
void TForm1::Rodyti3()
{
  int i, j;
  StringGrid1->ColCount = m+1;
  StringGrid1->RowCount = n+1;

  for (j = 0; j < m; j++)
    StringGrid1->Cells[j+1][0] = "Stulp. " + IntToStr(j);

  for (i = 0; i < n; i++)
    StringGrid1->Cells[0][i+1] = "Eil. " + IntToStr(i);

  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++
      StringGrid1->Cells[j+1][i+1] =
        FloatToStrF(Y[i][j], ffFixed, 6, 2);
}
//---------------------------------------------------------------------------
void TForm1::Skaiciuoti()
{
Y[i][j] = A[i] * pow( X[j], 3.0 ) + pow( A[i] * sin(X[j]), 5.0);
}
//-----------------------------------------------------------------------