Вы находитесь на странице: 1из 46

..

PASCAL
ABC Pascal

7-9

2012-2013

.., ABC Pascal

ABC Pascal


F2, Ctrl-S -
F3, Ctrl-O -
F12 -
Ctrl-Shift-S -
Ctrl-Shift-0 ... Ctrl-Shift-9 - 0...9
Ctrl-0 ... Ctrl-9 - 0...9
Ctrl-Tab, Ctrl-Shift-Tab - /

.
write writeln,
.
. F5
/ .
Esc.
.
Ctrl-Del .

read readln :
- (. ).
Enter , ,
.

F9
.
, , ,
.
, , ,
" ".
Ctrl-F2

. .
,
, , .
, , ,
.
GraphABC Esc,
.


.
( ) F8
( ),
F7
( ).
F4
.
, ,
Ctrl-F2
. ,
, F9.

-2 -

01.06.2013

.., ABC Pascal



.
:
CtrlF5 .
Ins. , , ..
.
/ Ctrl-Shift-W.
Del
.

.
CtrlDel .
,
,
"" " ".


Pascal ABC :
program ;


begin

end.

.
uses,
, .
, , ,
, .
.
" ".


, , , , ,
. ,
. "_".
, a1, _h, b123 - , 1a, 2 .

. Pascal ABC :
and array as begin break case class const constructor continue destructor div
do downto else end exit external external sync file finalization for forward
function if in inherited initialization is mod not of or private procedure
program property protected public record repeat set shl shr sizeof string
then to type unit until uses var while with xor

-3 -

01.06.2013

.., ABC Pascal

1
Pascal
Program Prog1;
var a, b : integer;
begin
write(' ');
readln(a);
b:=a*a;
writeln(' = ',b);
end.
:
; , .
, :
o
o , ,
:
var

a, b, Prog1
()
a, b
(integer)
integer

write, writeln
readln

b:=a+1
( b a+1)
begin ... end

, .
- .
, (
) .
. , integer
2 147 483 648 +2 147 483 647,
, ..
,
. , b:=a+1 .
. , .
"" "+" ( ).
, .
: 1, 123, 4567, 003, +012.
.
. ,
begin ... end.

-4 -

01.06.2013

.., ABC Pascal

. :=,
. ,
.
.
: a:=2; a:=2+3; a:=b*2+1;
: a+1:=a; 2:=b+3;
a:=a+1; .
, ,
a. ,
a .
, ,
.
.
:
(read readln).
. :

. .. integer,
, .

, , , .
, ,
, , div
mod. , *
. :
, . (. )
. .
. .
1 integer

*
div
mod

a+3
cd
2*3
a div 2
a mod 2

: 5 div 2 = 2, : 5 mod 2 = 1

,
-5 -

01.06.2013

.., ABC Pascal

:
:

(a 2b)(a b)

x y
2


( ):

(a+2*b)*(ab)

(x+y) div 2

2 + (
). , 2*(ab) a
,
.
ABC Pascal

integer
byte
word


4
1
2

-2147483648 2147483647
0 .. 255
0 .. 65 535

,
. ,
a word, a:=512*128; ,
65536,
word. , a integer,
a:=512*128; .
byte word.
/
. ,
, ( ).
,
(Enter). , .
3,
. Windows-
80 , 25 4.
,
.
write writeln .
writeln (
).
, .
(, )
( .. ).
: write(' '); writeln(a,b);

.
.
4
ABC Pascal CRT.
3

-6 -

01.06.2013

.., ABC Pascal

. write writeln ,
, ,
:
writeln(' ',a:5);
, , a
5 , .. ,
. ,
, .
read, readln. read
, readln.
,

Enter. readln ,
. ,
( Enter) Enter.
, ()
. (, ),
.
: readln(a,b);
: readln(a+3);
,
readln write writeln.
:
write(' ');
readln(n);
. ,
.
Pascal
. , ()
, : x:=x-abs(x).
(, )
( ).
,
.

sqr(n)
abs(n)
pred(n)
succ(n)
odd(n)
even(n)
chr(n)
random(n)

.
.
( ) .
, .
, .
TRUE, , FALSE
TRUE, , FALSE
( char) n.
0 n-1.
-7 -

01.06.2013

.., ABC Pascal

1
1. Pascal,
.
(a+b)(ab)
(1+x)2

15 x
y
2x2y

2. ( )
(a+1)*(a), a=10
(x+1) div (x1), x=2 x=4
2*4 mod 3
2*(4 mod 3)
a*(1), a=431

3.

, ,
.
,
.
, (. abs)

4. ,
: 100 5
.
. ,

.

-8 -

01.06.2013

2 CRT

.., ABC Pascal

2
CRT
.
CRT5. ,
, , .
, 25 80 .
(, , ).
(, ..) . CRT
.
Uses:
Program Card;
Uses CRT; { Program }
, begin .

.
Program Card;
Uses CRT; { CRT }
begin
ClrScr;
{ }
TextColor(White);
{ }
TextBackGround(Blue); { }
GotoXY(36,13);
{ 36 , 13 }
write(' '); { }
ReadKey;
{ }
end.
.
:

ClrScr ( . Clear Screen),


, TextBackGround.
.
TextColor() ,
write writeln. -
.
TextBackgroud() , write writeln.
GotoXY(, ) ; ,
write writeln
. 80 25 .
ReadKey (
).

Cathode Ray Tube - ()


-9 -

01.06.2013

2 CRT

.., ABC Pascal

0 15,
CRT :

Black
Blue
Green
Cyan
Red
Magenta
Brown
LightGray

DarkGray
LightBlue
LightGreen
LightCyan
LightRed
LightMagenta
Yellow
White

-
-
-
-
-
-

Window(x1,y1,x2,y2) . ,
write writeln , ClrScr
.
WhereX, WhereY ,
. : GotoXY(WhereX+10,WhereY+2).

2:
,
: , , , , .
, .
2*:
Sounds :
n:=LoadSound(fname) fname
n (
);
PlaySound(n) n;
StopSound(n) n;
RewindSound(n) "" n ;
DestroySound(n) n ,
;
SoundLength(n) n .

sound:
Program Player;
Uses Sounds, CRT;
var n: integer;
begin
n:=LoadSound('C:\WINDOWS\MEDIA\ringin.wav'); //
PlaySound(n);
Sleep(SoundLength(n));
DestroySound(n);
end.

- 10 -

01.06.2013

3. ABC Pascal

.., ABC Pascal

3
GraphABC
ABC Pascal .
Uses GraphABC.
GraphABC , ,
. :

:
Program Gr01;
Uses GraphABC;
begin
SetWindowSize(256,256);
SetPenColor(RGB(0,0,255));
Line(0,0, WindowWidth, WindowHeight)
Line(0,WindowHeight, WindowWidth, 0)
end.
SetWindowSize 256256 .
SetPenColor . RGB ,
Red, Green, Blue . Line ,
, , .
WindowWidth WindowHeight
(,
SetWindowSize, ).

x 0 WindowWidth
y 0 WindowHeight
WindowWidth

0
0

WindowHeigth

- 11 -

01.06.2013

3. ABC Pascal

.., ABC Pascal


. ,

.
rgb(Red,Green,Blue)

Red 0 255,
Green 0 255,
Blue 0 255,
(integer),
, .
:
clBlack
clPurple
clWhite
clMaroon -
clRed
clNavy -
clGreen
clBrown
clBlue
clSkyBlue
clYellow

clCream
clAqua
clOlive
clFuchsia
clTeal -
clGray
clLime -
clLightGray -
clMoneyGreen
clDarkGray -

SetPenColor() , color.
SetPenWidth() .
SetPenStyle() (, ..),
( 1 )
psSolid
psClear

psDash
psDot

,
, , ..

psDashDot
psDashDotDot
,

:
Program Gr02;
Uses GraphABC;
Var i : integer;
begin
SetWindowSize(512,512);
SetPenStyle(psDash);
SetBrushStyle(bsClear);
Circle(256,256,WindowHeight div 2);
end.

- 12 -

01.06.2013

3. ABC Pascal

.., ABC Pascal

SetBrushColor()
SetBrushPicture( )
, ,
.
ClearBrushPicture -, .
SetBrushStyle() , bs.

:
bsSolid bsClear bsCross bsDiagCross bsHorizontal bsBDiagonal bsVertical bsFDiagonal
,
. , SetBrushColor(bsClear).
:
Program Gr03;
Uses GraphABC;
Var i,j : integer;
begin
SetWindowSize(512,512);
SetBrushColor(rgb(128,0,255));
SetBrushStyle(bsDiagCross);
Rectangle(10,10,WindowWidth-10,WindowHeight-10);
end.

Line(x1,y1,x2,y2) (x1,y1) (x2,y2).


Circle(x,y,r) (x,y) r.
Ellipse(x1,y1,x2,y2) ,
(x1,y1) (x2,y2).
Rectangle(x1,y1,x2,y2) ,
(x1,y1) (x2,y2).
RoundRect(x1,y1,x2,y2,w,h) ; (x1,y1)
(x2,y2) , w h ,
.
Arc(x,y,r,a1,a2) (x,y) r,
, a1 a2 OX (a1 a2
, ).
Pie(x,y,r,a1,a2) , (
, Arc).
Chord(x,y,r,a1,a2) , , ( , Arc).
FloodFill(x,y,color) , (x,y)
color.

:
, ,
(, , ..)

ABC Pascal,
GraphABC.
- 13 -

01.06.2013

3. ABC Pascal

.., ABC Pascal


program avto;
uses graphABC;
var i : integer;
begin
SetWindowSize (800,600);
SetPenStyle (psClear); //
setBrushColor (Clgreen);
rectangle (250,250,550,351);
setBrushColor (ClAqua);
//
rectangle (255,255,395,345);
rectangle (405,255,545,345);
setBrushColor (Clgreen); //
rectangle (50,350,750,500);
setBrushColor (ClYellow); //
rectangle (749,375,764,400);
setBrushColor (ClRed);
rectangle (35,375,51,400);
setBrushColor (ClLightGray); //
RoundRect (725,450,775,475,10,10);
RoundRect (25,450,75,475,10,10);
SetPenStyle (psSolid); //
Line(250,350,250,425);
Line(250,425,300,500);
Line (400,250,400,500);
Line (550,350,550,425);
Line (550,425,500,500);
setBrushColor (ClBlack); //
Circle (200,500,50);
setBrushColor (ClLightGray);
Circle (200,500,25);

setBrushColor (ClBlack);
Circle (600,500,50);
setBrushColor (ClLightGray);
Circle (600,500,25);
end.

- 14 -

01.06.2013

4. for

.., ABC Pascal

4
for
for .
:
for i:=N1 to N2 do ;


,

begin ... end.

for i:=N1 to N2 do
begin
1;
2;
....
end;

i
( ),
N1 , ,
N2 , ,
N2 N1,
.
:
1.
2.
3.
4.
5.
6.

N1.
i<=N2. , . 3, .6.
.
(!).
. 2.
.

:
1 10.
Program Square;
var i, j : integer;
begin
for i:=1 to 10 do
begin
j:=sqr(i);
writeln(i:4,j:4);
end;
end.

:
Program Square;
var i: integer;
begin
for i:=1 to 10 do
writeln(i:4,sqr(i):4);
end.

writeln.
,
. ,
.

- 15 -

01.06.2013

4. for

.., ABC Pascal

for downto
for ,
, . :
for i:=N2 to N1 do ;
, N2 N1.
for
for . ,
.
Program Concentric;
uses graphABC;
var i : integer; // for
begin
SetWindowSize (400,400);
SetBrushStyle (bsClear);
// 10
// 20, 40, ... 200
for i:=1 to 10 do Circle(200,200,i*20);
end.

, . :
for to, for downto?
Program Concentric2;
uses graphABC;
var i : integer; // for
begin
SetWindowSize (400,400);
SetPenStyle(psClear);
for i:=20 downto 1 do
begin
SetBrushColor (RGB(10*i,0,0));
Circle(200,200,i*10);
end;
end.

,
. random(N)
0 N1. , .
Program RandomLines;
uses graphABC;
var i : integer;
begin
SetWindowSize (400,400);
for i:=1 to 200 do
Line(Random(400),Random(400),Random(400),Random(400));
end.

5. ,
for.
- 16 -

01.06.2013

5. if

.., ABC Pascal

5
if
Pascal , .
: .

if ... then ... else ...


if ... then
case

while
repeat ... until
for

if
7 :
if then -1 else -2;
:
if x>0 then z:=1 else z:=1;
, ,
-1, -2.
. ,
begin ... end.
:
if x>0 then begin
z:=1;
x:=2*x;
end
else begin
z:=-1;
x:=-x;
end;
, else .
.
x:=2*x x:=-x, begin end
, . 8
end, end.
, , ,
.
: end begin.

7
8

.
.
- 17 -

01.06.2013

5. if

.., ABC Pascal

if ( )
, else . .
:
if x<0 then x:=-x;
, x:=-x
.
if
Program OddEven;
{ }
var n : integer;
begin
write(' '); readln(n);
if odd(n) then writeln(' ')
else writeln(' ');
end.
if
.
if .
, else.

Program Sign;
{ }
var n : integer;
begin
write(' '); readln(n);
if n>0 then writeln(' ')
else if n=0 then writeln(' ')
else writeln(' ')
end.
, if
begin ... end, if
.
if, , :
if n>0 then if n=0 then writeln(' ')
else writeln(' ')
: if else. , else
if, .. , .
, , , else,
.

- 18 -

01.06.2013

5. if

.., ABC Pascal

. if ,
boolean9.
(true) (false).
.
:
var b : boolean;
. . . . . .
b:=true;
. . . . . .
if b then writeln(' ');
,
.
. 10 ,
(, , ).
<
>
=

<=
>=
<>

.
: if a>0 then a:=1 else a:=-1. Pascal a>0
( : b:=a>0, b
).
.
AND, OR 11 NOT.
and , .
or , .
not .
if :
if (x>=0) and (x<=1) then writeln('X 0 1');
if not ((x>=0) and (x<=1)) then writeln('X 0-1');
if (x<0) or (x>1) then writeln('X 0-1');

. ,
. and
, or , not (.. ).

. .
, .
11
.
10

- 19 -

01.06.2013

5. if

.., ABC Pascal

5
1. :
not true and not false
not true or not false
not (true or false)
Y
not (true and false)

2. a
,

x, y.

3. ,
, 3, 4 5
, 1 2.
4. , , ,
, 2, 3, 4 5 .
5. (mod, . 5),
Concentric (. 16), 3-
, .


,
. . .
1 10.
Program Table;
var i,j : integer;
begin
for i:=1 to 10 do
begin
for j:=1 to 10 do write(i*j:4);

writeln
end
end.

1
2
3
4
5
6
7
8
9
10

2
4
6
8
10
12
14
16
18
20

3
6
9
12
15
18
21
24
27
30

4
8
12
16
20
24
28
32
36
40

5
10
15
20
25
30
35
40
45
50

6
12
18
24
30
36
42
48
54
60

7
14
21
28
35
42
49
56
63
70

8
16
24
32
40
48
56
64
72
80

9 10
18 20
27 30
36 40
45 50
54 60
63 70
72 80
81 90
90 100

i,
j, write ( writeln!) i*j,
4 . writeln,
. 10 , ,
, 10 , .

- 20 -

01.06.2013

6. case

.., ABC Pascal

case
case 2 .
.
Program YourMark;
{ }
var n : integer;
begin
write(' '); readln(n);
case n of
2 : writeln('');
3 : writeln('');
4 : writeln('');
5 : writeln('');
end;
end.
, case end.
, 2-5,
. , , .
case :
Program YourMark2;
{ }
var n : integer;
begin
write(' '); readln(n);
case n of
2 : writeln('');
3 : writeln('');
4 : writeln('');
5 : writeln('')
else writeln(' !')
end;
end.
else else.
n .
Program YourMark3;
{ }
var n : integer;
begin
write(' '); readln(n);
case n of
2..3 : writeln(' !');
4
: writeln('!');
5..6 : writeln(' !')
else
writeln(' !')
end;
end.
else else.
- 21 -

01.06.2013

6. case

.., ABC Pascal

6.1. , ,
: 1 10
(, , ).
(2 )

6.2. ,
1 99 ( !).
1.
. .., n ,
d:=n mod 10;
2. : 1 9, 10 19, 20
99.
(5 )
6.3. , ,
999.
( 3 )

6.4*. 6.3 ( ),
1 999, .
( 4 )
:
1I
2 II
3 III
4 IV
5V
6 VI
7 VII
8 VIII
9 IX

10 X
20 XX
30 XXX
40 XL
50 L
60 LX
70 LXX
80 LXXX
90 XC

100 C
200 CC
300 CCC
400 CD
500 D
600 DC
700 DCC
800 DCCC
900 CM

.
:
23 XXIII

357 CCCLVII

888 DCCCLXXXVIII

- 22 -

901 CMI

109 CIX

01.06.2013

7
While Repeat Until
for, ,
. Pascal
, ,
, .
While ( )
, ,
.
:
while do ;

while do
begin
1;
2;
....
end;
,
, ,
. ,
. ,
. , .
repeat until while. :
repeat
1;
2;
....
until ;
, , , begin end
. .
, , , ,
, . ,
. ,
.
1 10 while repeat until.
Program SquareW;
var i : integer;
begin
i:=1
while i<=10 do
begin
writeln(i:4,sqr(i):4);
i:=i+1;
end;
end.

Program SquareR;
var i : integer;
begin
i:=1
repeat
writeln(i:4,sqr(i):4);
i:=i+1;
until i>10;
end.
- 23 -

01.06.2013

7. while repeat until

.., ABC Pascal

.
. 400 ,
, .. 200, 100, 50,
1 .
while repeat until,
(, ,
).
Program Circles;
Uses GraphABC;
var r : integer;
begin
SetWindowSize(800,800);
r:=400;
repeat
circle(400,400,r);
r:=r div 2;
until r<1;
end.

Program Circles;
Uses GraphABC;
var r : integer;
begin
SetWindowSize(800,800);
r:=400;
while (r>=1) do
begin
circle(400,400,r);
r:=r div 2;
end;
end.

.
( 10 )
, .
Program Circles;
Uses GraphABC, CRT;
var r : integer;
begin
SetWindowSize(500,500);
repeat
SetBrushColor(random($FFFFFF));
circle(random(500),random(500),random(10));
delay(10);
until keypressed;
end.

. -, keypressed,
CRT. true,
. SetBrushColor
random($FFFFFF). random
,
, 0
( ) $FFFFFF ( ).
HTML. delay(n)
n .
, .
7.
1. , ,
0. (5 )
2. , ,
.

- 24 -

01.06.2013

8.

.., ABC Pascal

8
Pascal
.
, , .
( ).
. Pascal
real, .
:
Program Krug;
Uses CRT;
//
var r
: real; //
s
: real; //
begin
write(' : '); readln(r);
s:=2*3.1415926*r;
writeln(' : ',s:8:2);
end.

( real). ,
(r, s : real),
, .
.
, , .
+, , *, /.
, , .. 5/2 2.5. (div),
(mod) !
.
. :
3.5, 2.0,

+36.6,

40.123.

,
, . .
(
6.67 1021 ). Pascal 6.67E21, ..
10 Pascal E ( , ).
:
3E1,

2e+10,

+1.234E10,

65.2e+20.

E , E
.
8 ( 1)
1. Pascal :
2.99 1033 , 0.2110 10 , 35.6 108 , 1200000, 0.000015
(5 )
2. Pascal :
2.71828, 1.25 102 , 1.5 101
(3 )
- 25 -

01.06.2013

8.

.., ABC Pascal

write/writeln
. ,
. ,
(. ). ,
, .
, ,
,
. 10,

. , Pascal
.
:
Program Formats;
Uses CRT;
var x
: real;
begin
x:=1234.567;
writeln(x);
writeln(x:8:3);
writeln(x:8:2);
writeln(x:8:1);
writeln(x:12);
writeln(x:14);
end.

,
0.1 1 0.1 (, pi):
Program Table;
Uses CRT;
var r, s : real;
begin
r:=0.1;
//
repeat
s:=2*pi*r;
//
writeln(r:3:1,s:6:2); //
r:=r+0.1;
// 0.1
until r>1.0;
//
end.

8 ( 2)
3. ,
( s r 2 ). (2 )
4. ,
, . (3 )
5. , 10
. (5 )
6. * , ,
.

- 26 -

01.06.2013

9. -

.., ABC Pascal

9
Pascal


. Pascal
. : .
. ,
, . ,
.
.
.
Program Table;
Uses CRT; //
// ,
function cube(x:real):real; //
begin
cube:=x*x*x; //
end;
function sign(x:real):integer; //
begin
if x>0 then sign:=1
else if x=0 then sign:=0
else sign:=-1;
end;
//

==== ==========

var
a : real;
//
const a1 = -5.0;
// ()
a2 = +5.0;
st = 0.5;
begin
a:=a1;
while (a<=a2) do
begin
writeln(a:4:1,cube(a):10:3,sign(a):3); //
a:=a+st;
end;
end.

, ( begin
end) .
, , .
( ).
. , ,
.

- 27 -

01.06.2013

9. -

.., ABC Pascal

, .
Program Power2;
Uses CRT;
function power(x : real; n : integer) : real; //
var i : integer; //
r : real;
begin
r:=1.0;
for i:=1 to n do r:=r*x; //
power:=r;
//
end;
//

==== ================

var
i : integer;
//
begin
for i:=1 to 10 do
writeln(i:2,power(2.0,i):6:0);
end.

( real integer),
.
. i , i
.
. .
9
1. , power
, .
x n

1
. : if, abs(n),
xn

.
(5 )
2. , n ! 1 2 3 n . :
, power.
(5-8 )

- 28 -

01.06.2013

10. -

.., ABC Pascal

10
Pascal

- ( )
-. , .
.
, .
.
Program UseProc;
Uses GraphABC;
Procedure Triangle(x1,y1,x2,y2,x3,y3:integer);
//
begin
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
end;
//
begin
SetWindowSize(500,500);
Triangle(100,200,400,300,250,150);
Triangle(10,20,30,40,50,10);
end.

, Trianlge
Line . ,
, .
10
1. ,
(, , ..)
( 3-4 )

- 29 -

01.06.2013

10. -

.., ABC Pascal

(Units)
, , , ,
( , ) .
. , .
Triangle MyGraph.
Unit MyGraph;

// .
// ! ..
// MyGraph.pas, !

Uses GraphABC;

//

Procedure Triangle(x1,y1,x2,y2,x3,y3:integer);
// MyGraph
begin
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
end;
end. // .

:
Program UseProc;
Uses GraphABC, MyGraph; //
begin
SetWindowSize(500,500);
// GraphABC
Triangle(100,200,400,300,250,150); // MyGraph
Triangle(10,20,30,40,50,10);
end.

, ,
, ( ).
10
2.
(5 )

- 30 -

01.06.2013

11.

.., ABC Pascal

11

- -
- ?
-,
. ,
?
,
( L 2r ) ( S r 2 ) .

Program ProcUse;
Uses CRT;
//
Procedure Pr(R,L,S:real);
begin
L:=2*PI*R;
S:=PI*sqr(R);
end;

//
var rad, len, area : real;
begin
write(' '); readln(rad);
Pr(rad, len, area);
writeln(' ', len);
writeln('
', area);
end.

. :
, :
0! ?
,
.
. ,
( ),
, .
.. , ..
, .
, ,
.

- 31 -

01.06.2013

11.

.., ABC Pascal

.
Pr :
Procedure Pr(R: real; var L,S:real);
var. ,
.
(
). ,
, ,
, ! .. Pr(5,6,7) , ,
Pr(5,a,b), a b . ,
, , .
. !

11

1. ,
. .
(3 )

2. , Pr,
r r.
(2 )

- 32 -

01.06.2013

12.

.., ABC Pascal

12


,
, : , ,
, , ..
.
,
.
.
:
A1

A2

A3

A4

A5

A6

A7

A8

(, ):
A11

A12 A13 A14

A21

A22 A23 A24

A31

A32 A33 A34

, ,
, .
,
:
A : array [1..8] of integer;
array , ,
.
Pascal
, A..H, 0..7.
, ()
.

, ,
. A
:
Const N = 8;
Var A : array [1..N] of integer;
,
, , ,
,
!

- 33 -

01.06.2013

12.

.., ABC Pascal

, ,
,
-.
Const N = 8;
Type TA = array [1..N] of integer;
Var
A : TA;
, ,
TA, ,
A B , , . ,
Const N
Type TA
Var A :
Var B :

= 8;
= array [1..N] of integer;
TA;
TA;

A B . :
Const N = 8;
Var A : array [1..N] of integer;
Var B : array [1..N] of integer;
A B .
:
Const N = 8;
Var A,B : array [1..N] of integer;
, , ..
:
Const M = 5;
N = 8;
Var
A : array [1..M] of array [1..N] of integer;
,
:
Const M = 5;
N = 8;
Var
A : array [1..M,1..N] of integer;
, ,
.


.
:
{ }
for i:=1 to N do A[i]:=0;
,
,
, .
, .
- 34 -

01.06.2013

12.

.., ABC Pascal

for .
for i:=1 to N do
.
,
:
B:=A;
, -
:
{ }
for i:=1 to N do
begin
write('e ',i,'- : '); readln(A[i])
end;
, ,
. :
{ }
for i:=1 to N do writeln('A[',i,']=',A[i]);

. :
, ;
, ,
, , .
, , ,
:
{ }
max:=A[1];
for i:=2 to N do if A[i]>max then max:=A[i];
writeln('Maximum=',max);
, :
Program Massiv;
Const N = 10;
Var A : array [1..N] of integer;
i, max : integer;
begin
for i:=1 to N do //
begin
write('e ',i,'- : ');
end;

readln(A[i])

max:=A[1]; //
for i:=2 to N do if A[i]>max then max:=A[i];
writeln('Maximum=',max);
end.
- 35 -

01.06.2013

12.

.., ABC Pascal

12

1. . .
(2 )

2. , ,
10 , .
(2 )
3. ,
( for i:=N downto 1 do) .
(1 )
4. . 35 ,
.
(2 )
5.

.
(1 )
6. * ,
(, real)
(* 3 )

7. * ,
, N ,
.
(* 3 )
, *, .

- 36 -

01.06.2013

13.

.., ABC Pascal

13


,
.
( )
(.. ).
. . 13.1.
,
( 4 2) ,
,
(. 13.2). , ,
(. 13.4).

13.1

13.2

13.3

13.4

(.
13.5) , (. 13.6-13.7).
1

13.5

13.6

13.6

13.7

, ,
N2
(
).
2

- 37 -

01.06.2013

13.

.., ABC Pascal

. ,
. Massiv (. 34).
var- (. 32),
. .. print
: procedure print(var m : Massiv); .
Program LinerSort;
Const N = 10; //
Type

Massiv = array [1..N] of integer; // Massiv

procedure swap(var x,y: integer); //


var z : integer;
begin
z:=x; x:=y; y:=z;
end;
procedure print(m : Massiv); //
var i : integer;
begin
for i:=1 to N do write(m[i]:5);
writeln; //
end;

//
Var
a : Massiv;
i,j : integer;
begin
// 0 99
for i:=1 to N do a[i]:=random(100);
print(a); //
for i:=1 to N-1 do // N-1
( !)
for j:=i+1 to N do // i+1 ( !)
if (a[i]>a[j]) then swap(a[i],a[j]); //
print(a); //
end.

13
1. .
( var- ).
(2 )
2. ,
.
N=10, 100, 1000.
(3)

- 38 -

01.06.2013

14

.., ABC Pascal

14

,
. Pascal
.
ABC Pascal : .

, .., , integer ,
4 .
, . /
.
record.

/.
(. 15 . 26).
. , ,


(notepad, aditor, ABC Pascal, [ Word12]). ABC
Pascal Win-1251, .
( )
ABC Pascal.
10
table.txt.
Program TextOut;
const name = 'text.txt'; //
var f : text;
n : integer;

//
// for

begin
assign(f,name); //
rewrite(f);
//
for n:=1 to 10 do writeln(f,n:2,sqr(n):4); // writeln(f,...);
close(f); // ,
end.

:
1. f : text ;
2. assign(f,name) f name ;
3. rewrite(f) f, .. ,
( )
;
4. writeln(f,) writeln,
,
5. close(f) , ,
( ), .
12

MS Word *.txt ,
, Win-1251.
- 39 -

01.06.2013

14

.., ABC Pascal

rewrite, append,

.13
,
text.txt.
Program TextIn;
Uses CRT;
const name = 'text.txt'; //
var f : text;
a,b : integer;
begin
assign(f,name); //
reset(f);
//
repeat
readln(f,a,b);
writeln(a:5,b:5);
until Eof(f);
close(f);
end.

//
//



//
//
//
//


CRT
eof true

:
1. reset(f) , ,
;
2. readln(f,) ,
read(f,) readln(f,) ,
,
. readln
,
;
3. eof(f) ,
: . ,
,
,
SeekEof(f) eof, true,
: , 14.
14
1. , mult.txt.
for (. 20).

(3)
2. , 14.1
(2 )

13

ABC Pascal FileExists(name), , ,


CanCreateFile(name), .
14
ABC Pascal Eoln SeekEoln,
.
- 40 -

01.06.2013

15

.., ABC Pascal

15

Pascal
. char
256 . char
.
readln,
Enter . CRT
ReadKey,
.

:
var c : char;

c:='a';
readln(c);
c:=ReadKey;

Pascal
: ord chr. (
) , ord('A') 65.
, , , .. chr(65) 'A'.
, 3215
255. if 32
. .
Program ANSI;
Uses CRT;
var c : char;
i : integer;
begin
for i:=32 to 255 do
begin
write(Chr(i));
if (i+1) mod 32 = 0 then writeln;
end;
end.

Turbo Pascal string,


, . string
ABC Pascal.
Pascal ABC string 255 .

var s: string;

s 256 , .

var s1: string[40];

41 ( ).
s1 40
, s1 40.
() s1+s1
string, .. 256 .
255 , .
, .
, : s[i] i-
. s[0] .
15

0 31 ANSI .
- 41 -

01.06.2013

15

.., ABC Pascal


Length(s). ,
SetLength(s,n). i , ,

. i
, .
char string ,
.
, .
Program Strings; // a b s
function replace(s : string; a,b : char):string;
var i : integer;
begin
for i:=1 to Length(s) do //
if s[i]=a then s[i]:=b; //
replace:=s;
//
end;
begin
writeln(replace(' ','','')); //
end.

char string , :
Program ReadText;
Uses CRT;
var name : string; //
s
: string; //
f
: text;
//
n
: integer; //
begin
write(' : '); readln(name); //
assign(f,name); reset(f); //
n:=0;
//
while not eof(f) do
//
begin
readln(f,s);
// f
writeln(n:4,': ',s);
//
inc(n);
// inc(n)
if n mod 25 = 0 then readln; // 25-
end;
close(f);
end.

15
1. ReadKey Ord ,
.
(2 )
2. ,
, , ,
, .
(2 )
3. , ,
, ( )
(3 )
- 42 -

01.06.2013

15

.., ABC Pascal

Pascal ,
ABC Pascal. .

Length(s)
s - string
Copy(s,index,count) s - string,
index
count integer
Delete(s,index,count) s - string,
index
count integer
Insert(subs,s,index) s, subs string,
index integer
Pos(subs,s)
s, subs string

SetLength(s,n)
Str(x,s)
Str(x:n,s)
Str(x:n:m,s)

integer
string

s
s
count, index
s count
index
subs s
index

integer

s - string, n
- integer
s - string, x
- integer,
real n, m integer

Val(s,v,code)

s - string, v
- integer,
real, code
- integer

Concat(s1,...,sn)

s1,..., sn string

string

UpCase(c)

c - char

char

LowCase(c)

c - char

char

UpperCase(s)

s - string

string

LowerCase(s)

s - string

string

Trim(s)

s - string

string

- 43 -


subs s ( 0
)
s
n
x
(
,
n m)
s
s

v.
, code
0, ,
code

,
s1,..., sn.
,
s1+s2+...+sn
c,

c,

s,

s,

s

01.06.2013

16

.., ABC Pascal

16

Pascal .
.
;
. :
set of ;

,
Ord 0 255. ,
, char byte ( ).16
type, :
type
ByteSet = set of byte;
CharSet = set of char;
Digits = set of '0'..'9'; // char
(
), :
var Vowels : CharSet;
Good
: Digits;

// vowels : set of char;


// good : set of '0'..'9';

Vowels:=['A', 'E', 'O', 'I', 'U']; //


Good:=['3'.. '5', '10'];
//

in:
var c : char;

if c in Vowels then inc(n); // , n 1

,
, .
: Sound, ,
, char, Sleep,
Upcase, .
16
1. ABCMorse, .
2. , , ,
, , .
(3 )
3. , 10
, .
13, < >.
(5 )
4. ABCMorse
.
(. )

16

( ).
- 44 -

01.06.2013

16

.., ABC Pascal

morse.txt

Program ABCMorze;
Uses Sounds,CRT;
var A : array [''..''] of string[5];
c : char;
f : text;
s : string;
i,j : integer;
dash, dot : integer;
morze : string[5];
begin
// A[''], A[''] ,... A['']
assign(f,'morze.txt'); reset(f);
for c:='' to '' do readln(f,A[c]);
close(f);
//
for c:='' to '' do write(c,' ',A[c]:5,' ');
//
dash:=LoadSound('dash.wav'); dot:=LoadSound('dot.wav');
//
writeln; write(' '); readln(s);
for i:=1 to length(s) do //
if Upcase(s[i]) in [''..''] then //
begin // ( Upcase)

-
---
-

--

----
--
----
-

--
---
------------
---

morze:=A[Upcase(s[i])]; // s[i] A morze


for j:=1 to Length(morze) do // Morze
begin
write(morze[j]); //
if morze[j]='-' then
begin
PlaySound(dash); Sleep(SoundLength(dash)); // dash
end
else
begin
PlaySound(dot); Sleep(SoundLength(dot)); // dot
end;
Sleep(50);
end;
write(' '); Sleep(500); // 500
end; // end if
end.

- 45 -

01.06.2013

17

.., ABC Pascal

17

7 ,
.
d 0

ax 2 bx c 0
:

d b 2 4ac

1. d 0 17;
b
2. d 0 ,
;
2a
3. d 0 ,

x1,2

b d
, +
2a

, .
:
Program SquareEquation;
var a, b, c : real; //
d : real; //
x1, x2 : real; //
begin
write(' a, b, c '); readln(a,b,c); //
d:=b*b-4*a*c; //
if d<0 then writeln(' ')
else if d=0 then begin
x1:=-b/(2*a);
write('x=',x1)
end
else begin
x1:=(-b+sqrt(d))/(2*a);
x2:=(-b-sqrt(d))/(2*a);
write('x1=',x1,' x2=',x2)
end
end.
else , (
)
else begin
d:=sqrt(d); a:=2*a;
x1:=(-b+d)/a;
x2:=(-b-d)/a;
write('x1=',x1,' x2=',x2)
end

17


- 46 -

01.06.2013

Вам также может понравиться