n:=n+1;
a:=-a*x/n;
s:=s+a;
end;
y:=exp(-x);
Memo1.Lines.Add(' x='+FloatToStrF(x,ffFixed,6,2)+' ='
+ FloatToStrF(s,ffFixed,8,4)+ y ='
+ FloatToStrF(y,ffFixed,8,4)+' N ='+IntToStr(n));
x:=x+h;
until x>(xk+h/2) // (xk+h/2)
end; // x
end.
3.4.
. . .
y(x) s(x) x xn xk M () e. S(x) Y(x) x S(x) Y(x).
, F4. , F7, , .
3.1. | |||||
S(x) | e | Y(x) | |||
1. | 0.1 | 0.001 | |||
. 3.1 | |||||
2. | 0.1 | 0.0001 | |||
3. | 0.1 | 0.001 | |||
4. | 0.1 | 0.01 | |||
5. | 0.1 | 0.7 | 0.001 | ||
6. | 0.1 | 0.0001 | |||
7. | 0.2 | 0.001 | |||
8. | 0.1 | 0.7 | 0.0001 | ||
9. | 0.3 | 0.001 | |||
10. | 0.1 | 0.5 | 0.0001 | ||
11. | 0.2 | 0.001 | |||
12. | 0.1 | 0.0001 | |||
13. | -2 | -0.1 | 0.01 | ||
14. | 0.2 | 0.8 | 0.0001 | ||
15. | 0.1 | 0.8 | 0.001 |
4. .
: TStringGrid. .
4.1.
, . ( TApplication.HandleException), , . Object Pascal try, .
|
|
try finally:
Try
<,
>
Finally
< , ,
>
end;
finally.
. finally , , . , , .
tryexcept:
Try
<,
>
Except
< ,
>
end;
except, except . . except , . except , case:
on < 1> do < 1>;
on < 2> do < 2>;
else <,
>;
, do . 4.1.
4.1.
EAbort | , Abort |
EArrayError | : , ( mxarrays) |
EConvertError | |
EDivByZero | |
ERangeError | ( {$R+}) |
EIntOverflow | ( {$Q+ }) |
EInvalidArgument | |
EZeroDivide | |
EOutOfMemory | |
EFileNotFound | |
EInvalidFileName | |
EInvalidOp | |
EOverFlow | |
EAssertionFailed | Assert ( { $+ }) |
, , Stop on Delphi Exceptions Tools Debbuger Options , Language Exceptions ( Delphi 3 Break on exception, Tools Environment Options, Perferences).
|
|
. Abort, Assert (b: Boolean) raise:
Raise( < >). Create (< >);
4.2. ShowMessage MessageDlg.
ShowMessage MessageDlg, ShowMessage(Msg: string) Msg OK, . . MessageDlg(const Msg: WideString; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word . Msg . DlgType ( 4.2).
4.2. | |
mtWarning | : Warning. : |
mtError | : Error. : |
mtInformation | : Information. : i . |
mtConfirmation | : Confirmation . : ? . |
mtCustom | . . |
Buttons , ( 4.3). .
4.3. | |||
mbYes | Yes | mbRetry | Retry |
mbNo | No | mbIgnore | Ignore |
mbOK | OK | mbAll | All |
mbCancel | Cancel | mbHelp | Help |
mbAbort | Abort |
HelpCtx .
, . , mr , : mrYes, mrOK, mr Help.
4.3.
, . , , , : a[1], bb[I], c12[I,j*2], q[1,1,I*j-1]. LongInt.
(Type) (Var) :
Array [ ] of < >;
:
Const N=20; // ;
Type TVector= array [1..N] of word; // ;
Var a:TVector; // TVector;
Ss: array [1..10] of integer; // Ss ;
Y: array [1..5,1..10] of char; // Y .
, , :
F:=2*a[3]+a[ss[4]+1]*3;
a[n]:=1+sqrt(abs(a[n-1]));
4.4. TStringGrid
. TStringGrid , ( TEdit). Cells[ACol: Integer; ARow: Integer]: String, ACol, ARow - . ColCount RowCount , FixedCols FixedRows . , .
|
|
4.5.
: , NxN, , N.
. N TEdit, B TStringGrid. , TButton, TStringGrid.
4.5.1. TStringGrid
TStringGrid Additional . . , . ColCount RowCount 4 ( ), FixedCols FixedRows 1 ( ). .. StringGrid2 StringGrid3 , : ColCount= 1, RowCount=4, FixedCols=0 FixedRows=1. TStringGrid , StringGrid1 StringGrid2 Options ( +, Options) goEditing True.
. 4.1.
. 4.1.
4.1.
4.1.
unit Unit4;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, mxarrays;
Type
TForm1 = class (TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button2: TButton;
StringGrid3: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
end;
Const
Nmax=10; //
Type
Mas2 = array[1..Nmax,1..Nmax] of extended; //
// Nmax
Mas1 = array[1..Nmax] of extended; //
// Nmax
Var
Form1: TForm1;
A: Mas2; //
B, Y: Mas1; //
N, M, i, j: integer;
Implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
Begin
N:=3; //
M:=3; //
Edit1.Text:=FloatToStr(N);
Edit2.Text:=FloatToStr(M);
{ }
StringGrid1.RowCount:=N+1;
StringGrid1.ColCount:=M+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 i:=1 to N do begin
StringGrid1.Cells[0,i]:=' i= '+IntToStr(i);
StringGrid1.Cells[i,0]:=' j= '+IntToStr(i);
end;
end;
procedure TForm1.Button1Click(Sender: TObject); //
begin //
N:=StrToInt(Edit1.Text);
M:=StrToInt(Edit2.Text);
{ }
StringGrid1.RowCount:=N+1;
StringGrid1.ColCount:=M+1;
StringGrid2.RowCount:=N+1;
StringGrid3.RowCount:=N+1;
{ }
|
|
for i:=1 to N do StringGrid1.Cells[0,i]:=' i= '+IntToStr(i);
for i:=1 to M do StringGrid1.Cells[i,0]:=' j= '+IntToStr(i);
end;
procedure TForm1.Button2Click(Sender: TObject);
Begin
{$R+}
Try
{ StringGrid1}
for i:=1 to N do
for j:=1 to M do
A[i,j]:=StrToFloat(StringGrid1.Cells[j,i]);
{ B StringGrid2}
for i:=1 to N do
B[i]:=StrToFloat(StringGrid2.Cells[0,i]);
Except
on ERangeError do begin ShowMessage('
. '); Exit; end;
on EConvertError do begin ShowMessage('
, '); Exit; end;
else begin ShowMessage('
!'); Exit; end;
end;
Try
{ }
for i:=1 to N do begin
Y[i]:=0;
for j:=1 to M do Y[i]:=Y[i]+A[i,j]*B[j];
end;
Except
on EInvalidOp do begin MessageDlg(' ',mtError,[mbCancel],0); Exit; end;
on EOverFlow do begin MessageDlg(' ',mtError,[mbCancel],0); Exit; end;
else begin MessageDlg( ! ',mtError,[mbCancel],0); Exit; end;
end;
{ StringGrid3}
for i:=1 to N do StringGrid3.Cells[0,i]:=FloatToStrf(y[i],fffixed,6,0);
end;
End.
4.6.
. . TEdit, c TStringGrid, 0- 0- . , Tutton. .
1. NxM. B, k- 0, k - , 1 .
2. NxM. B, k- 1, k , 0 .
3. NxM. B, k- 1, k - , 0 .
4. NxM. , , .
5. NxM. , , , , , .
6. NxM. .
7. NxM. .
8. NxM. .
9. , n - .
10. A, NxM. B, k- k .
11. n - , , , .
12. NxM , , .
13. n - n-1 , .
14. n - , , , .
15. NxM. .
5. C
: .
5.1.
, , , , . , , , , .
|
|
c , :
Type
Pukaz=^< >;
Pint = ^integer;
TMas = array[1..4] of integer
PMas = ^TMas;
Var
Uk: Pukaz;
a, b: PInt; //
p, q: pointer; //
U: Pmas; //
C: array[1..2,1..2] of integer; //
Begin
...
U:=Addr(C); // U
// C
a:=p; // p a
p:=Nil; //
...
(a, b, p, q, u) 4 , , . () , , u^[2]:=3. , , , :
...
c[1,2]:=5; [2,1]:=8;
u:=@c; // u (@ Addr);
Write(u[2],u[3]); // 5 8
...
, (heap). New, Dispose GetMem, FreeMem.
New(var P: Pointer);
, P. P . ,
Dispose(var P: Pointer);
P , .
:
Var a, b: PInt;
Begin
New (a);
b:=a;
a^:=9;
b^:=5
Write(a); // 58
Dispose (b);
integer. b , a. , 9, 5. Dispose(b) Dispose(a).
GetMem , , , :
GetMem(P:pointer;size:Word);
FreeMem(P:pointer;size:Word);
, , , size.
, sizeof(< >).
5.2.
.
, , :
type Tmas = array[1..1000, 1..2000] of byte;
Pmas = ^Tmas
var B: Pmas //
begin
New(B); ..
< >
Dispose(B); //
, .
Getmem Freemem . , , :
type
Tmas=array[1..1] of extended;
Pmas=^Tmas; //
Var a: Pmas;
mt, n: word;
begin
mt:=sizeof(extended ); // ,
//
GetMem(a,mt*n); // n
< n>
FreeMem(a, mt*n); //
, .
:
Type
TMas = array [1..1] of integer;
PMas = ^TMas;
TMas2 = array [1..1] of PMas;
PMas2 = ^TMas2;
Var
a: PMas2;
N,M,i,j: integer;
Begin
GetMem(a,4*M);
for i:=1 to M do GetMem(a[i],N*sizeof(integer));
// [i,j], 1≤i≤M, 1≤j≤N
for i:=1 to M do FreeMem(a[i],N*sizeof(integer));
FreeMem(a,4*M);
5.3. TBitBtn
TBitBtn Additonal TButton. , Clyph. , Kind, 11 . bkClose .
5.4.
: , . . . 5.1.
. 5.1.
5.1.
5.1.
unit Unit5;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids;
Type
TForm1 = class (TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
end;
const N=7;
Type
TMas = array[1..1] of integer;
PMas = ^TMas;
Var
Form1: TForm1;
a: PMas;
i,j,t: integer;
Implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
Begin
Randomize;
for i:=1 to N do
StringGrid1.Cells[i-1,0]:=IntToStr(Random(100));
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
Begin
GetMem(a,N*sizeof(integer));
for i:=1 to N do
a[i]:=StrToInt(StringGrid1.Cells[i-1,0]);
for i:=1 to N-1 do
for j:=i+1 to N do