Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <math.h>
- #pragma hdrstop
- #include "Unit4.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- int factorial(int x)
- {
- return !x ? 1 : x * factorial(x - 1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SG1DrawCell(TObject *Sender, int ACol,
- int ARow, TRect &Rect, TGridDrawState State)
- {
- int x,y;
- y = Rect.top + (Rect.Height() - SG1->Canvas->TextHeight(SG1->Cells[ACol][ARow])) / 2;
- if (ARow == 0) {
- x = Rect.left + (Rect.Width() - SG1->Canvas->TextWidth(SG1->Cells[ACol][ARow])) / 2;
- SG1->Canvas->Brush->Color = clBtnFace;
- SG1->Canvas->Font->Color = clBlack;
- SG1->Canvas->FillRect(Rect);
- SG1->Canvas->TextOut(x, y, SG1->Cells[ACol][ARow]);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- SG1->Cells[0][0] = "x";
- SG1->Cells[1][0] = "Y(x)";
- SG1->Cells[2][0] = "S(x)";
- SG1->Cells[3][0] = "|Y(x)-S(x)|";
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- double a = StrToFloat(Edit1->Text), b = StrToFloat(Edit2->Text), h = StrToFloat(Edit3->Text), n = StrToFloat(Edit4->Text);
- Labout (a, b, h, n, RG1->ItemIndex);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Labout(double a, double b, double h, double n, int f)
- {
- double y, s;
- Label1->Caption = "ネ荳・糺褊韃";
- switch (f){
- case 1: for (int i = 1; a <= b+h/2; a+=h, i++) {
- SG1->Cells[0][i] = FloatToStrF(a, ffGeneral, 5, 5);
- y = (pow(a, 2)/4 + a/2 + 1)*exp(a/2);
- SG1->Cells[1][i] = FloatToStrF(y, ffFixed, 5, 5);
- SG1->RowCount++;
- } ;
- break;
- case 2: for (int i = 1; a <= b+h/2; a+=h, i++) {
- SG1->Cells[0][i] = FloatToStrF(a, ffGeneral, 5, 5);
- s = 0;
- for (int k = 0; k <= n; k++)
- s += double(k*k + 1.) / factorial(k) * pow(a/2, k);
- SG1->Cells[2][i] = FloatToStrF(s, ffFixed, 5, 5);
- SG1->RowCount++;
- };
- break;
- case 3: for (int i = 1; a <= b+h/2; a+=h, i++) {
- SG1->Cells[0][i] = FloatToStrF(a, ffGeneral, 5, 5);
- y = (pow(a, 2)/4 + a/2 + 1)*exp(a/2);
- s = 0;
- for (int k = 0; k <= n; k++)
- s += double(k*k + 1.) / factorial(k) * pow(a/2, k);
- SG1->Cells[3][i] = FloatToStrF(fabs(y - s), ffFixed, 10, 10);
- SG1->RowCount++;
- };
- break;
- }
- Label1->Caption = "ツ飼頌・湜・鈞粢褊・;
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement