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

| |

1.
1.1
.
1.2
.
Str Val.

2. c

3.


1.

1.1

Char.
, 256
. :

) , , A,
() A;

) , , ,
Enter () ,
:

#____ASCII

: #13 , #65 .


. ( )
.

UpCase ( ch : Char ) : Char .


, .

program dialog;
var ch : Char;
begin
repeat { }
{ }
...
...
repeat {, }
write(? (Y/N)); { }
readln(ch); { }
ch := UpCase(ch); {: y->Y}
until (ch = Y) or (Ch = N);
{ , }
until ch = N;
{ , N}
end.

1.2.

( 255)
String[n], n . , String ,
, 255 . ,
,
.
. ,

var name : String[20];


: name := !, 7,
20 . , name
20 , , , .. 21 .
( ) , name
.

,
.

:
const
sc = F1 ; { }
var
sv : string; { }
begin
sv := !; { }
write(sv, , sc)
{ , }
end.

,
() .
+ , , ,
.

var
PathString,
FileName,
FileExtention,
CompleteName : string;
begin
PathString := c:\MyDirectory;
FileNmae := prog7;
FileExtention := pas;
CompleteName := PathString + \ + FileName + . + FileExtention;
write(CompleteName)
end.

CompleteName : c:\MyDirectory\prog7.pas.

, Char,
, . :
s := Computer, s[1] C, s[2] o, s[3] m ..

, .
Length (
. ).

program VertPrint;
var
s : string; { }
i, n : Integer; { }
begin
s := Hello Word!; { }
n := Length(s); { }
for i := 1 to n do Writeln( s[i] ); {
}
end.

H
e
l
l
o

W
o
r
d
!

Length( s : string ) : Integer () .


, .
:

ord( S[0] ), S .
Concat( s1, s2, s3, : string ) : string ,
s1, s2 .. +.

Copy( s : string; fs, ln : Integer ) : string ( s),


ln , fs. :

FileName := prog7.pas;

Extention := Copy( FileName, 6, 3)

Extention pas.

Delete( var s : string; fs, ln : integer ) s , ln ,


fs.

Insert( s1 : string; var s2 : string; fs : integer ) s2,


s1, fs.

Pos( subS, S : string ) : integer S S


S, subS.
, 0.

Pos Delete
, .

program Delete_extra_spaces;
var
s : string;
begin
s := , !;
while Pos( , s)<>0 do Delete( s, Pos( , s), 1);
write(s)
end.

Pos , ??. while


. , Pos
, .
, Pos .

Str Val.

Str( value; var s : string ) value s.


value ,
write.

var
a, b : integer;
s1, s2 : string;
begin
a := 5; b := 12;
Str( a, s1 );
Str( b, s2 );
writeln( a+b: , a+b);
writeln( s1+s2: , s1+s2);
end.

:
a+b: 17

s1+s2: 512

Val( s : string; var value; errcd : integer ) s, ,


value. .
, errcd 0, (
), errcd s,
.

var
s1, s2 : string;
x : real;
ec : integer;
begin
s1 := 123.45;
s2 := 123,45;
Val( s1, x, ec );
writeln (ec, , x);
Val( s2, x, ec );
writeln (ec, , x);
end.

0 1.2345000000+02
4 0.0000000000+00

s 1 ,
ec 0, x 123.45. s2
,
, ,
, .
ec 4 s2
, x .

2. c

(.. ) ,
, .
, .
(, , /) ( )
.

) ASCII;

) .
#10 #13;

) #26;

) , ( );

) .

() ,
:

[20][20],[10][13]
[20][20][10][13]
:[10][13]
[10][13]
[20][20]123[20][20]15.0[10][13]
[20][20]131[20][20]16.4[10][13]
[20][20]162[20][20]19.2[10][13]
[20][20]185[20][20]23.6[10][13]
[20][20]193[20][20]40.8[10][13]
[10][13]
[20][10][13]
[26]

ASCII , : [10]
, [13] , [20] , [26] .

,

:

123 15.0
131 16.4
162 19.2
185 23.6
193 40.8

.
:

var
f : Text;

f , Text .

:
Assign( f, c:\work\test.txt );

c:\work\test.txt , ( ) .
, , .

.
:

ReWrite(f) .

, f
Assign. .
, , .. .
ReWrite .

ReSet(f) /.

,
. /.

Append(f) .

,
. /.

Read( f, _ )

Readln( f, _ )

Write( f, _ )

Writeln( f, _ )

f .

, .
: , ,
. Readln Read , Readln
,
( ).

, ,
. : , ,
, .
TRUE FALSE. Writeln
#10 #13, ,
.

, ,
Close(f).


Read Readln. C: WORK test.dat
:
0.45 12.5 678.89
0.47 13.1 791.45
0.49 15.2 871.21
0.52 17.7 936.52

program ReadDataFile;
var
f : text; { }
a, b, c : real;
begin
Assign( f, 'c:\work\test.dat');{
f c
c:\work\test.dat }
Reset( f ); { }
{1} Read( f, a ); { }
{2} Read( f, b ); { }
{3} Read( f, c ); { }
Writeln( a:7:2, b:7:2, c:7:2 ); { }
{4} Read( f, a, b, c ); { 1-, 2- 3-
}
Writeln( a:7:2, b:7:2, c:7:2 ); { }
{5} Readln( f, a ); { }
{6} Read( f, b ); { ! }
{7} Read( f, c ); { }
Writeln( a:7:2, b:7:2, c:7:2 ); { }
Close( f ); { }
end.

, , .
Read ,
a, b c, . ,
. ,
, .
Read 4 .
Read ( 1, 2 3).
Readln, ,
a .
! Read 6- 7-
, , .
:

0.45 12.50 678.89


0.47 13.10 791.45
0.49 0.52 17.70

Readln.

3.

:
tab.dat, ;
tab.dat,
.

I.

1. , .
-.
2. .
, .

,
. , .

II.

1. .
2. .
3.
4. .
5. .

III.
program WriteTabData;
var
f : text;
x, xmin, xmax, dx : real;

function y( x : real ) : real;


begin
y := ...;
end;

begin
Writeln( Xmin, Xmax dx:);
Readln(xmin, xmax, dx);
Assign( f, tab.dat );
Rewrite( f );
Writeln( f, ... );
x := xmin;
while x<=xmax do begin
Writeln( f, x, , y(x) );
x := x + dx
end;
Close( f );
end.

I.

, -
. .

,
. ,
, ,
. ,
, ,
,
.

II.

1. .
2. -.
3. ,
. .
4. .

3- .
EOF( f ),
TRUE, , f, FALSE
.

III.
program ReadTabData;
const
nmax = 1000;
var
f : text;
x, y : array[1..nmax] of real;
title : string;
i : integer;
begin
Assign( f, tab.dat );
Reset( f );
Readln( f, title );
Writeln( title );
i := 1;
while (not EOF(f))and(i<=nmax) do begin
Readln( f, x[i], y[i] );
Writeln( x[i], y[i] );
i := i+1;
end;
Close( f );
end.

.
, , . ,
, .

I.

: ,
, .

, .

II.

1.
2.
3. , .
, .

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

III.

PROGRAM Words;
USES Crt;
VAR
s, w : string;
n, l, r : integer;
BEGIN
ClrScr;
Writeln(' : ');
Readln(s);
n := Length(s); { }
l := 1;
r := 1;
WHILE r<=n DO BEGIN
WHILE (s[l]=' ') and (l<=n) DO l:=l+1; { }
r := l;
WHILE (s[r+1]<>' ') and (r+1<=n) DO r:=r+1; { }
w := copy(s,l,r-l+1); { }
l := r+1;
IF w[1] = 'a' THEN Writeln(w); { }
END ;
ReadKey;
END.

, Length . l r,
, 1.
while. ,
, .
l .
, .
r . s Copy
l (r-1+1).
, , .

, ,
,. 256 .

I.

: ,
.
.
.

, .

II.
1.
2. ,
. ,
.
3.

.
, , .
.
, ,
, . .
,
1 0 13, .
, .

III.

program sentences;
uses crt;
var
f : text;
c : char;
w,s : string;

function IsComma( s : string ) : boolean;


var i : integer;
begin
IsComma := FALSE;
for i:=1 to Length(s) do
if s[i]=',' then IsComma := TRUE;
end;

begin
clrscr;
assign(f,'text.txt');
reset(f);
while not eof(f) do begin
s := '';
repeat
read(f,c);
until not (c in [' ',#13,#10]) or eof(f);
s := s + c;
while not (c in ['.','?','!']) and not eof(f) do begin
read(f,c);
if (c<>#10) and (c<>#13) then s := s + c;
end;
if not IsComma(s) then writeln(s);
end;
close(f);
readkey;
end.

( reset) ,
.
s. (repeat)
, , ,
. s.
(while) s,
. , ,
.
IsComma, true,
, false . ,
, .
.

| |