Upload
deadsock
View
97
Download
4
Embed Size (px)
Citation preview
1
090102
-
2006
I. 2
1. ............................................................................4 1.1. ...............................................................................................................4 1.2. ..........................................................................................................................4 1.3. ..............................................................................................................5 1.4. ............................................................................................6 1.5. .............................................................................................................6 1.6. ......................................................................................6 1.7. ...................................................................................................................6 1.8. ....................................................................................6 1.9. ............................................................................................7
2. ..................................................................................................................8 2.1. ..............................................................................................8 2.2. .................................................................................................................................8 2.3. ........................................................................................................................................8
3. .............................................................................................................................................10 3.1. , , ................................................................10 3.2. 1.......................................................13
4. .............................................................................14 .............................................................................15
5. 7.0................................................................16 6. ...........................................................................................................................18
6.1. ................................................................................................................18 6.1.1. , ...................................................................18 6.1.2. ........................................................................................................................19 6.1.3. ................................................................................................................................19 6.1.4. ....................................................................................................................20 6.1.5. .................................................................................................20
6.2. .......................................................................................20 6.3. ..........................................................................22
7. ...............................................................................................................23 7.1. .................................................................24 7.2. ...................................................................................................................26
7.2.1. () ..........................................................................................27 7.2.2. ......................................................................................................................28 7.2.3. .........................................................................................................30 7.2.4. .................................................................................................................31 7.2.5. ..............................................................................................................32
7.3. ..............................................................................................................32 7.4. .....................................................................................................................................35
7.4.1. ...........................................................................................................35 7.4.2. ..................................................................................................36 7.4.3. ..........................................................36
8. ..................................................................................37 8.1. ............................................................................................................37 8.2. () ...............................................................38
8.2.1. ......................................................................38 8.2.2. ......................................................................................38
9. .......................................................................................................39 10. .............................................................................................................40 11. - .......................................................................................41
I. 3
11.1. Input Output ...................................................................................41 11.2. ...............................................................................................................42 11.3. ....................................................................................................................43
12. .........................................44 12.1. .....................................................................................................45
13. ....................................................................................................46 13.1. CASE........................................................................................................46 13.2. .............................................................................................................48
14. ..............................................................................49 14.1. (While) .............................................................................................49 14.2. (Repeat until).............................................................................49
1. ...............................................................................................51 .............................................................................................................51 .........................................................................................................................51 ...................................................................................................................51
.........................................................................................51 .........................................................................................................................52 ...................................................................................................................52
....................................................................................................................52 .........................................................................................................................52 ...................................................................................................................53
.......................................................................................................................53 .................................................................................................54 .........................................................................................................................54 ...................................................................................................................55
I. 4
1. ,
. , , . , .
: 1. ( ); 2. ; 3. ; 4. ; 5. ; 6. ; 7. ; 8. .
1.1.
. . , . , , , .
1.2. ,
) ; ) , .. ; ) .
, (, ) , . . 1 2 ,
. :
. ,
: : ( ); ( ). : ( ).
, , , . .. .
, :
I. 5
= - * - , ,
: = * ,
- . (abstraction). 1.3.
- (IX .),
( ) . . , . . , , , , , . , . , :
1) , . . . , (, , ) : ;
2) , , . . , ;
3) . ;
4) , , . , , ;
5) . . , . , . n , . .
6) . , , . , , , - . .
, , . , : - , , , ()
I. 6
.
. ; . ( " ") , . , :
1. ; 2. ; 3. . ,
. , , , . .
. , ( ), , . , .
1.4. ,
. , .
1.5. .
.
, . .
1.6. ,
. . , , , , . .
1.7.
. : . . . .
1.8.
.
I. 7
1.9.
,
, .
, ,
.
. . , , . , 1 . = 1000 .
, , , , . Kq Gr , .
: Kg { } Gr { }
: 1 . = 1000 . , .
, : 1. ; 2. ; 3. . , -
, . 1 ( ) 3 ( ) , . 2, , .
2: , , ,
1000.
. 2 2.1 2 .
1. . 2. .
2.1. , , , 1000. 3. .
, , . , , 2 . ( 1), 1000, 2 000 ( 2.1). ( 3).
I. 8
Pascal-. , , . Pascal-. - , , .
2.
2.1. , . . . (.2.1).
2.2. , , . , , ( ), , (.2.2.). , , , .
. 2.1. . 2.2.
2.3. / / , - , - . (. 2.3.):
; ,
; /
;
I. 9
/ .
, , : ,
(. 2.3, ); , (.
2.3, ).
. 2.3.
I. 10
3.
3.1. , ,
( )
( , , , ).
( )
(-)
( , ).
()
, , ( , ).
( , )
-
, () ()
, , . . , , . . , . 1.
. - .
I. 11
. . . 2.
( ) , , . . , . 3.
1
2
3
a b. a 10 , , 5. b=1,5. b, 1:2. .
, .
. S 0,6 1,5 .
I. 12
1. 1.1 ,
, . 1.2 .
. 1.3 ,
. , , . , . , , .
, , , . , .
1.4 , , . (. 4).
4 -
, , , .
, .
1.5 . , (, ). (. 5).
5 -
2 2.1 .
. , (,
), . , , .
2.2 .
I. 13
, .
2.3 . , (. 6).
6 -
2.4 , , , . .
2.5 , , . , .
2.6 (. 7).
7 -
3 : ; ,
(. 8).
8 -
, , , , , .
3.2. 1. . . . .
I. 14
4.
, (). , , , , . , , . , . - , , -.
, . ( ), , , . Microsoft (MS-DOS, MS Windows), UNIX. , . , .
- . , , , ( , ). . . , , . , . . . , .
, . , . , , . , .
: (), , , -.
, , . - .
, . , , . LISP.
I. 15
, , , - . - . Prolog.
- - Object Pascal, Java, C++, #. , , , HTML.
Pascal . - . , : , . . , . ! Turbo Pascal Pascal, Borland 80- . , Turbo Pascal ( 7).
. Short
Code, 1949 BINAC, -0, -1 -2, . FORTRAN, IBM . . , , . FORTRAN , . ALGOL. . - ALGOL 68, ALGOL. . , , , . ALGOL W, Pascal, , . , : , , , , . .
, . 80- Borland Turbo Pascal. Pascal , Turbo Pascal, . Turbo Pascal Delphi Microsoft Windows (RAD Rapid Application Development) Kylix X Window System UNIX.
Pascal . . - C++, , , Java. . , - .
I. 16
, . , , , .
5. 7.0. () , ,
, , . , , , . ,
: , . ( ) () - . ( ) . ( ) , . : File . Edit . Search
. Run
. Compile , . Debug . Tools
. Options ,
. Window . Help
Turbo Pascal. ( Edit)
, . . :
F10 Esc; . ( (), (), () ()); , Enter. Esc; , , : 1) , , ; 2)
File Edit Search Run Compile Debug Tools Options Window Help
I. 17
, , , ( Ins). (BackSpace) Del: , - , . Enter. / Esc, .
" ", Alt-, - , .. : F, E, S, R, C, D, T, O, W, H. -
, . , , . : Edit Watch. Edit (
) . Watch , . Watch ( ), . , , Edit, Edit Edit Alt-E. , ,
. , (, ..). ""
:
F10 - ; Esc - ; Alt-X - ; Ctrl-Break - .
. Print Screen - . Pause -
.
.
I. 18
6.
6.1. . :
, _; 0 9; , +, *, { @; : , .
, , :
(); ; ; (, , , ). ; ; ; .
. -, 128, Proba, goto +. .
, . .
6.1.1. , , ,
, . .
, : ; , ; ; .
, Proba, B, B22 A_and_B, 21 ate, Big gig 5 ( , , ).
, : , , , , . .
() , . , . , goto, var. , , .
. , -
. . ,
I. 19
6.1.2. , .
-
2 15
$0101 SFFA4
-0.26 .005 21.
1.24 0.1-5
'g' #186 ^M
'' ' ABCDEF'
, . $, (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, , , , D, , F). 257 65 444.
. , . . , . 10. 1,2104 0,110-5. .
, . 1 , 256 . . MS-DOS ASCII, ( 0 127); ( 128 255) . , . , .
1. , . 2. , #. -
, . 3. , ^ (). -
. 64 , ( 13, ).
ASCII-, - . , . 126 .
6.1.3. : 1) 0 9999. 2) .
: goto metka; .. .. , Metka: a:=a+1;
I. 20
6.1.4. : {}. (* *): (* *).
( - ).
6.1.5. : {$I+} {$N+}
, . :
1) ; 2) ; 3) . {$I+} {$I-}
. , ( , ). .
6.2. :
I. 21
Program ;
Uses
Const
Type
Label
Var
begin end.
( , )
Program ;
. Uses
. Uses, Program, , , .
: Label 1, 2, ..., n;
I. 22
:
(Const, Type, Var ) , .. , , . 2 :
1) ; 2)
. , ,
, , . ( ), :
: unit ; end.
:
procedure ( ); end;
: function ( ): ; end;
6.3.
, () . :
(, , ) .
1-2 .
? ( ), 1 , .
, Program. Uses, Label, Type, Const, Var,
I. 23
, begin end, , , 1 Program.
Uses, Label, Type, Const, Var, , begin end, , , , . Type Var , : = . . : Program P1; uses crt; type t1= array[1..20] of char; t2= string2=15]. t3= record a:byte; b: char; end; var v1 :t1; v2 :t2; v3 :t3; begin .......... end.
7. , , .
, , , . . : , ,
; ( ).
, , , ; , , , .
. .
I. 24
7.1. :
, , , ,
, . . , , . . .
. , , . : Var a: byte; { 1 } b: integer; { 2 } c: Real; { 6 }
,
, , . , : .
I. 25
:
Type = ; Type M = record a, b: byte: end;
: Var 1: ; 2: ; : Var v1: array [1..10] of char; v2: byte; v1 , , v2 - .
, , :
I. 26
Const N = 2; C = 'c'; D = 1.28; E = $AD; F = 'abcd';
, , , ( ).
, . :
Const N: byte = 2; C: char = 'c';
, : , , . - , .
, . , . 7.2.
, , , - . , :
; Ord,
;
Pred Succ, ;
Low High, .
I. 27
= < >=. , . , .
7.2.1. ()
boolean. 1 : true () false (). false 0 (), true 1.
and, or, not.
: a b a and b a or b a xor b not a
false false false false false true false true false true true true true true true true false false true False false true true false
-
. . and , .
true, true. or ( , ) true,
true. , false or true true, true or true true.
, . , .
not , , . , not true false.
, , .
> >= <
I. 28
7.2.2.
( ). , : , . ( ). :
integer 2 -32 768 .. 32 767 (-215 .. 215-1) shortint 1 -128 .. 127 (-27 .. 27-1) byte 1 0 .. 255 (0 .. 28-1) word 2 0 .. 65 535 (0 .. 216-1) longint 4 -2 147 483 648 .. 2 147 483 647(-231 231-1)
integer, . , 4 , , 0 100.
.
( ). + - * div mod
, . , 3 < 8 true.
. . (, i):
( )
Xi not Xi 0 1 1 0
Var x = 2 x:byte; begin 00000010 x:=2; not x = 253 11111101 not x = 253
I. 29
( )
Xi Yi Xi and Yi 0 0 0 0 1 0 1 0 0 1 1 1
( )
Xi Yi Xi or Yi 0 0 0 0 1 1 1 0 1 1 1 1
. , , .
Xi Yi Xi xor Yi 0 0 0 0 1 1 1 0 1 1 1 0 : X Shl Y - X Y X shr Y - X Y .
( ) ( ): ; . ,
, . ( ).
, . N 2N, N ( ) 2N.
shortint, integer longint ( ) . . SHR .
, . Range Checking. , .
, 12 shr 2 3, 12 1100. 12 shl 1, 1 , 24.
:
1) ; 2) ( ) ; 3) ( 0 1) ; 4) (
I. 30
not); 5) .
( , ).
abs || abs(x) arctan * arctg x arctan(x) cos cos x cos(x) () ln logex ln() odd odd(3) true pred pred(3) 2 sin sin x sin(x) sqr 2 sqr(x) sqrt x sqrt(x) succ succ(3) 4 inc inc(x) 1
inc(x, 3) 3 dec dec(x) 1
dec(x, 3) 3 * . : : . : Var x, y: integer; begin x := 10; c := -10; Dec(x); { Dec} y := abs(c); { abs} end.
7.2.3. (, , )
. . : word, byte, integer, char, Boolean.
( ), . :
I. 31
Var 0 1 2 3 4 5 ----- v:(a, b, c, d, e, f);
:
byte=(0,1,..,255); char=(0, 1, , 255);
boolean = (false, true); , :
- 0; 1, - ( ) 1 , .
: . . Watch.
: ( ) ?
7.2.4.
.
:
Var v: .. ;
1. , . :
Var v: 1..10; { }
v: 10..1; { }
2. - , -. .
Var s: a..z; - (char) .
3. , , . , . 4. Range Checking {$R+} , .
I. 32
7.2.5. :
Var c: char;
1 . 0 255. (
ASCII), : c := ; ------ 3210. c := 1; ------- 6110. (=, =, ),
. , . , .
:
ord
ord(' b') 98 ord(' ') 238
Chr chr (98) ' b' ch (238) ''
pred pred(' b') ' ' succ succ(' b') ' ' upcase * upcase(' b') ' '* '' .. 'z'.
7.3.
, . , . , 0,087 0,87x10-1, 87 -1 ( , ).
, . , . ,
real 6 11-12 2.9-39 .. 1.7+38 single 4 7-8 1.5-45 .. 3.4+38 double 8 15-16 5.0-324 . . 1.7+308 extended 10 19-20 3.4-4932 .. 1.1+4923
comp 8 19-20 -9.2218 .. 9.2218
(-263 .. 263-1)
. .
Real , . . Comp . , , ,
I. 33
. , Comp . Comp , .
Extended, Extended .
. 2 :
- ; - , , ,
. (- ). Real :
S M E Real
S E M Single
: Single, Double, Extended . Real .
Extended. Real, Extended Real .
, Real, - Single Double. 2 .
. 1) :
{$N+} , 5 . {$N-} , Real. {$N-}.
, . {$N-} :
Var v: Single;
2) , : ()
(
). {$E+} - , , {$E-} -
. {$E+}. () , .. .
()
{$N+} {$N-}
I. 34
{$E-}, , .
1. {$N+} {$E+} 2. {$N+} {$E-} 3. {$N-} {$E+} 4. {$N-} {$E-}
1- , . , , - .
2- : {$N+} , , .
3- 4-: {$E} .
, , , .. ? :
1) 5 , : {$IFDEF CPU87} {$N+} ( {$ELSE} ) {$N-} {$ENDIF}
2) Real Single,
: {$IFOPT N+} {$N } float, type real=single; {$IFOPT N+} - {$ENDIF} type float = single; Real Single {$ELSE} type float = real; {$ENDIF} Var R:float;
, ,
.
. .
+ - * / , . , . . , .
I. 35
, /, di v. . .
abs || abs(x) arctan arctg x arctan(x) cos cos x cos(x) () frac frac(3.1) 0,1 int int(3.1) 3,0 ln logex ln() pi 3,1415926536 round round(3.1) 3
round (3.8) 4 sin sin x sin(x) sqr 2 sqr(x) sqrt x sqrt(x) trunc trunc(3.1) 3
7.4.
7.4.1. . : (string); string; ( ).
string 255 . , . . , string 256 . , , : type str6 = string [6]; str6. 7 . . , . : const n = 15; var s : string; { } s1 : str6; { str6, } s2 : string [n]; { } , ,
I. 36
. const s3 : string [15] = '1234567890'; s3 .
7.4.2. 1. .
, : s2 := '1234567890'; s1 := s2: { s1 "123456" }
2. () , +, : s1 := '': s2 := s1 + ''; { - "" }
3. .
, . , . . 'abc' > 'ab' 'abc' = 'abc' 'abc' < 'abc '
4. -: readln (s1); write (s1): , , ( Enter) . , .
5. , sl[4]. char, , : sl[4] := 'x'; writeln (s2[3] + s2[5] + '');
7.4.3. , , -
, , , . .
I. 37
1. Concat(si, s2.....sn) , s1, s2,..., sn. .
2. Copy(s, start, len) len, start s. len start .
3. Delete(s, start, len) s, start, len.
4. Insert(subs, s, start) s subs, start.
5. Length(s) s, byte. 6. Pos(subs, s) subs s
subs s , subs s. 7. Str(x, s) s,
, Str(x:6:2. s). 8. Val (s, x, errcode) s ,
s . errcode . , errcode , .
8.
8.1. - .
, .
. , :
; ; ; - ; - ; ,
; (
PACKED) ; -, - -, ; , - ; , - ; ( -),
. .
1 - , 2 - , .. 1 :=T2. : T1 2
, , -, ; T1 2 2
1; 1 2 2
1; 1 - 2 - ; T1 - T2 - ; 1 - 2 - ;
I. 38
T1 2 - ; T1 T2 - 2
1; T1 2 - ; 1 2 - ; T1 - 2 - .
, , . Type mismatch. 8.2. () . .
8.2.1. , , -. ORD, TRUNC, ROUND, CHR. , () , , .
, , typel type2 (
). , typel, type2. , , - .
y := type2(x) , , type2, . , N Byte, a ch Char, :
Ch := Char(N); N := Byte(Ch); .
: TypeID(expression),
TypeID , expressi on, . , . . , . , , . .
8.2.2. .
:
I. 39
1. .. .
2. . .
3. .
, , , . ABSOLUTE, , . WORD, ; , - . :
b : byte absolute $0000:$0055; w : longlnt absolute $128:$0;
ABSOLUTE , , , : var : word; : word absolute x; x y . , .. . . , . : var st : string[30]; srlen : byte absolute st; : var srlen : byte; sr : string absolute stlen; st stlen, , st.
9. . ,
. , . , . , .
, . , , . , . .
, . 1. not, -, @. 2. : *, /, div, mod, and, shl, shr. 3. : +, -, or, xor.
I. 40
4. : =, , , =, in. , , . . .
: , , . , .
:
x + 4 - Sin(x); x - , 4 - , Sin - .
() , ( ). . - .
: (a>b) or false and (c>d). .
. : .
, . , ( ). .
(1>2) and ((c>d) or (a
I. 41
, . , . ( : = + 0.5). , , . 0,5, . , , . .
, , . , . , , , :
:= ;
11. -
11.1. Input Output
()
, . . . , , (console).
- , , - .
, , , ( - , ).
: Input ( ) Output ( ). , , - .
Input Output , - . .. , . - , Output , Input. , , , .. .
Input output , .. . ,
EOLN #13+#10,
( Input )
( Output)
I. 42
- #13 - ( CR). ;
- #10 . .
EOF #26. ,
-. , - , , .
11.2. read readln. d(); readln[()]; . , . :
: read(a. b. ); readln(y); readln;
. , , . (, , ).
: 1. , .
2. , - .
3. , . , 3.78 real -
(3, , 7 8) .
, dln . , , . read . dln Enter.
, , . , var a : integer; b : real; d : char; read(a, b, ). , , 2, b 3,78, d #.
I. 43
, , , d. 2 3.78# 2 3.78# 2 3.78 # Tab. , d . , : readln(a, b); readln(d); . , . Enter (#13#10). read, readln, , , , . read(a); { } write(' ? (/n) '); readln(d); { #13 } , read readln.
11.3. :
, . write writeln.
write(); writeln[()]; write , writeln
. writeln .
:
, , ,
. , ,
:
:
I. 44
writeln(' = ', :4, ' b = ', b:6:2, sin(a) + b): ( b ).
, . , , . . , . .
, b. b , , , ( , ).
, ( ).
= _ _ _ 2 b = _ _ 3.78 4.6892974268+00 , ,
. . ,
, , , . ,
. , ; , .
, , . , . , .
, , . 17 , 10 .
. .
. .
12. . :
I. 45
: For := to do ;
For := downto do ; , .
( ). ( +1, (-1)). (, , , , - ). . , 7- , 2 ,
: For i := 1 to 10 do begin ... break; continue; ... end; Break - () . Continue : - - - ( ).
12.1. - .
: =f(x) , x0 n hx (. 12.1).
. 12.1.
I. 46
( ) - f(x) ; - . , 0, 0 + hx , 0 + 2hx , 0 + 3hx , , n , - , , . , . - . , Nx
Nx = [(xn x0) / hx] +1, [ ] . , , : . : . , - .
13.
13.1. CASE
: Case of 1 : 1; 2 : 1;
N : N; end; {case} "" .
, . :
1- : 2- : , 3- : 4- : . : ,
: ( ) ? Var C : char; Begin Read(c); Case of 'A' ..'Z' : writeln( ); 'a' ..'z' : writeln(' ');
I. 47
'0' ..'9' : writeln(' '); end; {case} end. 1: ,
longint. 2:
. (begin-end).
:
Case of 1 : 1; 2 : 1;
(N-1) : (N-1) else N end; {case} :
1: ,
: ( ) ? Var C : char; Begin Read(c); Case of
I. 48
'A' ..'Z' : writeln( ); 'a' ..'z' : writeln(' '); '0' ..'9' : writeln(' ') else writeln(' ) end; {case} end.
13.2. ,
, : 1 1 2
:
1, ,
.
1 1 1 -------------
if: :
if then 1
else 2;
: if then 1;
1 1 1 2
;
I. 49
14. FOR ,
: 1) . 2) . 3)
. .
: 1) , ; 2) ,
( ). :
; .
14.1. (While)
:
:
while do ;
: ( ). , ( ) . False, . : False , .
while . do, Pascal , . "" . : while true do : while while . , begin-end.
14.2. (Repeat until)
:
I. 50
:
repeat until ;
: , . True, . False, . repeat . : repeat until false; Repeat - until .
I. 51
1.
19.504-79
, 19.101-77
2095-80
1.1 19.105-
78. ( ) . 1.2 :
; ; ; ; .
.
1. , , , ( , , ..).
2. ( , , ..).
3. ( ..).
4. , , .
5. , , , .
6. (, , ..).
19503-79*
, 19.101-77.
2094-80 ( , . 1).
I. 52
19.105-78. :
; ; ; ; ; .
.
, .
1. , .
2. , , .
3. ( , .).
4. . 5. , ( , , ).
6. .
7. , , , , , .
8. (, , , . .).
19.505 79*
19.105 78. ( ) .
1. : ; ; ; .
I. 53
2. .
1. , .
2. , ( () ..).
3. : , , , , , , , .
4. ( , . 1). 5. (, . 1). 6. , , ( , ..)
7. , , , .
8. ( , . 1). 9. , .
19.402-78
1. , 19.101-77.
2. 2092-80. 3. 19.105-
78. 4. ( ) .
5. : ; ; ; ; ; ; .
. :
; , ; , .
I. 54
() . :
; ;
; .
. , . :
; .
, , . :
, ; , .
: ; , .
, , , . , .
. 19.301-79
, 19.101-77.
3747-82. ( , . 1,2)
1.1.
19.105-78. ( )
. 1.2.
: ; ; ; ; .
.
( , . 1,2 )
I. 55
1. , .
2. . 3. ,
4. , , , .
5. , , .
6. . , .
7. ( , . .).
8. , , , . .