.


:




:

































 

 

 

 


if pos(decimalseparator,Cells[Col,Row])<>0 then

4

 

: .

 

1. , .

2. : - -.

3. for to (downto) do.

4. .

 

1. , n .

. . , 1 n 1 (. 4.1).

, .

 

 

 
 

 

 


. 4.1.

 

 

program lr4_1_1;

{ . }

{ $APPTYPE CONSOLE }

Uses

SysUtils;

Const

max n =100;{ }

Var

n, i:integer;

s:real;

a: array [1..maxn] of real;

Begin

write('n= ');

readln(n);{ }

writeln('Vvedite elementi massiva a ');

for i:=1 to n do

Begin

write('a [ ', i, ' ] = ');

readln(a [ i ]);

end;

s:=0;

for i:=1 to n do

s:= s + a [ i ];

writeln(' a, ', n:4, ' ');

for i:=1 to n do

write(a [ i ]:8:2);

writeln;

writeln('S = ',s:8:2);

readln;

end.

 

3 ( ) , Delphi.

StringGrid. Options(goEditing) true.

. 4.1.

 

. 4.1 4_1

 

Unit-a

 

unit Unit1;

//

Interface

Uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Grids, Buttons;

 

Type

TForm1 = class(TForm)

lbl1: TLabel;

lbledt1: TLabeledEdit;

btn1: TButton;

sd: TStringGrid;

btn2: TBitBtn;

lbl2: TLabel;

procedure lbledt1KeyPress(Sender: TObject; var Key: Char);

procedure btn1Click(Sender: TObject);

procedure sdKeyPress(Sender: TObject; var Key: Char);

Private

{ Private declarations }

Public

{ Public declarations }

end;

Var

Form1: TForm1;

Implementation

{$R *.dfm}

Var

n:Integer;

a:array[0..10] of Real;

s:Real;

procedure TForm1.lbledt1KeyPress(Sender: TObject; var Key: Char);

//

//Backspace Enter

Var

i:Integer;

Begin

Case Key of

'0'..'9',#8:;

#13: begin

// StringGrid

sd.ColCount:=strtoint(lbledt1.Text);

n:=sd.ColCount;

sd.Options:=sd.Options+[goEditing];

sd.Width:=n*(sd.DefaultColWidth+2);

for i:=0 to n-1 do

sd.Cells[i,0]:=' '+inttostr(i);

sd.SetFocus;

End

Else

key:=#0;

end;

end;

 

procedure TForm1.btn1Click(Sender: TObject);

Var

i:Integer;

Begin

f o r i:=0 to n-1 do

a[i]:= strtofloat(sd.Cells[i,1]);

s:=0;

fo r i:=0 to n-1 do

s:=s+a[i];

sd.ColCount:=sd.ColCount+1;

sd.Width:=(n+1)*(sd.DefaultColWidth+2);

sd.Cells[n,0]:=' ';

sd.Cells[n,1]:=FloatToStrF(s,ffFixed,8,3);

end;

 

procedure TForm1.sdKeyPress(Sender: TObject; var Key: Char);

// StringGrid

Begin

With sd do

Case Key of

'0'..'9',#8:;

'-': begin

if (Cells[Col,Row]='') then

key:='-'

Else

if (Cells[Col,Row]<>'') and ((copy(Cells[Col,Row],length(Cells[Col,Row]),1)='E') or

(copy(Cells[Col,Row],length(Cells[Col,Row]),1)='e'))then

key:='-'

Else

key:=#0;

end;

'+': begin

if (Cells[Col,Row]='') then

key:='+'

Else

if (Cells[Col,Row]<>'') and ((copy(Cells[Col,Row],length(Cells[Col,Row]),1)='E') or

(copy(Cells[Col,Row],length(Cells[Col,Row]),1)='e')) then

key:='+'

Else

key:=#0;

end;

',','.': begin

key:=decimalseparator;

if pos(decimalseparator,Cells[Col,Row])<>0 then

key:=#0

end;

'E','e': begin

key:='E';

if ((pos('E',Cells[Col,Row])<>0) or (pos('e',Cells[Col,Row])<>0))

or ((length(Cells[Col,Row])=1)

and ((copy(Cells[Col,Row],1,1)='-') or

(copy(Cells[Col,Row],1,1)='+'))) or

((length(Cells[Col,Row])=0)

And

((pos('E',Cells[Col,Row])=0) or (pos('e',Cells[Col,Row])=0))) then

key:=#0;

e n d;

#13: if col<colcount-1 then

col:=col+1;

 

Else

key:=#0;

end;

 

end;

 

end.

 



<== | ==>
| 
:


: 2016-11-24; !; : 272 |


:

:

! . .
==> ...

1936 - | 1730 -


© 2015-2024 lektsii.org - -

: 0.023 .