Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <math.h>
  5. #pragma hdrstop
  6.  
  7. #include "Unit4.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma resource "*.dfm"
  11. TForm1 *Form1;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14. : TForm(Owner)
  15. {
  16. }
  17.  
  18. //---------------------------------------------------------------------------
  19.  
  20. int factorial(int x)
  21. {
  22. return !x ? 1 : x * factorial(x - 1);
  23. }
  24.  
  25. //---------------------------------------------------------------------------
  26.  
  27. void __fastcall TForm1::SG1DrawCell(TObject *Sender, int ACol,
  28. int ARow, TRect &Rect, TGridDrawState State)
  29. {
  30. int x,y;
  31. y = Rect.top + (Rect.Height() - SG1->Canvas->TextHeight(SG1->Cells[ACol][ARow])) / 2;
  32. if (ARow == 0) {
  33. x = Rect.left + (Rect.Width() - SG1->Canvas->TextWidth(SG1->Cells[ACol][ARow])) / 2;
  34. SG1->Canvas->Brush->Color = clBtnFace;
  35. SG1->Canvas->Font->Color = clBlack;
  36. SG1->Canvas->FillRect(Rect);
  37. SG1->Canvas->TextOut(x, y, SG1->Cells[ACol][ARow]);
  38. }
  39. }
  40. //---------------------------------------------------------------------------
  41.  
  42. void __fastcall TForm1::FormCreate(TObject *Sender)
  43. {
  44. SG1->Cells[0][0] = "x";
  45. SG1->Cells[1][0] = "Y(x)";
  46. SG1->Cells[2][0] = "S(x)";
  47. SG1->Cells[3][0] = "|Y(x)-S(x)|";
  48. }
  49. //---------------------------------------------------------------------------
  50.  
  51. void __fastcall TForm1::Button1Click(TObject *Sender)
  52. {
  53. double a = StrToFloat(Edit1->Text), b = StrToFloat(Edit2->Text), h = StrToFloat(Edit3->Text), n = StrToFloat(Edit4->Text);
  54. Labout (a, b, h, n, RG1->ItemIndex);
  55. }
  56. //---------------------------------------------------------------------------
  57.  
  58. void __fastcall TForm1::Labout(double a, double b, double h, double n, int f)
  59. {
  60. double y, s;
  61. Label1->Caption = "ネ荳・糺褊韃";
  62. switch (f){
  63. case 1: for (int i = 1; a <= b+h/2; a+=h, i++) {
  64. SG1->Cells[0][i] = FloatToStrF(a, ffGeneral, 5, 5);
  65. y = (pow(a, 2)/4 + a/2 + 1)*exp(a/2);
  66. SG1->Cells[1][i] = FloatToStrF(y, ffFixed, 5, 5);
  67. SG1->RowCount++;
  68. } ;
  69. break;
  70. case 2: for (int i = 1; a <= b+h/2; a+=h, i++) {
  71. SG1->Cells[0][i] = FloatToStrF(a, ffGeneral, 5, 5);
  72. s = 0;
  73. for (int k = 0; k <= n; k++)
  74. s += double(k*k + 1.) / factorial(k) * pow(a/2, k);
  75. SG1->Cells[2][i] = FloatToStrF(s, ffFixed, 5, 5);
  76. SG1->RowCount++;
  77. };
  78. break;
  79. case 3: for (int i = 1; a <= b+h/2; a+=h, i++) {
  80. SG1->Cells[0][i] = FloatToStrF(a, ffGeneral, 5, 5);
  81. y = (pow(a, 2)/4 + a/2 + 1)*exp(a/2);
  82. s = 0;
  83. for (int k = 0; k <= n; k++)
  84. s += double(k*k + 1.) / factorial(k) * pow(a/2, k);
  85. SG1->Cells[3][i] = FloatToStrF(fabs(y - s), ffFixed, 10, 10);
  86. SG1->RowCount++;
  87. };
  88. break;
  89. }
  90. Label1->Caption = "ツ飼頌・湜・鈞粢褊・;
  91. }
  92.  
  93. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement