Professional Documents
Culture Documents
, -
.
, -
.
-
. 14 , .
( 1-5) -
,
. -
-
.
. -
-
. -
. -
.
,
.
, , -
. -
.
( ). -
, -
. -
, -
, -
. -
, -
.
iv
, , -
, -
.
:
1. ...........................................................................1
1.1 .........................................................................3
1.2 ..............................................................5
1.3 ........................................................................8
1.4 ..............................................................11
1.5 ...........................................................16
1.6 ..........................................................18
2. ................................................................23
2.1 ........................................................................25
2.2 ..........................................................27
2.3 ................................28
2.4 / .............................28
2.4.1 .............................................................30
2.4.2 .................................................................32
2.4.3 ..................................35
2.4.4 .............................................37
2.4.5 ..........................................................39
3. ........................................................51
3.1 .......................................................................................53
3.2 + = ........................54
3.3 .........................................................................................56
3.4 ...........................................................................................59
3.5 .............................................................................................60
3.6 ....................................................................................64
3.7 ...................................................................................66
3.8 ......................................................................................69
vi
3.8.1 .....................................69
3.8.2 .....................70
3.8.3 Fibonacci...................72
3.9 .................................................................73
3.9.1 .................................................................................73
3.9.2 ................................................................................75
3.9.3 ................................................................................75
4. ...........................................................79
4.1 ................................................................81
4.2 ...................................................83
4.3 .......................................................85
4.4 ......................................................87
4.5 .........................................................................90
5. ............................................................................95
5.1 ....................................................................97
5.1.1 ..........................97
5.1.2 ..................................98
5.1.3 ........99
5.1.4 .........................................100
5.2 ...............................................................101
5.3 .....................................................104
5.3.1 ...................................107
5.3.2 .....................................................108
5.4 .........................................................................109
6. .......................................................115
6. 1 .....................................................117
vii
6.2 .....................................................................117
6.2.1 ...........................................................118
6.2.2 .....118
6.2.3 ............................................119
6.2.4 4 .........................................................127
6.3 . ..................................................130
6.4 ...........................................131
6.4.1 ..............................132
6.4.2 ......................................132
6.4.3 .......................................132
6.5 ....................................136
6.6 .................................................137
6.7 .............................................137
7. ...................................................145
7.1 ........................................................148
7.2 ........................................................................148
7.3 .....................................................................................149
7.4 ................................................................................151
7.5 ..................................................................152
7.6 ................................................................................153
7.7 ...............................................................153
7.8 ......................................................................154
7.9 - .............................................................155
7.10 ................................................................157
8. ......................................................................163
8.1 ........................................................................165
8.1.1 .........................................................................166
viii
8.1.2 .............................................................172
8.2 ..................................................................173
8.2.1 ...............................................173
8.2.2 _ ...................................................175
8.2.3 ....................................................178
9. .................................................................................................183
9.1. . ...........................................................185
9.2. ..............................191
9.3. .............................................................191
9.4. .................................................198
10. ..............................................................................203
10.1. ................................................205
10.2. ...............................207
10.3. ..............208
10.4. .............................................................................209
10.5. ...................................................210
10.5.1 ..................................213
10.5.2 ....................................214
10.5.3 ..........................216
10.6. -. ...........................................220
10.7. .................................................................................222
11. ..................................229
11.1. .................................231
11.1.1 ....................................................................232
11.1.2 ...........................................................................234
11.1.3 ........................................................................235
ix
11.1.4 .........................................................................237
11.2. .....................238
11.2.1 ...................................................................239
11.2.2 .............................................240
11.3.
...............................................241
11.4. ........248
11.4.1 ............................................................249
11.4.2 ..........................................................251
11.5. .............................................252
12. ..............................................................259
12.1. ......................................................................261
12.2. ..........................................................262
12.3. ..........................................266
12.4. ..................................270
12.4.1 .......................................................................271
12.4.2 ........................................................273
12.5. .................................274
13. .......................................................279
13.1 ....................................................................281
13.2 .........................................................................284
13.3. ......................................................284
13.4 ..............................288
14. - .................................................................291
14.1 .....................................293
14.1.1 - .................................................293
14.1.2 ..........................................................................297
x
14.1.3 ......................................................................301
14.1.4 .......................................................................305
14.2 ...............................................308
14.2.1 ........................................................310
14.2.2 ...............................................310
14.2.3 .............................................315
14.3 ..........................................................315
: ASCII....................................................................323
............................................................................326
................................................................................................327
.............................................................................................333
.................................................................................................337
1.
2
, .
, , -
, -
, -
.
, -
, -
, .
:
-
-
-
3
-
;
3 2000";
3 -
;
3 ,
;
3
1.1
,
. ,
,
. -
, -
,
, -
, . -
-
,
.
: -
, , ,
.
, ,
, -
.
, -
.
-
. ,
-
.
,
.
, -
,
.
-
Robin Wood
Nottingham.
,
.
4
-
2000
(millennium bug). -
. , 15 1999 -
150499.
,
-
, -
. 21
010100,
.
2000 . -
()
. -
-
.
, -
, , , - -
,
2000.
, -
-
. 2000
.
, ,
.
, ,
,
, Pasteur Fleming, -
.
-
-
.
-
5
,
, , -
, .
,
,
-
.
, , ,
,
, -
, -
.
-
, ,
,
, -
-
.
-
, -
-
.
, , -
, -
, , -
, .
1.2
-
. -
,
.
-
6
-
.
. -
, -
, , -
.
,
, , , -
. -
. -
, .
-
.
. -
. ,
, .
-
. , ,
-
. -
. -
.
1
,
. -
, .
7
, -
:
. -
. .
,
. -
, .
, . -
, , -
.
. -
. .
. -
. ,
, . - - -
.
: .
: -
.
. , -
( ) -
( ).
.
-
. -
. -
-
.
8
:
.
-
.
, -
.
-
. ,
.
1.3
.
-
.
, . -
-
.
: -
, -
.
-
. -
-
,
.
.
9
-
.
, :
(1)
(2)
(3)
-
.
.
(1) ,
:
(1.1)
(1.2) , -
(1.3)
(2) , -
:
(2.1)
(2.2)
(2.3)
(3) ,
:
(3.1) -
(3.2)
(1.1) -
:
(1.1.1)
(1.1.2)
(1.1.3)
10
(1.2),
:
(1.2.1)
(1.2.2) -
(1.2.3)
, -
-
.
.
, -
, -
.
-
. -
-
. :
-
-
,
-
,
. , -
-
.
1.1.
11
. 1.1.
. -
,
.
1.4
-
. -
-
.
-
. -
. -
. , -
. -
, -
.
12
. -
.
, , .. -
-
, -
.
, -
-
. -
, -
-
.
: -
.
, -
.
:
, , -
,
. -
.
. -
.
;
.
, -
;
-
.
, . -
.
13
1.1.
: 9
: : 2
:
/
1 10
2 17
3 15
. -
100 , -
.
. -
1.1.
,
. ,
-
. -
.
:
100 ;
, ,
.
, ,
.
.
: -
, ;
.
-
92 8.
, , -
.., 5809 , 5287
522 . -
14
-
. , ,
. -
, -
.
-
.
,
10 13 ..
, -
. -
, -
1.2.
1.2.
1999-2000.
%
0 9 522 9,0
10 13 1211 20,8
14 15 2120 36,5
16 17 1180 20,3
18 20 776 13,4
5809 100
1.2 -
, -
( ) -
-
( ).
-
, .
, 1.2,
, -
. -
1000 .
15
. 1.2. .
, -
.
, -
.
,
.
, .
. -
, -
, , -
. ,
( ),
.
16
-
( 1.3):
,
, -
, ,
.
. 1.3. -
1.5
-
, ,
. ,
. -
.
1. ,
:
,
. -
, -
, -
.
,
, ,
.
, .
,
, . -
-
. -
, .
17
2. , -
:
, -
. -
, -
,
.
,
,
.
-
. -
, ,
-
.
, -
-
. -
. -
,
.
-
.
3. , -
. -
, :
, -
, ,
. - -
. -
,
.
:
, .
, -
18
, .
.
:
.
,
. -
-
.
:
.
1.6
, . -
-
. -
, ,
. -
,
.
,
, -
,
, ;
-
.
. -
.
-
.
, .
, , -
19
-
. -
.
-
, , .
.
. -
,
, . ,
. -
,
,
.
-
, .
,
-
3 .
-
3 ,
3 ,
3 ,
3 .
,
:
3 , ,
,
3 , -
,
3 , -
.
,
.
20
.
-
.
.
.
,
,
.
-
.
-
. -
-
. -
, -
.
.
.
-
, -
.
, , , -
, , , .
21
-
.
.
.
, , -
.
-
1.4.
.
-
;
-
.
1. Jacques Arsac, Les machines a penser Des ordinateurs et des hommes,
Seuil, Paris, 1987.
2. Emanuel Falkenauer, Genetic algorithms and grouping problems, Wiley,
1998.
3. Les Goldschlager & Andrew Lister: Computer Science A modern
introduction, Prentice Hall, 1990.
4. R. Kadesch, Problem Solving-Across the Disciplines, Prentice Hall
Engineering, Science & Math, 1996.
5. Nicholas Negroponte, Being digital, Alfred Knopf Inc, 1995.
6. G. Polya, How to solve it A new aspect of mathematical method,
Princeton University Press (second edition renewed), 1985.
22
http://snow.utoronto.ca/Learn2/targets8.htm
,
. -
, ,
, -
.
.
http://www.awesomelibrary.org/Classroom/Science/Problem_Solving/Pro
blem_Solving.html
-
. -
, .
http://www.suremath.com/suremath/suremath/essential.html
-
. -
,
.
http://www2.hawaii.edu/suremath/click.html
,
, -
,
(, , ) -
.
http://www.infinn.com/creative.html
-
, -
, -
.
2.
24
-
. , -
.
,
, .
, -
-
. , -
, -
. , -
, , -
, -
. -
, -
. -
,
,
.
:
,
,
-
,
,
-
.
3 ;
3 ;
3 ,
;
3 3+6+9++999;
25
2.1
,
1 n.
. -
,
. -
25 , -
-
.
(algorithm)
Abu Jafar Mohammed ibn Musa al Khowarizmi,
825 ..
Algoritmi dixit ... ( -
....). al Khowarizmi
( al-jabr=-
), -
. -
, -
.
20
.
, ,
. , -
.
: ,
,
.
.
(input). ,
. -
, -
26
-
.
(output).
-
.
(definiteness).
. ,
, -
.
(finiteness). -
. -
-
, (computational
procedure).
(effectiveness). -
.
, .
-
. , ,
-
:
3 ,
3 ,
3 ,
3 ,
3 ,
3 ,
3 ,
3 .
. ,
, , , -
, -
. , , -
27
,
(
) .
2.2
-
. ,
, ,
.
H , ,
:
(hardware). -
,
(
, -
.).
(programming languages).
(, -
) -
. -
( assembly C)
( Basic Pascal). -
,
. ,
(
).
(theoretical). , -
-
.
, -
. -
,
.
(analytical). (computer
resources) , -
28
,
CPU / .. -
5.
2.3
:
(free text),
. -
-
,
.
(diagramming techniques),
.
,
, (flow chart).
, -
.
(natural language) .
, -
, -
, .
(coding), -
.
-
,
.
2.4 /
29
-
, .
,
. -
:
, ,
,
,
, -
,
, .
-
.
..
.
30
, -
.
, -
, , , -
-
.
( ),
.
2.4.1
( )
, -
.
. -
-
.
.
1. A
, -
.
_1
a
b
= - c a + b
c
T _1
= -
.
, . -
. -
, a
, a
.
31
(constands). -
-
.
, .. 123, +5, -1,25
.. ,
,
(variables). ,
. -
, -
. -
, , -
.
(operators). -
. -
, .
(expressions). -
(operands), -
. -
.
.
.
, ,
. -
.
a b -
: c a + b. -
. :
-
, , . -
, - . 2.1.
. , 1
=
32
. -
.
, -
. -
. -
, -
.
a b
, c -
, . , -
(),
(), -
(). -
, 2.1.
2.4.2
/ .
.
,
. -
. , -
. -
, , , .
,
.
-
( ) -
. -
. -
,
-
.
33
2.
, -
, , .
, ,
, + 5 = 5 5 = 5
. -
.
_2
a
a < 0 a a*(-1)
a
_2
.... :
: ( ), -
.
, .
... , , -
.
, - .
_. .
_1
_2
...............
_
_
,
a . -
, (-
), (),
(-
). -
2.1.
34
. 2.2. 2
3.
, -
, -
.
_3
a, b
a < b
c a + b
c a * b
_
c
_3
35
-
, :
. 2.3. 3
2.4.3
-
-
. ,
1 24,
.
-
.
36
4.
, 1 2 3 -
.
_4
a
a = 1
_ a = 2
_ a = 3
_
_4
. 2.4. 4
,
...
(select case), .
37
5.
-
.
_5.
;
age
age<0
...
0 age < 5
!!
5 age < 60
60 age < 100
age > 100
_
_5
2.4.4
.
... , ( )
.... ,
.
6.
-
. , -
80 , -
. -
1.70, .
38
_6
,
< 80
< 1.70
,
,
_
< 1.70
,
,
_
_
_5
. 2.5. 6
,
39
. -
. -
-
. ,
, -
, -
. -
. -
.
( )
. -
-
.
2.4.5
, -
-
. -
, -
, . ,
. -
-
,
= *
. -
-
(
). -
40
-
.
7.
: ...
1
100.
.
, -
. -
, -
.. 5, 207, -32 . -
i i + 1
i - -
1. -
, i, 1 100
1.
ii+1
i i 1.
100 i i + 1. -
....
:
_
:
, . ,
_-
.
:
_7
i 1
i 100
i
,
i i + 1
_
_ -
. _7
41
8:
:
,
. , , -
, -
,
. :
1.
2.
3. 1.
,
( ). , -
. , -
.
, 3 :
3. ,
1, .
. :
,
, -
.
-
, .... -
: -
_8 ,
x .
x > 0
x
x
_
_8
,
. ,
42
. ,
-
, ,
.. 999999. -
. ...
:
x 999999
9. :
_..._
. , -
.
_9
_
x
E x
_ x < 0
_9
, -
_-
x .
..._ -
, -
.
10.
: ......
100 1
100.
-
, -
....... .
43
_10
Sum 0
i 1 100
Sum Sum + i
_
E Sum
_10
, ......
Sum Sum+i -
, - Sum
i (=1) (=100). i i
1, , 1.
Sum , -
0, -
. Sum -
.
. 2.6. 10
44
11. :
.........
1 100.
-
.
, -
i.
_11
0
i 2 100 _ 2
+ i
_
E
_11
....... ,
, .
, .
, -
, :
k 100 0 _ -1
k 5 5
, -
. . , -
k 5 1
f(x) x 0
1,
x 0 1 _ 0,01
12.
-
,
.
-
. , , -
. ,
,
45
45
, , -
x 19
.. -
405
, + 45
2.7. 855
, -
. 2.7.
. ,
. - .
( ), -
,
. ,
,
.
, , , 45 45 19 45
19. - - 90 9 90
, . - 180 4
2.8 , 360 2
. ,
720 1 720
, -
= 855
. ,
. . 2.8. -
.
(shift)
-
, 0 1, -
, ,
.. 17 -
00010001 ,
byte.
, 0 -
0,
00100010 , 34
. , , -
,
1 0,
00001000 , 8
. -
, -
.
46
1.
: , +,
,
:
,
: , .
2.
-
, ,
_ (underscore).
, .
3.
+, -, *, /, ^
: , <, =, , >,
: (), (), ().
4.
, , ,
.
5.
6.
<> <>
<> <_1>
<_1> <_1>
_ <_2>
<_2> <_2>
_ ......
_ <_>
1 <_>
_1
............ <_>
_
_
_
_
47
7.
<>
_
_
_ <>
1 2 _
_
8.
, , , ..
9.
, , -
, ..
10.
- , !,
!.
11.
<_> <_-
>
12.
( )
// ... //. -
// ... //.
48
, -
. , ,
. -
. , , -
(shift),
. -
-
-
.
-
.
: ( )
: M1 M2, M1, M2 1
: P=M1*M2
1 P=0
2 M2>0, 3, 7
3 2 , P=P+M1
4 1=1*2
5 2=2/2 ( )
6 2
7 P.
-
.
__
// 1,2 //
P 0
M2 > 0
M2 mod 2 = 1 P P+M1
M1 M1*2
M2 [M2/2]
_
// P, 1,2 //
__
49
-
. -
. .
, -
. -
, -
, ,
.
, , , , , -
, , .
-
1. .
2. ;
3. -
;
4.
;
5. -
.
6. / ;
7.
.
8. -
.
9.
.
10.
.
11.
50
.
12. -
.
13.
; -
;
1. ., ., .,
, , 1991.
2. , , -
, 1993, .
3. ,
Pascal, Art of Text, , 1998.
4. .. , -
, , 1990.
5. D. Brunskill and J. Turner, Understanding Algorithms and Data Structures,
McGraw-Hill, 1996.
6. D. E. Knuth, The Art of Computer Programming: Fundamental Algorithms,
Vol.1, 3rd edition, Addison Wesley, 1997.
7. M.A. Weiss, Data Structures and Algorithm Analysis, 2nd edition,
Benjamin/Cummings, 1995
http://hissa.ncsl.nist.gov/~black/CRCDict/
, -
(Algorithms, Data Structures, and Problems Terms and Definitions
for the CRC Dictionary of Computer Science, Engineering and Technology)
http://www.ee.uwa.edu.au/~plsd210/ds/ds_ToC.html
, -
.
3.
52
, -
. -
.
, -
, .
-
, , -
, .
:
,
-
,
-
,
-
,
-
,
.
3 FIFO;
3 -
, ;
3 -
;
3 , -
;
53
3.1
(data) -
. ,
.
, , , , .,
, . , , ,
(byte)
.
11110001.
H :
(information). -
l _ -
, ASCII 437
-
l -
.
928
. -
l 1 -
, , , . ,
EBCDIC
,
, (Information Theory), l 241
( -
.
)
- l -14
, ( -
. , - -
: 1)
l -15
. (hardware), , ( -
- -
2)
(representations). , SCII (.
), EBCDIC, 1 2 .. 2 4
bytes, -
.
.
(high level programming languages) -
-
(types) (variables)
, -
. - ,
, , -
. , -
,
. (data structure) ,
.
, (record), .
, .
(fields) (attributes) -
, , . -
54
. -
.
.
. (Data-
bases), (Data Modelling) -
(Knowledge Representation)
.
3.2 + =
,
.
, -
. (data structure)
-
.
:
.
(nodes). ( ) -
:
3 (access),
.
3 (insertion), -
.
3 (deletion), , -
.
3 (searching),
, -
.
3 (sorting),
.
55
3 (copying),
.
3 (merging), -
.
3 (separation),
.
-
.
,
,
, .
, -
.
-
. , -
. ,
.
1976 Wirth
( Pascal)
+ =
.
.
: (1,1), (2,2), ...,
(n,n), i i -
i- , i=1,2,...,n.
: -
k k.
,
.
56
.
: -
, -
. (,n1),
(B,n2), ..., (,n24). K -
ni ( i=1, 2, ..., 24) -
.
: .
:
(static) (dynamic).
-
(dynamic memory allocation). -
, ,
-
.
-
. , -
3.3
-
,
.
.
,
-
. -
( , .). -
. -
,
-
(indexes) .
, -
57
, -
.
, -
(square) n x n.
, -
. -
,
.
1.
table 100 . -
_
// table //
. 3.1
Min table[1] (-
i 2 100 , , -
table[i] < Min Min table[i] )
_
//Min//
_
Min. -
, Min , -
. Min -
table.
2.
table m n . -
, .
. -
, -
.
-
.
58
_
// m, n, table //
sum 0
i 1 m
row[i] 0
_
j 1 n
col[j] 0
_
i 1 m
j 1 n
sum sum + table[i,j]
row[i] row[i] + table[i,j]
col[j] col[j] + table[i,j]
_
_
// row, col, sum //
_
-
, , -
.
, ,
. -
, i 1 j -
1,2,,n. , i 2, j
1,2,,n. -
i m.
5x5. -
,
row
, col -
. sum -
- .
59
table
row
4 16 5 21 7 53
28 9 38 13 51 139
17 67 22 40 30 176
20 40 10 3 13 86
21 34 48 29 26 158
-
, (stack) (queue), -
, -
.
3.4
. -
, (top)
, -
. ,
,
. -
, LIFO
. 3.2. .
60
(Last-In-First-Out). -
,
.
:
(push) ,
(pop) .
,
, (overflow) -
. , , -
, (under-
flow) .
-
, 3.3. -
. 3.3 - ( top)
.
() top
. -
()
top top
.
3.5
. , -
, , , .. -
.
, ,
(Operations Research), -
(Queueing Theory), -
. , -
( -
). -
, -
FIFO (First-In-First-Out).
:
61
(enqueue) ,
(dequeue) .
, ,
: (front) (rear) ,
.
3.4 (), -
() .
. 3.4. .
-
, 3.5.
rear -
. ,
front,
, .
, -
, -
.
. 3.5
62
FIFO LIFO
LIF,
FIFO.
.
. -
-
, , -
. -
, , .. -
, -
.
.
-
-
.
, ,
;
o .
, -
.
(.. ),
. -
FIFO
.
-
, -
. -
.
/
1/1/99 4 100 400
15/1/99 6 120 720
10 1120
63
/
30/1/99 5 200 1000
-
/ - - - - - -
1/1/99 4 4 400 400
15/1/99 6 10 720 1120
30/1/99 5 5
-
. -
, .
) LIFO
30/1/99 5
6 , 120 .
=5x120 = 600 . =1120-600=520. -
1000-600=400.
) FIFO
30/1/99 5 , 4 -
1/1/99 1 15/1/99.
=4x100+1x120=520 =1120-520=600. ,
1000-520=480.
)
-
, -
.
1120/10=112. =5x112=560
=1120-560=560.
1000-560=440 .
64
3.6
(searching)
.
, . -
,
. .
(sequential) (linear) .
Sequential Search key -
table. position -
0, , -
, (-
, 1 n).
Sequential_Search
// n, table, key //
done
position 0
i 1
(done=) (i<=n)
table[i]=key
done
position i
i i+1
_
_
//done, position //
Sequential_Search
, table
. , -
. -
,
: done
-
i n. , -
, , -
.
65
,
. , -
56 4 . , -
() 11 9 -
, . -
. 11 -
12.
, -
. , -
:
3 ,
3 ( , n 20),
3 ,
. 3.6.
66
-
, .
3.7
(sorting)
(ordering). (ascending
sequence) .
.
,
, , , -
-
.
.
. a1,a2,...,an
(permutation) , -
ak1,ak2,...,akn ,
(ordering function), f, :
f(ak1) f(ak2) ... f(akn)
A
, -
(descending sequence) .
H (straight exchange sort)
, .
-
-
.
- -
(bubbles) ,
-
67
/ , -
.
-
, -
. (files).
-
, -
, . ,
,
,
, -
. (records),
(fields),
, -
. ,
: , , -
, , .
(primary key) . -
-
(secondary keys), .
(searching)
-
, -
( , , -
, ..), ( -
, , , , ..),
(,
.).
. -
(bubblesort).
. -
: 52, 12, 71, 56, 5, 10, 19, 90 45.
.
,
-
68
.
(i).
. 3.7. .
.
// table, n //
i 2 n
j n i _ 1
table[j-1] > table[j]
table[j-1], table[j]
_
_
- _
// table //
.
-
table n -
-
. -
. -
, -
, ,
(quicksort). .
-
table[j-1], table[j]
- . -
. .
69
temp table[j-1]
table[j-1] table[j]
table[j] temp
3.8
(recursion), -
.
.
,
, -
.
3.8.1
H . -
, n, n , n!,
:
n! = 1 x 2 x 3 x x (n-1) x n
n ( n 1) ! n > 0
n!=
1 n = 0
-
.
. -
n .
// n //
n = 0
product 1
product n * (n-1)
_
// product //
70
, n! , -
2.
2
// n //
product 1
i 2 n
product product * i
_
// product //
2
, -
n , -
. , -
.
3.8.2
E
() .
.
.
x y.
( ), -
-
. , z,
z
, x y,
z.
__
// x,y //
x < y
z x
z y
_
(x mod z 0) (y mod z 0)
z z-1
_
// z //
__
71
,
,
.
// x,y //
z y
z 0
z x mod y
x y
y z
_
// x //
. , -
150 35. -
z, x y, -
. , -
x y 150 35 (
). 0 z, -
x, 5.
z x y
35 150 35
10 35 10
5 10 5
0 5 0
-
, . H
.
// x,y //
y = 0
z x
z (y, x mod y)
_
// z //
72
3.8.3 Fibonacci
-
, ,
Fibonacci , -
:
0 i = 0
Fi = 1 i = 1
F = F + F i > 1
i i1 i2
Fibonacci :
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 .
A -
. Fibonacci
Fn .
-
n.
Fibonacci1
// n //
n 1 Fib n
f0 0
f1 1
i 2 n
fib f0+f1
f0 f1
f1 fib
_
// Fib //
Fibonacci1
Fibonacci2
// n //
n 1
Fib n
Fib Fib(n-1) + Fib(n-2)
_
// Fib //
Fibonacci2
73
-
. -
,
. -
. -
. -
. ,
,
.
Fibonacci
,
,
. , -
. -
F5. -
Fibonacci .
3.9
-
. -
, -
. ,
.
3.9.1
. (pointer) -
. -
, .., -
-
, -
. 3.8 -
. -
, 3.8. -
74
.
3.9 ,
, -
index pointer -
.
. -
,
-
. . 3.9.
. 3.10
-
.
. 3.10.
, -
()
-
( -
). ,
.
, -
(dynamic),
,
- . 3.11.
-
.
,
, -
, 3.11. (
-
) -
- , .
.
75
3.9.2
(trees) -
, -
. , -
( ). ,
, -
. , , -
. 3.12.
. . ,
... -
,
.
. 3.12.
3.9.3
(graph) (
) ( ) -
. -
,
.
. 3.13.
76
-
. -
-
. -
, ,
, -
.
, -
, . -
.
( ),
, . -
,
.
-
.
.
/ -
.
-
. ,
, .
, , , ,
, , , FIFO LIFO, , , -
, , , .
77
-
1. ;
.
2.
;
3. .
4. ;
5. -
;
6. .
7.
.
8. .
9. ;
10. .
11. ;
12. -
.
13. -
.
14. .
15. -
.
16. .
17. -
.
1. , , , 1996.
2. , .
, , 1993.
78
3. ,
Pascal, Art of Text, , 1998.
4. , , , 1993.
5. D. Brunskill and J. Turner: Understanding Algorithms and Data
Structures, McGraw-Hill, 1996.
6. D. E. Knuth: The Art of Computer Programming : Fundamental
Algorithms, Vol.1, 3rd edition, Addison Wesley, 1997.
7. M.A. Weiss: Data Structures and Algorithm Analysis, 2nd edition,
Benjamin/Cummings, 1995.
http://hissa.ncsl.nist.gov/~black/CRCDict/
, -
(Algorithms, Data Structures, and Problems Terms and Definitions
for the CRC Dictionary of Computer Science, Engineering and Technology).
http://www.ee.uwa.edu.au/~plsd210/ds/ds_ToC.html
, -
.
4.
80
, -
,
. ,
,
-
. ,
-
.
.
:
,
,
,
,
.
3 ;
3 -
;
3 ;
81
4.1
, -
. -
. ,
, . ,
-
. -
.
-
:
3 ,
3 ,
3
:
3 ,
3 .
, -
:
1. ,
2.
,
3. ( -
),
4. (.. ),
5. -
(.. )
. -
, , -
, -
, -
. -
,
.
82
. 4.1. .
4 4
, 6
. ,
-
. ,
1, , -
2, 3 4. -
.
) :
1. ,
2.
,
3.
.
:
36 .
83
) :
1. ,
2. -
-
.
:
30 .
, -
,
,
. ,
-
. ,
-
. , -
-
:
-
,
( -
),
-
, -
.
4.2
-
, -
, .
, -
84
. , -
-
.
. ,
. -
( ). -
, :
3 ,
3
3 .
.
, -
-
.
. -
,
:
. 3
3
3
.
-
, -
. -
.
,
.
85
4.3
(divide and conquer)
,
-
. , -
.
-
,
.
(top-down).
,
:
1. .
2. -
.
3. -.
4.
-, -
.
: .
, -
n .
. n -
: names[1..n] phones[1..n] .
, ,
(
).
, 3 -
:
1. names, . 4.2. -
86
2.
names,
3.
names.
. -
-
(, names).
-
- , -
- .
.
_
// names, phones, onoma, arxi, telos //
meso [arhi + telos]/2
onoma = names[meso]
Tel phones[meso]
onoma < names[meso]
_(names, phones, onoma, arhi, meso-1)
_(names, phones, onoma, meso+1,telos)
_
_
// Tel //
_
. -
-
.
.
. 4.3 -
.
87
, , -
. -
. ,
,
. , -
, - -
. , -
.
. ( Bolzano)
f(x)=0 -
[a, b]. , ,
f(a).f(b)<0 ( -
). x1 (=(a+b)/2)
[a, b] , f(a).f(x1)<0. ,
[a, x1], [x1, b]. -
x2 -
.
x1, x2, ...
. , -
.
. 4.4
4.4
-
, -
.
- -
88
. , -
(bottom -
up). ,
-
. ,
-
, -
.
..
-
.
, -
.
-
,
- . -
:
1. ,
2. -
,
3. .
-
.
-
. ,
,
.
, , -
, ab. -
1, -
.
89
1
// a, b //
power 1
i 1 b
power power * a
_
// power //
1
1
, , b
b- . -
, -
a16
: (((2) 2)2)2.
, -
b. -
power
. , -
2 (, a=2),
0 1, 1 2, 2 4,
3 16 , .
0 1 2 3 4
0 1 2 4 8
2 =1 2 =2 2 =4 2 =16 2 =256
0- 1 2 4 8
2
. 4.5 2.
, , -
. , 27 , -
4 2, 27 = 24 *22 *21.
ab
, -
.
90
2
// a, b //
!:
power[1] a
i 1
pow 1
pow < b
i i+1
pow 2* pow
power[i] power[i-1] * power[i-1]
_
!:
used 0
result 1
used < b
used + pow <= b
result result * power[i]
used used + pow
_
pow pow / 2
i i - 1
_
// result //
2
4.5
,
, ,
, -
. ,
, -
. -
-
-
. ,
4.1, . -
(greedy method),
:
91
-
( -
).
,
, .
1,
2, 5, 10, 20, 50 100 200, 500, 1000,
5000 10000 .
, , -
. -
789 . 1 , 1 -
, 1 , 1 , 1 , 1 2 , -
8 .
,
-
. T
,
.
// C, n, poso //
find poso
coins 0
choice n
(choice>0) (find > 0)
C[choice]<= find
coins coins + 1
find find - C[choice]
choice choice - 1
_
_
// coins //
92
C n -
. -
( coins). , -
.
-
. -
. -
: -
, -
. -
-
. -
. -
-
-
. ,
, -
.
, , ,
, .
-
1. -
;
2.
;
3. -
;
93
4. -
.
5.
.
6.
.
7.
, -
.
8.
.
1. :
, , -
, 1993.
2. : .
, , 1993.
3. : , -
, , 1988.
4. :
Pascal, Art of Text, , 1998.
5. , , -
, , 1996.
6. , , , 1995.
7. Niklaus Wirth: , , ,
1990.
8. G. Brassard and P.Bratley: Fundamentals of Algorithms, Prentice Hall,
1996.
9. T. Cormen, C. Leiserson and R. Rivest: Introduction to Algorithms MIT
Press, 1990.
10. E. Horowitz, S. Sahni and S. Rajasekaran: Computer Algorithms,
Computer Science Press, 1998.
94
http://www.cs.pitt.edu/~kirk/algorithmcourses/index.html
-
. .
http://www.wisdom.weizmann.ac.il/~naor/puzzler.html
puzzle.
/.
http://www.cs.sunysb.edu/~algorith/
(Stony Brook)
- . .
5.
96
-
-
.
, -
(, ). -
, ,
() -
. , -
,
, .
:
,
,
-
,
,
,
.
3
;
3 ;
97
5.1
-
,
.
(performance)
(efficiency) .
-
. -
:
1. ;
2. ;
3. , ;
-
. -
.
5.1.1
-
, -
. -
.
-
. -
. , :
3 ,
3 ,
3 .
, -
, -
.
98
: :
1
n 10
A_
m
n n - 1
M_ (m=0) (n=0)
m
1
10 ( n=0).
5.1.2
(size) .
-
. ,
. ,
,
n,
.
5.1
,
:
. 5.1.
(n)
99
5.1.3 -
:
2
x 123
y 234
i 0 4
i
z x * y
_
x
y
z
2
. -
5 , :
x y 2
i 1
i 6
i 5
i 5
z (25) 10
x, y, z 3
32
-
n ,
n. 5.2
n, -
- :
100
. 5.2.
n
5 42 -
10 77 -
100 707 -
1.000.000 7 ()
5.1.4
-
, -
. ,
,
, . -
, -
, . -
, -
. ,
:
,
,
,
-,
, .
,
, :
3 -
,
3 -
,
3 ,
101
3
.
5.2
, -
.
-
.
. -
. , ,
. -
, -
.
-
. -
,
, , .. .
. ,
;
, -
. -
:
: -
10 -
.
-
:
102
3
// a //
low a[1]
i 2
i < 10
a[i] < low low a[i]
i i+1
_
// low //
3
, -
. -
10 , -
. 3 -
:
11 3 2 56 32 69 81 90 222 2
2 444 1 65 51 51 99 98 1 1
90 11 333 38 224 61 73 80 7 59
,
. -
:
6 8 3 4 3 7 8 9 5 2
3, -
2. , -
, .
,
.
, , -
, -
.
(i < 10), .
103
,
. , -
, -
,
.
-
, , -
.
1/10, 10 . -
0,9.
, -
0,9*0,9=0,81.
-
:
-
1 0,1 0,9
2 0,19 0,81
3 0,271 0,729
4 0,344 0,656
5 0,410 0,590
6 0,469 0,531
7 0,522 0,478
, -
7 -
0,5 .
-
. ,
.
-
.
:
104
-
,
, -
. .
a b
. -
, -
.
, -
: a b b a, .
,
a0 b0 . ,
: a=b0 b=a0.
. , -
,
. :
t a, a b b t
, ,
.
5.3
(empirical) (a posteriori).
, -
, (proces-
sing time) (memory space). -
.
.
, -
.
105
.
-
(theoretical) (a priori).
n, (size)
,
-
, . -
, .
, k n=k.
-
f(n) -
(time complexity) (space complexity).
-
, .
O (-notation),
order -
. .
: f(n),
O(g(n)), c n0,
n n0 :
f ( n) c g ( n)
.
f(n)=2n3+5n2-4n+3. -
, x (
) -
,
. , 2 -
g(n)=n3. ,
(n3). ,
.
f(n)=5.2n+4n2-4logn, g(n)=2n, -
f(n) 5
2n. ,
f(n), 1, 2, 3 -
n .
( , n=10),
2n.
-
106
, ,
. , -
,
.
, :
(1). K
. -
.
(logn). . -
log , ln
. , -
.
O(n). . -
n .
O(n logn). (n logn),
( -
).
.
O(n2). .
.
O(n3). . -
.
O(2n). -
.
5.3 -
-
(n). -
. -
(n3) , -
(23) . -
,
.
107
. 5.3.
n=20 n=40 n=60
(n) 0.00002 0.00004 0.00006
(n2) 0.0004 0.0016 0.0036
3
(n ) 0.008 0.064 216
n
(2 ) 1.0 o 2.7 366
(n!) 771 3 1032 3 1066
.
, ,
.
3, -
.
5.3.1
C, (key
comparisons), .
(moves) -
. C M n ,
.
,
,
. :
C = 1 + 2 + + (n-1)
n ( n 1)
C=
2
,
(n2).
108
5.3.2
3.6 ,
.
,
(successful). , -
(unsuccessful).
.
, .
, -
n -
. , -
, , -
. , n-
, n
. ,
:
(1 + 2 + K + n) n ( n + 1) n +1
= = =
n 2n 2
, -
(n),
.
(n). ,
,
.
, -
,
.
. 5.4.
- (1)
- (1)
Fibonacci (n)
O(n2)
O(n)
O(logn)
109
5.4
, -
,
, -
. , ,
. , -
-
.
.
, -
/ -
. ,
, , -
,
( ).
-
, -
. -
,
, -
, . -
(parallel) ,
, -
, -
. ,
-
.
,
2 ,
, . -
. , -
.
110
,
.
, . -
, -
,
, ,
,
..
, -
, (Computa-
tional Complexity),
. -
, -
. (optimal),
, -
.
(polynomial)
. ,
(n), O(n3/2), O(n2) ..
O(2n), O(n2 2n) O(nn), -
.
-
, -
.
, :
x1, x2, , xn (
n ). n/2 , -
,
x1, x2, , xn (
n ). n/2 , -
.
, -
. , -
n ,
. (n2), -
. ,
-
111
. , -
.
. -
(2n).
( ) -
, -
. (intra-
ctable).
-
,
.
.
. ,
-
,
. -
, -
.
, -
, NP--
Nondeterministic
Polynomial. -
.
-
,
(approximate) ,
.
, ,
-
.
, , -
,
, .
. -
112
,
.
,
.
-
,
.
-
. -
() -
.
-
.
, -
(-
, , ).
/ , -
, , , -
, , , ,
, ,
-
1. -
;
2. -
;
3.
.
113
4.
;
5. -
;
6. .
7. -
;
8.
.
9. .
10. -
, .
11. ;
12. ;
13. ;
1. ,
, , ,
1993.
2. , .
, , 1993.
3. , , -
, , 1988.
4. ,
Pascal, Art of Text, , 1998.
5. . , , , , 1993.
6. Niklaus Wirth, , , ,
1990.
7. G. Brassard and P.Bratley, Fundamentals of Algorithms, Prentice Hall,
1996.
8. T. Cormen, C. Leiserson and R. Rivest, Introduction to Algorithms MIT
Press, 1990.
114
http://www.csd.auth.gr/~contest/
-
. -
.
http://olympiads.win.tue.nl/ioi/
-
.
http://acm.baylor.edu/acmicpc/
Association for
Computing Machinery (ACM).
6.
116
. -
-
, -
. -
. -
,
,
-
. -
,
.
.
:
.
-
.
.
.
-
3
;
3 ;
3 ;
3 ;
3 -
;
117
6. 1
, -
, .
.
.
-
.
,
-
,
. ,
, , -
-
.
.
, -
.
. ,
-
, , -
, -
. ()
, ()
. -
,
, -
.
6.2
-
. ,
-
-
.
(hardware) , -
, -
118
1945 , .
,
, -
.
6.2.1
, 0
1, -
.
, - ,
- .
. ENIAC ,
, -
,
.
,
. , -
, .
-
0 1, ,
, .
6.2.2
-
, ,
-
0 1. ADD () -
, -
. -
-
. ,
(assembler).
,
, -
119
.
. -
, .
-
, . -
,
-
.
. -
10101000 00001010 INDEX=$01 sum = 0 -
SUM=$02 FOR index=1 TO 10 -
10001100 00000001
00111100 LDA #10 sum=sum+index
01010001 00000001 STA INDEX NEXT index
01000011 00000001 CLA END
11000000 11111010 LOOP ADD INDEX
10001100 00000010 DEC INDEX
BNE LOOP
11111111
STA SUM
BRK
. 6.1. ,
1 10
6.2.3
-
-,
50
.
1957 IBM
FORTRAN. FORTRAN FORmula
TRANslation, . FORTRAN -
. FORTRAN -
, -
, .
FORTRAN ,
. -
FORTRAN , -
.
120
C PROGRAM EQUATION
READ(*,1) A,B
1 FORMAT(F5.1)
IF (A.EQ.0) GO TO 20
X=(-1.)*B/A
WRITE(*,2) X
2 FORMAT(X=,F10.2)
GO TO 50
20 IF (B.EQ.0) WRITE(*,3)
IF (B.NE.0) WRITE(*,4)
3 FORMAT()
4 FORMAT()
50 STOP
END
.6.2. FORTRAN -
. , -
.
4, 77, 90/95 Visual
FORTRAN. .
FORTRAN -
,
,
.
.
1960 , -
COBOL. COBOL (Cm-
mon Business Oriented Language - -
) , -
, FORTRAN .
COBOL -
. -
.
, ALGOL (ALGOrithmic Language -
). ,
121
IDENTIFICATION DIVISION.
PROGRAM-ID. EQUATION.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.
SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 X PIC S9(6)V9.
77 A PIC S9(6).
77 B PIC S9(6).
77 W-X PIC -(6),-.
PROCEDURE DIVISION.
ARXH.
DISPLAY .
ACCEPT A.
DISPLAY .
ACCEPT B.
DISPLAY .
IF A = 0 GO TO ROYT-1.
COMPUTE X = B * (- 1) / A.
MOVE X TO W-X.
DISPLAY H : W-X.
STOP RUN.
ROYT-1.
IF B = 0
DISPLAY
ELSE
DISPLAY .
STOP RUN.
10 REM
20 INPUT A=,A
30 INPUT B=,B
40 IF A=0 THEN 100
50 X=-B/A
60 PRINT X=;X
70 END
100 IF B=0 THEN PRINT ELSE PRINT
110 END
1960,
.
60 PL/1
(Programming Language/1 1)
, -
, ,
FORTRAN COBOL .
-
. 60
LISP (LISt Processor- ), -
PROLOG
(PROgramming LOGic ) 70.
-
( , ,
..).
,
60 , -
BASIC PASCAL.
123
TO KYBOS :A
REPEAT 4 [FD :A RT 90]
PU SETPOS [20 20] PD
REPEAT 4 [FD :A RT 90]
PU HOME PD
REPEAT 2 [FD :A RT 45 FD 29 RT 135]
PU SETX :A SETY 0 PD
REPEAT 2 [FD :A RT 45 FD 29 RT 135]
HOME
END
(DEFUN a-exisosi (a b)
(setf apot (- (/ b a)))
(princ )
(princ a)
(princ x + )
(princ b)
(princ = 0 = )
(princ apot))
.
.
C. C
BELL
Unix, -
, Pascal -
-
. C C++, -
. -
70 -
.
-
.
, -
(Internet), JAVA. H JAVA
SUN
, ,
.
-
,
.
-
125
#include <stdio.h>
printf(A = );
scanf(%f, &a);
printf(B = );
scanf(%f, &b);
if (a == 0) {
if (b == 0) {
printf(\n);
}
else {
printf(\n);
}
}
else {
printf(X = %f\n, -b/a);
}
return 0;
}
. 6.7. C Bell-
& 1972 Dennis Ritchie. C
-
.
UNIX, C
-
.
.
-. -
, -
, -
.
-
(object driven programming) (visual
programming).
126
CLEAR
? 1.
? 2.
? 3.
? 4.
INPUT [1..4] : TO CHOICE
DO CASE
CASE CHOICE=1
APPEND
CASE CHOICE=2
LABEL FORM PELATES
CASE CHOICE=3
BROWSE
OTHERWISE
QUIT
END CASE
. 6.8. dBASE 70
Ashton-Tate 8-bit -
. dBASE
-
() . dBASE -
,
-
.
-
. dBASE III Plus.
Clipper ,
-
. ,
-
xBASE,
Access.
-
.
-
. -
-
- , -
.
, -
- -
Visual Basic, Visual C++
Java.
127
-
:
-
.
.
.
-
.
-
.
-
.
-
.
,
-
.
6.2.4 4
( 3 ) -
. -
.
, -
. -
-
. -
-
4 .
,
, -
128
-
-
.
(procedural) . -
, -
. -
:
(object -oriented languages)
(functional languages) .. LISP
(non procedural languages) ..
PROLOG. -
.
(query languages) .. SQL.
-
. :
.
-
. -
. -
:
3 (science-oriented langua-
ges) .. FORTRAN
3 (business-oriented languages)
.. COBOL.
.. BASIC, Pascal.
(system programming
languages) .. C.
(artificial intelligence languages) ..
LISP, PROLOG.
. -
.. -
, , -
, , -
..
129
-
,
.
SELECT ENAME, JOB, SAL
FROM EMPLOYES
WHERE DEPTNO=20
AND SAL > 300000;
SQL
EMPLOYES ,
20 300.000 .
. -
-
. -
.
.
-
.
-
.
-
,
.
,
, -
. -
, -
-
.
130
6.3
, -
.
-
, -
. , -
, -
, .
, ,
.
-
.
: -
48 (-
-), 10 (0-9) .
(A-Z a-z)
.
,
. -
, -
, .
(accidence)
(syntax).
-
. -
, , ,
.
131
.
-
-
.
(Semantics)
.
, -
, - ,
- .
.
.
-
. ,
,
-
,
.
, -
.
-
,
. -
( GW-Basic QuickBasic)
( Basic Visual Basic).
6.4
-
,
,
132
6.4.1
-
(top-down
program design) -
, ,
, -
, -
- .
-
,
- .
-
,
6.4.
6.4.2
. -
, (mo-
dule), -
.
-
-
.
-
,
, -
.
6.4.3
,
133
. 6.4.
(structured programming). -
1960.
1964
Bohm Jacopini -
.
, 1968 Edsger Dijkstra -
-
.
GO TO Statement Considered Harmful - -
GOTO -
. ,
.
,
.
,
GOTO .
134
GOTO:
-
GOTO (). GOTO
,
.
.
GOTO,
-
, -
.
GOTO.
-
, -
,
,,,,,
>0 GOTO 1
=0 GOTO 2
GOTO 4
1:
GOTO 4
2:
GOTO 4
4:! ,
,,,,
>0
_ =0
_
,,,
GOTO -
.
135
, -
GOTO .
-
, .
GOTO -
-
.
GOTO .
-
,
,
, -
.
, , -
.
-
.
.
2 -
.
-
GOTO, -
.
, -
.
136
.
.
.
.
.
.
.
6.5
-
70
.
-
(object-oriented) .
.
-
. -
()
. ,
.
.
,
(objects). -
,
137
-
. , , -
;,
;, ;
;. -
-
11.
-
,
.
6.6
, -
. -
. -
. -
,
.
, -
-
-
.
5, - OCCAM.
,
.
6.7
-
,
, .
. -
138
, (compilers) (interpreters). -
-
. -
.
-
.
(source), -
-
(object).
-
, . -
,
(libraries) . -
(linker-
loader).
(executable), -
. -
.
-
, . -
. -
, .
, -
.
. 6.5.
139
-
.
,
, -
, -
, -
.
-
.
.
, -
.
, -
, -
. -
. -
, -
,
. -
. 6.6.
140
, -
-
.
- -
(editor). -
-
, -
. -
- ,
-
: , -
,
- . -
. .
-
. (visual) -
( -
, , ) -
.
-
. -
, -
-
.
, , -
.
-
,
, -
, -
. -
, .
. -
, -
141
, .
, ,
-
.
-
;
;
;
;
-
;
;
-
;
;
;
;
;
-
;
;
-
;
, , , -
, , , -
, , ,
142
1. Ph. Breton, , , ,
2. . , , , 1986.
3. . -, , ,
, , 1992.
4. , -
, , 1986.
5. .-., FORTRAN 77 FORTRAN
90, , , 1995.
6. . -. , COBOL ,
, , , 1992.
7. . -. , Structure & Advanced COBOL, -
, , 1992.
8. . -. , GWBASIC ,
, , 1992.
9. . -. -. , PRO
LOG, , , 1991.
10. . , LOGO , -
, , 1991.
11. . , C , , -
, 1995.
12. M., SQL 4 ,
, , 1995.
13. E. Horowitz, , -
, , 1995.
14. R. Shackelford, Introduction to Computing and Algorithms,
Addison-Wesley, USA, 1998.
15. W. Hutching-H. Somers, An Introduction to Machine Translation,
Academic Press, London, 1992.
143
cuiwww.unige.ch/langlist
. -
2000 .
www.swcp.com/~dodrill/
-
.
www.progsource.com
, , -
-
Pascal, Delphi, C/C++, Java, Perl, Visual Basic.
www.hensa.ac.uk/parallel/
.
Softwaredesign.com/objects.html
-
.
Iamwww.unibe.ch/~scg/Ooinfo
,
.
7.
146
, , -
. -
.
.
,
,
.
, -
,
.
:
.
.
.
.
, , -
.
3 -
;
3 ;
3 ;
3 -
;
147
-
,
.
, -
. -
.
:
,
-
. -
, -
.
. -
,
. -
-
, -
.
-
, , -
.
, -
-
. , -
Pascal,
Visual Basic, C, C++, Java , -
.
.
,
.
.
148
7.1
, , ,
, -
.
(-)
(-)
(-)
(a-z)
0-9
+ - * / = ^ ( ) . , ! &
7.2
, -
.
,
,
.
. -
. , -
. 1, 3409, 0, -980.
.
. 3.14159,
149
, -
(
, ).
-1 = --1
-2 = --2
.
.
.
- = --
150
=3.14159
=0.18
=
.
,
-
.
.
, (-
) , -
. -
(-,
-), (0-9) (underscore)
(_), .
, , , -
, .,
. .
: ,
, , _, 100, , , _-
.
: 100,
, $.
151
7.4
(variable) .
=
() , -
. , -
.
,
.
, -
-
. -
.
, -
, -
.
,
.
, , ,
-
.
, -
, ,
_, .
-1: --1
-2: --2
.
.
.
-: --
152
: ,
: ,
:
:
, -
, -
, ,
.
- -
- ,
.
.
7.5
-
: , ,
,
.
:
153
+
-
* div -
/
-
^ , -
mod .
DIV ..
MOD 7 div 2 = 3 7 mod 2 = 1
7.6
. :
()
()
()
_()
()
() ex
A_M(X)
_()
7.7
, -
(expressions). -
, , ,
.
.
,
.
154
, -
, .
, -
1.
2.
3.
a+1 a+1
3
1/2 a 1/2*a^3
3x + 2y
(3*x+2*y)/(a-b)
ab
2 2*()
,
-
. -
-
. - . -
- .
- , . ..
- 2+3*4 14, (2+3)*4 20,
.
.
7.8
-
.
155
- <-
<- 132
<-
<- *
, .
-
. ,
, -
, .
<- -
(=). , , -
.
.
7.9 -
,
, -
.
-
, -
, .
-
-
.
156
-
.
-
.
(,). -
, -
.
.
, , : ,
-
.
-
. , -
,
.
.
.
. -
-
.
157
, -
.
7.10
,
. -
, -
.
.
-
, .
, -
.
,
.
_.
(. . 10),
_.
.
,
&.
(!),
.
. -
, -
. 18%.
158
_
!
=0.18
: , _,
: _, _
!
_
!
<- * _
_ <- *
_ <- +_
!
,,. ,
, _
, _
_ _
-
Pascal Basic.
Pascal
PROGRAM computers;
CONST
fpa=0.18;
VAR
cost, value, quantity:INTEGER;
total,cost_fpa:REAL;
BEGIN
write( );
readln(quantity);
write( );
readln(value);
cost:=quantity*value;
159
cost_fpa:=cost*fpa;
total:=cost+cost_fpa;
writeln ( , quantity, :,
cost);
writeln ( : , cost_fpa:7:0);
writeln ( : , total:7:0)
END.
Basic
fpa = .18
INPUT : , Quantity
INPUT : , Value
Cost = Quantity * Value
CostFpa = Cost * fpa
Total = Cost + CostFpa
PRINT ; Quantity; :;
Cost
PRINT USING H : ######; CostFpa
PRINT USING : #######; Total
END
, , , -
, , -
,
.
:
: , ,
, .
-
.
-
.
,
( )
- .
160
, , , , , -
, -
-
.
;
-
;
;
;
;
;
;
1. . , . , Pascal, ,
1984.
2. . , Basic: , , ,
1991.
3. . , QuickBasic , -
, , 1992.
4. R. Shackelford, Introduction to Computing and Algorithms,
Addison-Wesley, USA, 1998.
5. S. Leestma-L.Nyhoff, Turbo Pascal, Programming and Solving, McMillan,
New York, 1990.
6. N. Wirth, Systematic Programming: An introduction, Prentice Hall, 1973.
161
http://www.swcp.com/~dodrill/
-
.
http://www.progsource.com
, , -
: Pascal, Delphi, C/C++, Java, Perl, Visual Basic.
www.cit.ac.nz/smac/pascal/default.htm
Pascal -
. , .
http://www.cs.vu.nl/~jprins/tp.html
, , , -
Turbo Pascal.
http://qbasic.com/
,
Qbasic.
www.basicguru.com
Basic. -
, , -
.
(Usenet):
comp.lang.pascal
comp.lang.pascal.misc
Pascal
alt.lang.basic
comp.lang.basic.misc
Basic
8.
164
,
. -
-
, ,
, -
, -
.
, , -
. -
-
. -
.
:
, .
() .
.
-
.
.
.
-
: , .
3 ;
3
;
3 ;
3 ;
3 ;
165
8.1
,
. -
-
.
-
. -
, -
. , -
, 0.
,
0, , 0,
.
, , ,
, .
, -
.
.
-
.
= =0
<> 1 <>
> >10000
, -
.
. -
-
.
,
.
-
,
- -
.
, -
(=)
. (<>),
.
-
,
. -
, , .
0<<5 >0 <5
=1 2 3 =1 =2 =3
8.1.1
.
. ...,
...... ......
. _.
-
( ),
_.
167
>=0
< _()
_
-1
-2
-
_
> 0
_ <- _+1
_
, -
_, -
.
_
,
,
, ( ).
.......
168
>=0
< _()
.
_
...... :
-1
-2
-
-1
-2
-
_
> 0
_ <- _+1
0
__ <- __ +1
_
, -
,
_.
_
169
-
.
, -
,
, .
...... .
,,,,,,,
,
< 80
< 1.70
,
_
_
,,,,,
.
,
__, .
,,,,,,,
,
< 80 < 1.70
,
_
,,,,,
......_
170
-1
-1
-2
-
_AN -2
-1
-2
-
-1
-2
-
_
> 0
- <- _+1
_ <0
_ <- _ +1
0
_0 <- _0 +1
_
,
.
-
_
171
( -
)
. -
.
1-50 200,000
51-100 180,000
101-200 160,000
200 150,000
:
=<50
< *200000
=< 100
< *180000
=< 200
< *160000
< *150000
_
_
_
......_ -
:
=<50
< *200000
, -
_ =<100 , -
< *180000 ,
_ =<200 -
< *160000 -
< *150000 -
_ .
172
.
.
, -
:
<=50
< *200000
_ >50 =<100
< *180000
- _ >100 =<200
_ -
< *160000
>50
< *150000
_
8.1.2
, -
, :
__1
_1
__2
_2
......
_
_
0
173
1,3,5,7,9
2,4,6,8
< 0 >9
_
.
, .
-.
-
.
8.2
, , -
. -
, -
.
, -
-
, _ -
-
, -
.
8.2.1 ...
... . , -
-
, .
174
... -
. -
,
.
-1
-2
-
_
<0
<1000
< +
_
,
_ _-
. ,
. , -
_-
.
,
,
. -
.
, ,
.
0.
175
:, ,
:
<- 0
<- 0
<>0
<- +
<- +1
_
>0
<- /
: ,
: ,
_
-
, -
0, -
.
-
. ,
, 0
.
.
8.2.2 _
-
_.
-
.
176
_
-1
-2
-
_ -
_
<- +
_ >= 1000
_ -
_.
( ), _-
_, .
, -
.
_.
... -
_
.
_ -
. -
, _.
_
-
.
177
, . ,
( ).
:, ,
:
:
<- 0
<- 0
_
_
!
=<0
, ...
_
!
_ >0
<- +
<- +1
;
! -
_ = = _ -
<- /
=,
=,
_
Pascal
PROGRAM athroisma2;
VAR
x,sum,count:INTEGER;
avg:REAL;
choice:CHAR;
178
BEGIN
count:=0;sum:=0;
REPEAT
REPEAT
write( :);
readln (x);
IF x<=0 THEN
writeln ( , ..);
UNTIL x>0;
sum:=sum+x;
count:=count+1;
write( ;);
readln(choice);
UNTIL (choice=o) OR (choice=O);
avg:=sum/count;
writeln(: , sum:5);
writeln( : ,avg:6:2);
END.
8.2.3 ......
,
. -
-
, .
, . -
-
, ( -
......
- _).
- .
, . -
, -
.
,
_.
, 1, -
.
179
1 2 3
-1
-2
-
_
1 100 2
<- +
_
,
. 1, .
-
100.
:,
<- 0
-
1 100 2
<- + ...., -
_
: , -
_ ..
...
-
. -
.
180
.
:
-
. ,
.
.
-
.
5
-
.
! 1 10
:,,
!:
!:
!:
1 10
1 10
<- *
,,,=,
_
!
_
_
Basic
DEFINT A-Z
FOR a = 1 TO 10
FOR b = 1 TO 10
c = a * b
PRINT a; x; b; =; c
NEXT b
181
PRINT
NEXT a
END
-
.
-
, , . .
:
_.
.
. , -
_ .
,
-
.
, _
.
, , ,
-
1. ;
2. ;
;
3. ;
4. - - -
_;
5. ;
6. ;
182
7. ;
8. _;
9. ;
10. -
;
1. . , Pascal, , -
, 1997.
2. . -. , Turbo Pascal, -
, 1996.
3. . , QuickBasic , -
, , 1992.
4. R. Shackelford, Introduction to Computing and Algorithms,
Addison-Wesley, USA, 1998.
5. S. Leestma-L.Nyhoff, Turbo Pascal, Programming and Solving, McMillan,
New York, 1990.
6. N. Wirth, Systematic Programming: An introduction, Prentice Hall, 1973.
http://www.swcp.com/~dodrill/
http://www.progsource.com
www.cit.ac.nz/smac/pascal/default.htm
http://www.cs.vu.nl/~jprins/tp.html
http://qbasic.com/
www.basicguru.com
9.
184
-
. , -
.
.
,
-
, -
, , .
.
.
, .
.
.
.
3 -
, ;
3 -
;
3 ;
3 -
;
185
9.1. .
-
, .
, , -
-
.
, 30, ,
.
<- 0
1 30
<- +
_
<- /30
..
, -
, -
.
-
,
. -
.
,
, .
30 1,
2,..., 30. -
.
-
, -
.
-
,
. -
186
, -
.
-
.
,
9.1.
. 9.1.
, .
,
[ ]. [2],
,
27.
[i] i-
-
.
-
. -
- , , , , .
-
i, j, k. .
-
.
187
: [30]
, -
.
. -
.
1
-
: [30], ,
: i,
<- 0
i 1 30
[i]
<- + [i]
_
<- /30
<- 0
i 1 30
[i] <
<- +1
_
_
:,
,
_
,
, . -
, ,
[i], -
188
,
<-+ [i].
, -
-
, -
, . , -
-
30 .
, -
2
-
,
-
- , , -
, 2 100.
.
.
N
Xi
i=1
=
N
N
Xi
i=1
2
= 2
2
N
-
. ,
. -
, -
, , -
.
, 3.
: i, , [100], , ,
_2,
: , _
!
( 100)
189
i 1
,i,-
[i]
_
!
<- 0
_2 <- 0 -
i 1
,i,-
[i]
<- + [i]
_2 <- _2 + [i]^2
_
!
T <- /
!
_ <- _(_2/ - ^2)
!
i 2 N
j N i -1
X[j-1] > X[j]
! j j-1
<- X[j-1]
X[j-1] <- X[j]
X[j] <-
_
_ !! j
_ !! i
!
MOD 2 =0 TOTE
<- (X[N/2]+X[N/2+1])/2
<- X[(N+1)/2]
_
!
============
=,
= ,
= , _
= ,
_
190
Basic
DEFINT A-Z
DIM x(100)
CLS
sum = 0: sum2 = 0
INPUT N=, n
FOR i = 1 TO n
PRINT ; i; - : ;
INPUT , x(i)
NEXT i
FOR i = 1 TO n
sum = sum + x(i)
sum2 = sum2 + x(i) ^ 2
NEXT i
mt! = sum / n
ta! = SQR(sum2 / n - mt! ^ 2) ..
FOR i = 2 TO n
FOR j = n TO i STEP -1
IF x(j - 1) > x(j) THEN SWAP x(j - 1), x(j)
NEXT j
NEXT i
IF n MOD 2 = 0 THEN
median = (x(n / 2) + x(n / 2 + 1)) / 2
ELSE
median = x((n + 1) / 2)
END IF
PRINT
PRINT =======================
PRINT =; n
PRINT =; mt!
PRINT =; ta!
PRINT =; median
END
191
9.2.
, -
.
,
.
.
. -
-
.
. -
,
100. -
,
.
-
.
,
, -
.
.
.
. -
,
. , -
, .
-
, .
9.3.
30 ,
-
192
30 , .
.
.
1 2 10
1 25 21 32
2 26 22 31
. .. .. .. ..
30 27 23 30
30 -
, 300 .
,
, . -
27.
, (
) ( ).
[30,1] 27.
-
[i,j] i j -
, i 1 30 j 1 10.
3010.
( 30 -
10 ). , , -
.
193
_2
: [30,10], [10]
: i, j, ,
!
i 1 30
j 1 10
, i, j
[i,j]
_
_
!
j 1 10
<- 0
i 1 30
<- + [i,j]
_
[j] <- /30
_
j 1 10 ,
<- 0
-
i 1 30
[i,j] < [j] , -
<- +1 -
_ -
_ .
, i, :, [j]
,
_
_
Pascal
PROGRAM poleis;
VAR
temperature: array[1..30,1..10] OF REAL;
ave:array [1..10] OF REAL;
total:REAL;
i,j,days:INTEGER;
194
BEGIN
FOR i:=1 TO 30 DO
FOR j:=1 TO 10 DO
BEGIN
write ( :,i,j, );
readln (temperature[i,j])
END;
FOR j:=1 TO 10 DO
BEGIN
total:=0;
FOR i:=1 TO 30 DO
total:=total+temperature[i,j];
ave[j]:=total/30
END;
FOR j:=1 TO 10 DO
BEGIN
days:=0;
FOR i:=1 TO 30 DO
IF temperature[i,j] < ave[j] then
days:=days+1;
writeln ( ,i,
,ave[i]:4:1);
writeln ( :,
days);
END
END.
-
,
, -
. -
-
.
, . -
. ,
.
, 25
[1,1,1].
195
2001
1 2 10
1 25 21 32
2 26 22 18 31
2000
. .. .. .. ...
1 2 10
30 27 23 18 30
1 25 21 32
2 26 22 18 31
1999
. .. .. .. ...
1 2 10
30 27 23 18 30
1 25 21 32
2 26 22 31
... ... ... ...
30 27 23 30
4.
:
. -
.
. -
,
.
. -
, .
-
. ,
.
, -
,
, .
:
196
1. -
, .
2.
, -
.
3. -
,
.
.
,
.
: [10,7], i,j, , ,
: [10]
!
i 1 10
,i,
[i]
j 1 7
, j,-
[i,j]
_
_
!
!
<- 0
i 1 10
<- 0
j 1 7
<- +[i,j]
_
. ,[i], =,
<
<-
<- i
_
_
197
.. ,, ,[]
!
!
<- 0
j 1 7
<- 0
i 1 10
<- + [i,j]
_
. ,j,- =,
<
<-
<- j
_
_
.. ,, ,,-
_
Pascal
PROGRAM cinemas;
VAR
i,j,k,max,sum:INTEGER;
tickets:ARRAY[1..10,1..7] OF INTEGER;
name:ARRAY [1..10] OF STRING;
BEGIN
FOR i:=1 TO 10 do
BEGIN
write ( : );
readln (name[i]);
FOR j:=1 TO 7 DO
BEGIN
write ( , j, : );
readln(tickets[i,j]);
END;
END;
max:=0;
FOR i:=1 TO 10 DO
BEGIN
sum:=0;
FOR j:=1 TO 7 DO
sum:=sum+tickets[i,j];
198
max:=0;
FOR j:=1 TO 7 DO
BEGIN
sum:=0;
FOR i:=1 TO 10 DO
sum:=sum+tickets[i,j];
writeln( ,j, = , sum);
IF max<sum THEN
BEGIN
max:=sum;
k:=j;
END;
END;
writeln ( , max, , k);
END.
9.4.
-
. -
:
.
.
.
.
.
-
.
, -
199
, -
.
:
.
.
.
.
-
. -
, , -
. , -
.
.
3 -
, 2.
-
.
.
, -
.
.
:
3
3
, -
.
. -
.
200
.
.
( )
, .
-
.
-
. -
(-
). ,
. -
. -
.
-
, . -
-
.
, , , , -
,
-
1. ;
2. ;
3. ;
4. ;
5. ;
6. ;
7. ;
8. .
201
9. ;
10. ;
11. ;
12. ; -
;
1. . , Turbo Pascal 6.0 , -
, , 1993.
2. QuickBASIC: , , -
, 1991.
3. . , QuickBasic , -
, , 1992.
4. R. Shackelford, Introduction to Computing and Algorithms,
Addison-Wesley, USA, 1998.
5. S. Leestma-L.Nyhoff, Turbo Pascal, Programming and Solving, McMillan,
New York, 1990.
6. N. Wirth, Systematic Programming: An introduction, Prentice Hall, 1973.
http://www.swcp.com/~dodrill/
-
.
http://www.progsource.com
, , -
:Pascal, Delphi, C/C++, Java, Perl, Visual Basic.
www.cit.ac.nz/smac/pascal/default.htm
Pascal -
. , .
202
http://www.cs.vu.nl/~jprins/tp.html
, , , -
Turbo Pascal.
http://qbasic.com/
,
Qbasic.
www.basicguru.com
Basic. -
, , -
.
(Usenet):
comp.lang.pascal
comp.lang.pascal.misc
Pascal
alt.lang.basic
comp.lang.basic.misc
Basic
10.
204
-
.
. ,
-
.
,
,
. -
-
.
:
.
-
-
.
.
.
-
.
3
;
3
;
3 -
;
3 ;
3 ; -
;
205
10.1.
,
,
. 6,
-
, , -
(top-down). -
-
.
o- , -
.
-
.
-
,
-
.
-
.
1
o
,
.
.
:
. -
:
206
-
.
-
. ,
,
,
-
.
10.1
.
( 3)
-
1 2 .
, -
(subprogram).
207
. 10.1
10.2.
,
.
, -
.
.
208
, ,
.
-
:
. -
, ,
.
.
,
-
.
.
.
, -
,
.
. ,
.
10.3.
6.
, -
:
-
.
.
-
.
209
.
-
.
-
.
-
, -
.
-
.
. , -
. -
, -
, -
.
.
. ,
,
-
, ( ).
-
,
, . -
, -
.
10.4.
.
, ,
, -
210
.
, -
.
, .
-
.
-
, -
.
-
.
,
, .
10.5.
, -
. -
.
. ,
,
. -
.
. -
, ,
. -
.
.
.
211
, -
.
-
( -
).
-
.
,
.
.
) , -
) (=r2)
) , ,
, -
.
-
. -
, . -
_, -
:
_()
_
_ >0
_
212
. -
.
, .
_(R)
.
,
.
_(R) :
=3.14
: R
_ <- *R^2
_
.
, -
. -
.
()
:
:,
_
:
_2
: R, E
_(R)
<- _(R)
()
_
. ,
-
213
. 10, -
:
10
: 314
-
, .
10.5.1
.
( ):
....
<-
...
_
-
. ,
.
-
.
, , ,
-
, -
_<-*R^2.
, -
.
.
<-_(R).
O , : -
R. -
R
. -
. -
, -
.
214
10.5.2
.
( )
_
.
, -
/
.
.
.
,
.
- (-)
(, , )
-
. -
.
. -
.
_(R)
()
215
-
. ,
_
,
. ,
_ ,
( -
) R -
. -
-
.
-
. , -
. , -
-
.
-
. -
.
2 -
Pascal Basic.
Pascal
PROGRAM example2;
VAR
r,e:REAL;
FUNCTION area(r:REAL):REAL;
BEGIN
area:=pi*sqr(r)
END;
PROCEDURE output(result:REAL);
BEGIN
writeln ( :,result:6:2)
END;
BEGIN
input(r);
e:=area(r);
output(e)
END.
Basic
3
DECLARE SUB Eisodos (nb!)
DECLARE SUB Ektypwsh (res!)
DECLARE FUNCTION Emvado! (r!)
CLS
CALL Eisodos(r)
e = Emvado(r)
CALL Ektypwsh(e)
END
10.5.3
-
.
217
-
.
, , 1, 1, ,, 2, 2
_3 -
, ,, ,
, .
,, 1 - -
_3 - (formal parameter list)
-
_3. - .
. -
-
,
(actual parameter
, . list) -
, , -
.
,
.
218
-
_3 .
,, 1
1 , ,
, .
5 7.
, -
1 1 .
, -
_, -
-
-
- . (=5), (= 7),
1 (=-2) 1 (=12).
. .
:
. 10.2. ()
()
()
() 1 1
.
219
-
.
, -
, (return address), -
(execution time stack). -
-
-
. , -
-
. , a b,
c .
c, b, a.
,
. -
LIFO
.
. 10.3. -
.
220
.
. -
-
.
.
10.6. -.
.
-
. ( -
) .
.
: A, B,
...
_
: , , ,
...
_
: , ,
...
_
221
, , -
, .
.
, , , ,
.
,,.
.
-
, .
, -
,
. R
2.
.
-
, -
, . (scope) -
.
-
.
-
, . -
.
, -
,
.
-
, .
,
. .
222
-
, -
.
.
.
-
.
,
.
10.7.
-
.
. .
3,
,
.
-
- ,
-
.
. ,
:
:
n ( n 1) ! n > 0
n!=
1 n = 0
T -
,
1 n=0.
223
n*(n-1)!, -
,
.
-
.
():
!
=0
< 1
< *(-1)
_
_
():
!
: i,
Fact < 1
i 2
Fact <- Fact*i
_
_
, -
. -
-
, -
.
-
-
.
5!
().
5,
0, (4). -
224
, (3) -
-
(0).
(5)
<* (-1)
(4)
<* (-1)
(3)
<* (-1)
(2)
<* (-1)
(1)
<* (-1)
(0)
<1
=0 (0) 1, -
.
(2)=1*2, -
(3)=2*3, (4)=6*4 .
(5)=24*5. -
120 .
225
(5)
<* (-1)
5 120
(4)
-
<* (-1) -
4 24 .
-
(3) -
,
<* (-1)
3 6 ( ).
-
(2) ( ) -
<* (-1)
.
2 2
, -
-
(1) , LIFO
<* (-1) , -
1 1
-
, -
(0) -
.
<1
0 1
-
. -
3,
.
,
, -
.
226
Pascal
FUNCTION factorial(n:INTEGER) : INTEGER;
BEGIN
IF n=0 THEN
factorial:=1
ELSE
factorial:=n*factorial(n-1);
END;
asc
FUNCTION Factorial (n)
IF n = 0 THEN
Factorial = 1
ELSE
Factorial = n * Factorial(n - 1)
END IF
END FUNCTION
-
.
,
. -
, . -
,
.
-
. -
,
. -
,
.
, -
.
.
, , , ,
, .
-
1. ;
2. ;
3. ;
4. ;
5. ;
6. ;
7. ;
228
8. -
; -
.
9. ;
10. ;
11. ;
.
1. . , . , Pascal, ,
1984.
2. . , Basic: , , , 1991
3. . , QuickBasic , -
, , 1992.
4. R. Shackelford, Introduction to Computing and Algorithms,
Addison-Wesley, USA, 1998.
5. S. Leestma-L.Nyhoff, Turbo Pascal, Programming and Solving, McMillan,
New York, 1990.
6. N. Wirth, Systematic Programming: An introduction, Prentice Hall, 1973.
http://www.swcp.com/~dodrill/
http://www.progsource.com
www.cit.ac.nz/smac/pascal/default.htm
http://www.cs.vu.nl/~jprins/tp.html
http://qbasic.com/
www.basicguru.com
(Usenet):
comp.lang.pascal comp.lang.pascal.misc Pascal.
alt.lang.basic comp.lang.basic.misc Basic.
11.
230
, -
,
.
-
,
. -
-
. -
. ,
.
:
, , , ,
,
,
-
.
3
;
3 -
;
3 -
;
3
;
3 -
;
3
;
231
11.1.
,
,
-
, , ,
. -
-
-
.
, -
-
-
.
. -
(object - orie-
nted programming)
, -
.
-
-
- -
" ;".
, ,
-
()
.
, -
. -
,
,
.
, -
. ,
,
-
-
232
, .
,
.
-
- Visual C++, Java, Visual Basic, Delphi.
-
Simula
Smalltalk. 11.1.1.
-
(objects). , -
,
. -
,
, , (
11.1).
. 11.1.
, -
-
. , ,
.
, ,
, .. -
.
, ,
, -
.
233
, -
,
.
, ,
( 11.2).
. 11.2 .
; -
.
,
,
. , (data)
(operations) -
. -
(methods).
,
.
-
, , . -
, . -
-
, , , -
, , ,
11.3.
234
. 11.3 .
-
, , -
. -
-
, , -
, -
.
-
. ,
. -
, -
, -
.
11.1.2.
,
. , -
. -
, -
. -
235
-
. -
, (instance)
.
(class) -
. Smalltalk, -
-
- , , -
. - ,
. - .
. , -
-
, . -
(metaclass).
11.1.3.
-
.
. -
,
(attributes properties),
.
.
, , -
,
, -
.
-
,
,
.
-
,
(properties window), -
.
-
,
236
-
, , -
. -
:
(Data abstraction). -
.
. -
. -
-
.
(Encapsulation). , -
-
()
(). -
-
. -
. -
,
.
(Inheritance). -
-
.
(subclasses) .
()
.
, -
-
, , ..
.
237
(Polymorphism). -
-
, , ,
.
. -
-
. -
, -
. ,
, -
. -
. -
.
,
. -
, Visual C++ Visual Basic, -
:
. =
. -
.
11.1.4.
,
Smalltalk Visual Basic, -
(methods).
. -
.
. -
-
.
,
. :
.
238
11.2.
(event-driven prog-
ramming) ,
, -
.
, -
, -
.
, -
-
. -
.
. ,
, -
, -
.
,
-
, ,
.
, -
.
(event) -
, , -
.
, .
, ,
,
..
.
239
11.2.1.
, -
,
-
.
, -
,
(event procedures),
.
. , -
, -
.
:
_
...
...
To -
,
.
-
,
, -
.
-
, - -
.
, Visual
. C++ -
-
(functions).
, -
,
:
240
...
...
-
-
:
_
...
...
-
.
(modular) , -
, -
(structural) -
, -
.
,
, .. -
.
11.2.2.
-
, -
:
1. .
2. -
.
3.
, .
241
4. , -
.
5.
( 2).
-
- -
. - .
-
. -
, - -
, .
. -
-
.
11.3.
-
-
-
,
.
-
. -
,
(user interface). , -
-
. ,
-
. -
-
.
.
,
. -
.
242
, -
-
. -
. -
, -
-
.
-
:
1. -, -
.
2. -
.
3. .
, , -
,
-
.
-
, -
.
,
.
-
. :
,
,
243
.
.
(toolbox)
.
-
, .
. -
, -
.
-
.
-
, :
-
( ) ,
,
,
,
:
1
1
1
2
2
2
3
3
3
244
,
.
-
. -
, -
, .
-
, :
-
. -
1, , -
- -
- ,
,
. -
,
,
-
.
-
:
0
1
1
-
,
2
2
245
3
3
4 ( )
-
-
,
-
.
-
-
-
-
.
. 11.4.
, -
11.4.
,
. -
.
.
246
, .
.
-
, , .
-
:
-
,
, .
.
,
-
.
:
1_()
1. =
2. =
3. =
2_()
1. =
2. =
3. =
3_()
1. =
2. =
3. =
-
:
247
_()
, , -
. -
-
. -
, -
, , -
.
-
, -
.
(
11.5).
. 11.5.
-
( 11.6).
248
. 11.6.
,
.
11.4.
. -
. ,
.
, Visual C++,
Delphi Visual Basic, -
. -
, ,
. -
, -
.
249
-
, -
, , ,
, , ,
. ,
, ,
,
.
,
-
. -
, (toolboxes),
(debugging tools), (code windows),
(report generators) -
. -
(wizards) -
, .
,
,
-
.
,
-
-
.
.
11.4.1
(menus) , -
, -
.
-
.
(menu bar)
( 11.7).
250
. 11.7.
-
- (popup menu) ( 11.8).
- , -
-
-
.
, -
(Menu
Editor).
. 11.8.
251
. 11.9.
-
, -
(toolbars) ( 11.9).
.
11.4.2
(dialog boxes) ( 11.10) -
. -
-
. -
, -
.
-
. -
-
. 11.10.
.
. -
, -
,
,
.
, -
252
11.5.
-
, -
.
, -
.
-
-
, -
, -
.
, . ,
- , ,
-
. -
, -
- , -
, - ,
. -
- ( 11.11).
-
(document-centered ,
view) - -
- . ,
-
(multitasking).
.
253
. 11.11.
, (linking)
.
, -
. ,
, ,
. -
.
, -
,
. -
.
,
(real-time)
-
. -
, -
, -
,
:
254
-
,
(embedding)
. -
.
.
, -
, -
.
. -
.
-
-
. ,
,
-
. -
-
.
, ,
-
. -
.
.
. -
-
, -
-
.
, -
.
,
,
,
.
255
-
-
, , -
, , -
-
.
, -
. ,
-
,
. ,
, -
-
.
-
,
, .
-
.
,
.
-
. -
, -
-
.
,
, , , , , -
-, , -
, , , , -
.
256
-
1. -
.
2. .
3.
.
4. -
.
5. .
6. .
7. ;
8. .
9. -
;
10. -
;
11. -
;
12. -
;
13. -
.
1. Object-Oriented modeling and Design, Prentice Hall, New York, 1991.
2. G. Masini, A. Napoli, D. Colnet, D. Lonard, K. Tombre : Les langages a
objets, InterEditions, Paris, 1989.
3. Gary Entsminger: Secrets of the Visual Basic for Windows, SAMS
Publishing, Indiana USA, 1992.
4. Bertrand Meyer : Object-oriented Software Construction, Prentice Hall,
London, 1988.
257
5. . -. : Visual Basic
4.0, , , 1997.
http://iamwww.unibe.ch/~scg/Ooinfo/
-
Internet, -
.
http://whatis.com/oop.htm
-
.
http://oop.cs.technion.ac.il
-
.
www.oop.com/frameworks/delphi/
Delphi.
http://www.humboldt.edu/~jsb7/C/WIN95/events.shtml
.
http://midrangecomputing.com/mc/97/05/
-
.
http://service.shu.ac.uk/schools/sci/maths/jw/jw/vbintro/
Visual Basic Delphi.
http://www.cnet.com/Resources/Info/Glossary/Terms/ole.html
OLE (Object Linking and
Embedding).
12.
260
. -
, -
, -
(user
interface) -
. , , -
.
-
.
:
-
,
3
;
3 ,
;
3 ;
3 -
;
3 ,
;
261
12.1.
(user interface)
-
.
, -
( 12.1).
, -
.
-
, .
. 12.1 :
-
, -
(lightpen) . -
, , , , -
, ,
. , -
, ,
, -
,
.
.
.
, -
.
262
, Standard Directory of
Electrical and Electronics Terms, interface
shared boundary, -
.
( -
) interface
. interface -
, , -
.
, .
, -
,
-
.
.
, , -
.
-
. -
,
-
.
12.2.
,
, ,
. -
, (,
) ,
, -
.
-
(command-based). -
263
, -
, . -
-
DOS. -
, .
-
, -
.
.
-
DOS, DOS (dosshell), -
DOS (Norton
Utilities, ). , -
, -
,
.
Apple.
Apple
,
GUI (Graphical User Interface).
,
,
.
,
PCs,
. -
, Windows S/2. -
Apple.
Macintosh Apple
-
.
GUIs -
. , -
, clicks -
.
GUI
. , , -
264
-
.
:
: -
, .
:
. -
-
. (-
12.2):
3 ,
,
3 (title bar),
,
. 12.2: .
265
3 (menu bar), -
,
3 (toolbar), -
-
,
3 (status bar), -
,
3 (scroll bars), -
,
, -
,
3 (control menu),
,
3 (maximize button),
,
3 (minimize button), -
,
3 (restore button), -
,
3 (close button), .
:
. -
. -
, -
(, , ).
:
.
.
266
12.3.
-
. -
;, -
- . ,
- ,
,
,
-
.
, ,
-
-
(user task analysis).
,
. ,
.
:
: , , -
, -
.
, -
,
.
, : -
, . -
, - , -
, -
.
.
:
. ,
video
,
-
267
video,
.
: -
.
-
.
. -
, -
,
, -
.
, -
, . -
, -
,
-
.
: -
, -
.
.
-
-
.
, ,
.
:
-
.
-
:
268
3 on line , -
.
-
, , ,
.
3 , (assistants)
.
.
3 ,
.
: -
, -
-
. , -
-
.
:
. -
,
. ,
, ,
- ,
. -
-
.
.
: -
. ,
; (/), ;
(/), -
-
( , ).
.
269
................
!
, , ,
()
................
-
()
<- 0
_ ,
(/);
.
, , , n
<- 1
, , ,
<- 2
_ =1 =2
, -
, -
.
. ,
, -
-
.
-
.
. -
-
.
( 12.3) :
270
. 12.3.
, ,
, -
-
.
,
.
, , . -
, -
.
,
.
, , .
, -
-
,
.
12.4.
-
-
,
.
271
12.4.1.
-
. -
, -
. -
, -
. ,
-
.
: , , -
. ,
. , ,
, . -
:
,
,
,
,
,
-
.
. -
. -
.
12.1.
272
12.1 :
. -
-
.
:
. -
. -
-
, -
, , -
-
.
. -
, -
. -
.
-
. .
, -
.
273
. , , -
-
, -
.
. -
, -
-
.
.
.
.
12.2 .
12.2 :
-
.
12.4.2.
-
. , -
,
. , -
274
. -
-
.
,
,
, :
. -
-
.
, -
.
,
.
. -
,
.
-
-
.
. -
. ,
.
-
.
-
-
. -
. -
-
.
12.5.
-
.
, .
275
, -
, .
. -
, :
:
. -
. -
.
-
.
.
, -
.
.
, -
.
. -
. -
,
.
:
, .
-
. -
, , .
-
, -
.
, -
.
: -
. .
, -
, -
-
276
. -
, -
. ( -
)
.
(user
interface) . -
,
(GUI). -
, . -
-
.
.
(user interface), , -
, ,
-
1. -
user interface
.
2. -
.
3.
GUI.
4. .
5.
.
6. -
.
277
7. -
-
;.
1. Lon Brafield: The user interface Concepts & Design, Addison-Wesley
Publishing Company, Amsterdam, Holland,1993.
2. Robert Lindstrom: Multimedia Presentations Create dynamic
presentations that inspire, Osborne-McGraw Hill, USA, 1994.
3. Arch Luther: Designing Interactive Multimedia, antam Books, New York,
USA, 1992.
4. Mark Maubury: Intelligent Multimedia Interfaces, AAAIPress/The MIT
Press, California, USA, 1993.
5. Karen McGraw: Designing and Evaluating User Inetrfaces for
Knowledge_based Systems, Ellis Horwood Limite, West Sussex, England,
1992.
6. : , , -
, , 1994.
7. Ben Shneiderman: Designing the User Interface Strategies for Effective
Human-Computer Interaction, Addison-Wesley Publishing Company Inc,
New York, USA, 1992.
http://cfg.cit.cornell.edu/cfg/design/contents.html
-
, ,
, , ..
.
http://www.depauw.edu/~dberque/hci/bell/index.html
Ben
Shneiderman Designing the User Interface -
, -
.
278
http://www.depauw.edu/~dberque/hci/chauner/main.htm
, , -
,
, ,
.
http://www.sju.edu/~jhodgson/gui/guihome.html
. -
,
.
13.
280
-
, , -
, -
. -
, , -
.
, -
.
, -
.
,
, -
, ,
.
:
.
.
.
.
3 -
;
3 ;
3 -
;
3
,
;
3
;
281
13.1
, , -
, . -
,
.
-
, :
, -
. -
-
.
, -
, -
.
, , -
.
-
, -
-
. -
, . -
-
,
.
-
-
-
, -
(bug)
. -
(crash) .
, -
, -
bugs, -
-
.
.
282
, -
-
,
.
,
, ,
-
,
,
.
.
-
-
, -
.
(testing) -
.
-
2000 (millennium bug). -
, -
.
-
:
1962 Mariner 1 -
Canaveral
. -
-
... (NASA) -
, -
283
.
. NASA
-
FORTRAN -
. 80 -
.
1990 -
-
AT&T, -
-
. 5
.
Pentium 1994 ,
-
.
Thomas Nicely Lynchburg
Virginia . -
,
-
-
450
1995 -
Denver . -
. -
-
, -
.
,
3,2 .
284
13.2
,
(debugging). -
.
,
. -
.
, -
.
-
, -
, ,
-
-
- . -
- , -
. .
-
-
.
.
13.3.
-
. -
,
.
,
-
. -
-
. .
(debuggers).
285
, -
-
.
:
(watch expressions)
. ,
,
. -
.
. 13.1.
(breakpoint) -
. -
.
, -
.
, -
.
-
.
286
. 13.2.
(history)
. -
.
, -
. -
(tracing) , -
.
-
-
.
. 13.3.
287
-
(.. -
, ), -
-
.
,
,
, -
.
13.4
. -
, -
.
288
. -
-
, .
, -
-
. .
- -
, - :
.
-
,
.
,
(exception error handler), -
. -
.
-
-
,
.
-
- :
-
-
Java, ADA C++ - .
- .
(exceptions),
Visual Basic -
, .
(On Error GoTo).
, -
, -
, -
.
-
, -
. -
(..
) , -
.
289
, .
,
.
-
-
. ,
( ) -
.
. -
.
.
-
. -
.
,
-
-
.
, , , ,
.
-
1. -
.
290
2. -
.
3.
.
4. .
5. -
.
1. , -
, 2, , 1986.
2. . -. : Visual Basic
4.0, , , 1997.
3. Ivars Peterson: Fatal Defect:Chasing killer Computer Bugs, Science
News, USA, 1995.
http://www.alsplace.com/home/pages/famous_bugs.htm
.
http://www.bugnet.com
.
http://www.guide-p.infoseek.com
.
http://www.netstuff.com/computerbug
.
http://www.techweb.com
, ,
2000.
http://www.year2000.co.nz
2000.
14.
-
292
-
.
,
, . -
, ,
, -
. VTOC (Visual Table
Of Contains), -
.
-
.
:
-
, -
.
-
.
-
( , ..).
.
.
.
3 ,
;
3 ;
3 -
;
3 ;
-
293
14.1
, -
, .
-
. -
. -
:
,
3 ( , - -
)
, -
3 ( , ) -
.
3 ( )
3 ( )
3
, , -
,
, -
, .
-
. -
. -
.
,
. -
,
. ,
, -
.
14.1.1 -
, -
. -
( -
), , -
. -
, -
294
. , -
, .
. -
:
3 .
3 .
,
!!
, -
.
-
-
.
1000 . ,
. -
.
:
, -
, .
(<>), , -
, (=) -
.
.
2, 2, 3, 3, 3, 3, 5, 6, 6, 6, 6, 6,
7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9.
:
-
295
2 2
3 4
5 1
6 5
7 1
8 6
9 6
.
1
: i, S, _, A[1000]
i <- 1
S <- 0
_ <- [i]
i < 1001
_ <> [i]
_, S
_ <- A[i]
S <- 0
_
S <- S+1
i <- i+1
_
_, S
_ 1
: i, S, _, A[1000]
i <- 1
S <- 0
_ <- [i]
i < 1001
_ = [i] i < 1001
S <- S+1
296
i <- i+1
_
_, S
. <- (i)
S <- 0
_
_ 2
3
: i, S, _, A[1000]
i <- 1
S <- 0
_ <- [i]
i < 1001
_= [i]
S <- S+1
i <- i+1
_ , S
_ <- [i]
S <- 0
_A
_
_, S
_ 3
-
.
. -
(i).
(i),
, (i). -
(i).
i
i<1001. _(i). -
, .. -
i<1001, i .
-
297
, ... -
.
, -
(=) (<>),
...TOTE....
:
3 .
3 , -
.
3 , .
,
(i) .
., S -
, .<-(i), s<-0" -
. -
, . -
.A, S ,
, ,
. , -
s<-0, .A<-A(i)" -
-
. ,
.
s<-s+1.
14.1.2
-
. ,
, -
, ,
.
. -
,
.
,
, 3
.
298
4 .
,
.
, -
.
-
.
_2
,
,
<
,
,
_
_ _2
, ,
.
;
.
-
.
3 6 (3!=1*2*3=6). -
, -
.
_3
, ,
, ,
<
<
, ,
-
299
<
, ,
, ,
_
_
<
, ,
<
, ,
, ,
_
_
_
_ _3
, -
24 (4!=1*2*3*4=24) -
, -
, -
.
-
, , -
, -
.
,
, -
.
,
, -
. -
,
, 16%,
, , 50%.
.
.
300
_2
,
,
>
- temp <-
<-
- <-temp
- _
. ,
_ _2
.
,
.
, , -
.
.
_3
:
, ,
<- 0
, ,
=0
<- 1
>
temp <-
<-
<- temp
<- 0
_
>
temp <-
<-
<- temp
<- 0
_
_
, ,
_ _3
-
301
, -
. =1 -
. -
, -
( ),
. > > -
, .
(>) (>, >).
.
.
14.1.3
-
.
, ,
.
,
-
, .
-
.
, -
, -
. . .
.
-
.
,
, -
.
-
, .
. -
.
, ,
. ,
; .
302
. -
; -
, -
.
(,
, ), -
. -
: , ;
12; 32;
, -
-
.
:
3 -
;
3
;
3 -
;
:
.
.
0 1.
.
.
I, V, X, L, C, D, M, -
-
.
,
.
. -
,
.
-
303
, -
-
. , -
. .
, , - -
, . -
-
, - , -
.
.
.
-
.
,
.
365 , , 366.
, , , , ,
31 .
, , , 30 .
28 , ,
29.
4,
100, 400. -
: 1984 ( 4), 1900 (-
4 100), 2000 (
4, 100, 400), 1993 .
.
4 1582
. 4 15 .
10 1923. 10
23 1923.
304
-
11/3/1923 22/3/1923. -
5/10/1582 14/10/1582.
, .
, -
.
3 , .
3 , .
.
3 , .
, -
.
3 ,
.
, ,
_1(, , , c)
c=0
_2(, , , c)
c=0
_3(, , , c)
c=0
_1(, , , c)
!
c <- 0
>0 >0 >0 c <- 1
_ _1
_2(, , , c)
!
c <- 1
(10< <23) =3 =1923 c <- 0
_ _2
_3(, , , c)
! ( =1 )
4 <- mod 4
100 <- mod 100
-
305
_2. -
,
.
.
, .
-
-
. -
.
.
14.1.4
, -
. :
. -
, (quick
306
sort), ( -
) ,
,
,
, -
,
,
, -
.
,
-
, -
.
, .
( -
).
.
number>0
<- +1
_ number<0
<- +1
<- +1
_
number<0
<- +1
_ number>0
<- +1
<- +1
_
-
307
number=0
<- +1
_ number<0
<- +1
<- +1
_
;
,
, -
,
. -
2 .
1000 . -
, -
.
3. , -
,
. -
,
.
:
.
,
.
,
.
-
, , -
.
308
. ;
12345. 6 :
6 =(1*1+2*3+3*5+4*7+5*13) mod 11
=(1*1+2*3+3*5+4*7+5*13) mod 11 =(1+6+15+28+65) mod 11 = 5.
123455.
, , -
6, ,
1000 .
6 : -
,
. 11.
. 11 0
10. 10, 6 0.
-
.
,
.
, -
,
1000 ,
, .
,
, ISBN -
-
.
14.2
-
.
14.1 -
.
-
309
-
,
-
-
.
. 14.1.
: .
-
.
,
, -
.
310
14.2.1
. , -
, -
, -
.
. -
-
-
.
. -
-
. (test file), -
, -
.
14.2.2
. -
,
, . -
.
. (test file)
,
-
-
. , -
.
.
-
. -
(users manual).
. -
,
. -
. -
, , -
, -
.
-
-
311
.
.
:
- - .
, -
.
, -
, .
. ,
-
.
. -
.
.
. -
, ,
.
.
,
-
, -
. -
. -
.
-
-
.
.
. -
, , .
-
. -
. -
312
2000
,
, ,
,
. , -
, -
, -
. , -
,
, -
.
, , -
,
.
.
HIPO (Hierarchy plus Input Process Output). -
,
. .
(Visual Table Of Contains, VTOC). -
.
- -
(Overview Hierarchy plus Input Process Output, Overview
HIPO). , ,
.
, ,
(Detail HIPO). ,
-
.
-
313
, VTOC,
. -
,
, ,
. -
,
. -
, .
VTOC
.
. 14.2. VTOC
14.2 -
, . -
, -
. , -
. ,
-
.
314
-
, ,
. (
), 0000.
1000, 3000 ...
9000 -
( 1000, 3000 .). -
, -
.
, -
. 1100
1300 1000 ..
-
.
, , , ,
, . -
, -
, .
,
. -
, , -
, -
.
-
, .
3
, -
l
( 3 , , , ).
l
l
.
, ,
.
, -
.
.
-
315
14.2.3
-
. , -
, , ,
, -
,
, . -
, .
-
.
, -
.
14.3
-
, -
(, , -
).
,
, , -
, , o
(version).
-
, -
. , ,
, , , -
(DOS ver.5 DOS ver.6),
, (Windows v.3.1, Windows
v.3.11). -
. -
,
-
(Windows 95, Windows98, Office 97 .).
,
, MS-DOS -
Windows.
316
, ,
.
; ;
. .
, , ,
, . ,
, , -
.,
, , , , ,
, .. ( ).
-
,
-
, , , .. ( ).
-
, -
( ).
-
. -
,
( ).
. -
,
(
).
, -
,
14.3.
-
.
, .
, -
, .
-
317
. 14.3.
-
, :
3 -
.
3 , -
.
3 .
3 (, )
.
3 (modules) -
.
3 -
.
, :
3 -
. -
.
3 . -
(source program).
3 , -
.
(object program).
318
3 "
.
3 -
, .
:
,
. -
, -
.
. 3 ,
, -
.
3 -
.
3 -
.
3 -
.
3 , -
-
.
. -
,
, -
. -
.
-
.
. :
3 -
.
3
.
3
.
-
319
3 -
.
3
. ...
.
14.4
.
. 14.4. -
-
.
-
.
-
,
.
.
-
.
320
, -
.
.
VTOC
.
, , HIPO, VTOC,
, .
1. ;
2. -
;
3. 3 ;
4.
;
5. -
(VTOC).
6. -
;
7. .
8. ;
9. ;
10. -
;
11. -
;
1. , -
, 1986.
2. . , , -
, 1992.
-
321
http://diamond.idbsu.edu/~philmac/cs125/980331.htm
.
http://129.219.88.111/softeval.html
.
http://www.acm.org/pubs/toc/Abstracts/cacm/62963.html
, , -
, ACM (Association of Computing Machinery).
algorithmic languages
- object oriented language
-
. , -
-
algorithm
.
- data abstraction -
. -
alphanumeric -
.
,
.. - loop
. , -
.
recursion -
- event -
. -
. -
recursive function
.
-
, - machine language
. -
.
analysis
programming
- language -
. .
object . graph ,
- , -
- .
.
write -
object program -
- .
.
328
data , - -
.
, -
.
program testing and debugging -
index , - .
program testing
-
.
.
pointer - -
- .
.
structure
tree - programming -
. -
, ,
, . -
, .
. : ,
.
read -
, . debugging -
-
procedural language
.
debugger -
. , -
, -
interactive -
-
.
() - assignement -
. .
interface software testing
, -
, - -
, - .
.
instruction -
interpreter - -
, .
329
- access
-
. .
table breakpoint
-
. .
() information - constant
, , - .
, ,
stack
-
.
.
() program -
string
. -
,
-
.
, merging -
.
.
programming -
. .
append condition -
. -
,
.
bottom-up approach
bug -
- .
- program design
.
331
- -
. - -
- .
.
subprogram
sorting - ,
- .
.
natural language
program
documentation - , -
. .
operand nesting H -
. -
.
operator
- pseudocode -
.
.
artificial intelligence -
embedding= formatting=
debugging=
empirical= free text=
decision=
emulation= function=
declaration=
encapsulation= global=
335
.-., , , , 1994
al Khowarizmi 25 64 29
ALGOL 120 16, 81 10
Allen P. 122 - 317 28
BASIC 122, 123 232 128
Bolzano 87 138 210
Clipper 126 - 85
COBOL 120, 121 123, 136, 231 253
dBASE 126 293 241, 261
Dijkstra E. 133 301 138
Fibonacci 72 90 219
FIFO 61, 62 293 53
FORTRAN 119, 120 85 8
Gates B. 122 88 157
GOTO 134 100 123, 132
HIPO 312 26 85
Hopper G.M. 121 60 74
JAVA 124 152 87
Kemeny G. 122 Fibonacci 72
67
Kurtz T. 122
236 67
LIFO 59, 62
25, 155
LISP 122, 124
315
LOGO 123 285 284
NP- 111 138 138
OCCAM 137 40 31, 153
Papert S. 123
PASCAL 123 285
238 154
PROLOG 122
4 127 282, 318
Ritchie D. 125
- 128 28
SMALTALK 235
- 118 220
SQL 129
- 119 37
VTOC 312
- 118 236
Wirth N. 55, 123
130 254
A 248 26, 155
30 75 39, 173
128 8
25 97
130, 148 8, 32, 165
286 56, 73, 185 25
69, 222 75 297
338
70
- 111
- 16 317
233
- 17 110
87
- 17 207
249
117
31, 151
137
138
111 138
127
28, 130
110
64
131 46
-
125, 238 285 308
45 31, 149
150 63
60
125 56