.


:




:

































 

 

 

 


. 4




- . TmpValue, :

Power:= TmpValue;

, . , , () .

Power(5, 2), Res 25.

, := ( ).

Writeln(Power(X, A) + Power(Y, B) + Power(Z, C));

3 Power , .

, , , . . .

 

5.5.1

, -, . , . function, () , , . , BEGIN..END:

 

function <>(< >): < >;

const... { , }

var... { }

Begin

<>

end;

 

<> , , Func1;

< > , ;, (Value: Real; Stepen: Integer);

! , , , . , -. Power Value Stepen, : X, Y, Z, A, B, C. , , , Power(5, 2). , ( -).

< > , , Integer, Real ..

:=, , -. .

5.5.2

, -, ( Pascal). , . procedure, () , . , BEGIN..END:

 

procedure <>(< >);

const... { , }

var... { }

Begin

<>

end;

 

A B, A > 0 (Real), B <> 0 (Integer). InputAB . , 100.

 

program ProcDemo;

{ InputAB . ValueA ValueB -

, InputAB

A B, }

procedure InputAB(var ValueA: Real; var ValueB: Integer);

Begin

Repeat

Write(' A ( ): ');

Readln(ValueA);

if ValueA <= 0 then

Writeln('! > 0. !');

until ValueA > 0;

 

Repeat

Write(' B ( ): ');

Readln(ValueB);

if ValueB = 0 then

Writeln('! = 0. !');

until ValueB <> 0;

end;

 

Var

A: Real;

B: Integer;

Begin

repeat { REPEAT}

InputAB(A, B); { InputAB}

Writeln(' A * B = ', A * B:8:2);

until A * B = 100; { REPEAT}

end.

 

, InputAB ValueA ValueB - ( var), InputAB A B, . ValueA ValueB , A B.

About:

 

program ProcDemo2;

 

procedure About; { }

Begin

Writeln(' ');

Writeln(' : ..');

Writeln(' : 1.0');

end;

 

Begin

About;

{ }

end.

About , . , .

5.5.3 - -

, , , Pascal ;. . 2 : ( -) ( -).

- ( ) . , . , , . :

 

procedure MyProc(MyParam: Integer); {MyParam - -}

Begin

...

end.

 

- ( ) -, . - , . - , .

, MyParam - ( var):

 

procedure MyProc(var MyParam: Integer); { MyParam - - }

Begin

MyParam:= MyParam * 2; { MyParam}

end;

 

Var

A: Integer;

Begin

A:= 5;

Writeln(A); { "5"}

MyProc(A); { MyProc}

Writeln(A); { "10"}

end.

 

, - -, :

 

procedure MyProc(A, B: Integer; var X: Real; C: Real; var Y: Integer);

 

A, B, C -, X, Y -.

 

5.5.4

, , . , .. . Pascal , . ( ), , , , .

, , . , , , , .

, , .

5.5.5

(, A) , (, B) , A , B. . , , , , , , , . ( )? . Pascal forward. :

 

procedure ProcA(S: string); forward; { }

 

procedure ProcB(S: string);

Begin

ProcA(S); { ProcA , }

end;

 

procedure ProcA; { }

Begin

Writeln(S); { Hello!}

end;

 

begin { }

ProcB('Hello!'); { ProcB 'Hello!' }

end.

5.5.6

, . , , ( ). () , .

 

 

5.6.

    0,1  
    0,2  
    0,5  
    0,1  
    0,2  
    0,5  
    0,1  
    0,2  
    0,5  
    0,1  
    0,2  
    0,5  
    0,1  
    0,2  
    0,5  
    0,1  
    0,2  
    0,5  
    0,1  
    0,5  

5.7. (. . 1.10)

5.8.

1) ?

2) ?

3) -?

4) -?

5) ?

6) ?

7) ?

8) ?

9) .

10) ?

11) ?

12) ? ?

 


6. Pascal

6.1.

Pascal.

6.2.

(. 6.7).

6.3.

:

, ;

;

. (. 6.6).

6.4.

1) (. 6.7).

2) (. 6.5).

3) .

4) (. 6.9).

5) (. . 1.10).

6.5. Pascal

6.5.1.

, : ( 0 9), ( , ), ( , ), . , , Char, 8 (1 ), 256 . ( 0 255), 0 127 ( ANSI). , , , , Unicode- ..

128 255 ( ). , . , , 127 (, , 50 . ), Pascal .

Char ( ) 6.1.

 

6.1

:

9 . . ( 8) . 8 1.

10 . .

13 . . .

32 .

, 6.1:

Var

I: Integer; { FOR }

C: Char; { }

Begin

WriteLn(' :');

for I:= 0 to 255 do { }

Begin

C:= Chr(I); { }

Write(I:3, ':', C, ' '); { }

if I mod 12 = 0 then { 12,}

WriteLn; { }

end;

end.

Char Readln, ( ), (), :

C:= 'F';

Char , , :

if (C >= 'A') and (C <= 'Z') then

Writeln(' !');

 

 

Pascal, Char, 6.1.

6.1 Pascal

Chr Byte Char x:= 68; y:= Chr(x); {y = 'D'} y:= Chr(2*x-5); {y=''}
Ord Char Byte x:= 'G'; y:= Ord(x); {y=71}
Pred Char Char x:= ''; y:= Pred(x); {y='A'}
Succ Char Char x:= ''; y:= Succ(x); {y=''}
Upcase Char Char Ch:= 'd'; Y:= Upcase(Ch); {Y='D'}

6.5.2. STRING.

, , . , , , . Pascal, 255 . , , . Pascal STRING. :

Const

sConstStr = ' 1'; { }

Var

S1: string; { 255 }

S2: string [10]; { 10 }

S3: string [8]; { 8 }

Begin

S1:= ' '; { }

Readln(S2); { }

S3:= sConstStr; { }

end;

Length:

Writeln(Length(S1)); { 26}

Pascal , :

StrLen:= Ord(S1[0]); { StrLen 26}

, Pascal , .

:

S1[0]:= Chr(Length(S1) - 1); { 1 }

 

 

, , , :

if S1 = 'hello' then

Writeln(' ')

Else

Writeln(' ');

 

, <> ( ), > (), >= ( ), < (), <= ( ). = <>.

('Hello' > 'hello') False, 'H' (72) , 'h' (104). , .

+, :

S2:= '';

S3:= '';

S1:= S2 + ' ' + S3; { S2 S3 }

Writeln(S1); { : }

 

( ), :

 

St[1]:= 'F'; { F}

Writeln(St[2]); { }

 

Pascal, , 6.2

 

6.2

procedure Delete( var S: string; Index: Integer; Count: Integer); Count S, Index S:= ' '; Delete(S, 4, 2); {St=''}
procedure Insert( Source: string; var S: string; Index: Integer); Source S, Index St1:= ''; Insert('*', St1, 4); {Str2='*'}
procedure Str( X: Real; var S: string); X (Integer Real) S V:= 1500; Str(V:6, St); {St:=' 1500'}
procedure Val( S: string; var V: Real; var Code: Integer); S V (Integer Real) . Code   St:= '1.455'; Val(St, V, Cod); {V=1.455, Cod=0}
function Copy( S: string; Index, Count: Integer): string; S Count , Index. Count , . St:= ' '; Y:= Copy(St, 2, 3); {Y=''}
function Pos( Substr, S: string): Integer; Substr S , , St2:= 'abc de f'; Y:= Pos('de', St2); {Y=4}

 

6.6.

, S:

 

program SortFIO;

 

type { TFIOElem TFIOArray}





:


: 2016-10-06; !; : 365 |


:

:

- - , .
==> ...

1409 - | 1417 -


© 2015-2024 lektsii.org - -

: 0.11 .