End.
For...to :
for d:=Low(week) to High(week) do writeln(d);
For...in (array).
9. , 8, :
var a: array[1..7] of string
=(monday,tuesday,wednesday,thursday,friday,
saturday,sunday); s: String;
begin
For s in a do writeln(s)
End.
For...in (set). .
10. , 8, :
var week:set of TWeekDay= [monday,tuesday,wednesday,thursday,friday];
d: TWeekday;
begin
For d in week do writeln(d)
End.
11. , :
1) M , 0 20, : M0 ={ 5 15}, M2 ={ 0 20}, M3 ={ 0 20, 3},
2) ) Ms1:=(M2+M3)-M0, ) Ms2:=M2*M3, ) Ms3:=M0-M3, For...in.
:
type M = Set of 0..20; { }
var element:byte; { element }
M0,M2,M3,Ms1,Ms2,Ms3:M; { M0,M2,M3 Ms1,Ms2,Ms3 }
Begin
M0:=[5,6,7,8,9,10,11,12,13,14,15]; { M0,M2,M3 }
M2:=[0,2,4,6,8,10,12,14,16,18,20];
M3:=[0,3,6,9,12,15,18];
Ms1:=(M2+M3)-M0; { Ms1 }
Ms2:=M2*M3; { Ms2 }
Ms3:=M0-M3; { Ms3 }
writeln; write( SET Ms1: ); { Ms1 }
for element in Ms1 do write(element, );
writeln; write( SET Ms2: ); { Ms2 }
for element in Ms2 do write(element, );
writeln;write( SET Ms3: ); { Ms3 }
for element in Ms3 do write(element, );
End.
.
1. , , ?
2. .
3. ?
4. ?
5. , ?
6. , ?
|
|
7. :
) ['a','c','e'] ['b','e']; ) ['','e','g'] ['b','c','d','e']; ) ['a','b','c'] [0,1]; ) [1,3,5] [2,3,4,5,6]?
8. :
) ['a','c','e'] ['b','e']; ) ['','e','g'] ['b','c','d','e']; ) ['a','b','c'] [0,1]; ) [1,3,5] [2,3,4,5,6]?
9. :
) ['a','c','e'] ['b','e']; ) ['','e','g'] ['b','c','d','e']; ) ['a','b','c'] [0,1]; ) [1,3,5] [2,3,4,5,6]?
10. For...in?
11. For...in?
12. For...in char?
.
1. , :
1) [0..10] , ,
2) ,
3) , ) ,,, ) , .
, , , , . , ( ), . .
, - . ( ), . , : , , , , . , , - . , .
, :
1) record
2) .
record :
Type
= record end;
record, end - ,
- ,
, ; ( end ).
( ), record:
Var
: record end;
, , , .
1. Pers_Data , : 1) , 2) , 3) , 4) , 5) . P_Data.
. 1)-5) fam;adr;tel;e_mail;salary. 4 . , 20,40,15,20. 5) :
|
|
type Pers_Data=record
fam:string[20]; adr:string[40]; tel:string[15];
e_mail:string[20]; salary:real
End;
var P_Data: Pers_Data;
2. P_Data, , 1.
:
var P_Data: record fam:string[20]; adr:string[40]; tel:string[15];
e_mail:string[20]; salary:real
End;
, . . , , .
3. fam, tel salary - P_Data 2 :
P_Data. fam:=' ..';
P_Data. tel:='85662223322';
P_Data. salary:=36500.00;
, .
( ) with. :
with do ;
( ), , .
4. 3:
With P_Data do begin
fam:= ' ..';
tel:='85662223322';
salary:=36500.00
End;
() .
5. , Pers_Data, 1, Andreev :
Const
Andreev: Pers_Data=(fam:' ..';
adr:'105141,Moscow,Krasnaya Presnya street,37-125';
tel:='85662223322';
e_mail:'[email protected]'
salary:=36500.00);
record. , , - -.
6. , woker_ALPHA Pers_Data, 1. :
1) ( ) woker_firm:
type woker_firm: array [1..30] of Pers_Data;
var woker_ALPHA: woker_firm;
2) - woker_ALPHA:
var woker_ALPHA: array [1..30] of Pers_Data;
, ( ), (.- fixed records). ( .- records with variant parts ), case, . , , , . , . , .
, :
case [ :] of:
, , . , .
|
|
. , .
, . c , . .
, , .
7. , , , , :
Type
TVarRec = record { }
ch: char;
case byte of { }
1: (i: integer); { i integer }
2: (d: double); { d double }
end; { }
var Rec: TVarRec; { Rec TVarRec }
begin { }
Rec.ch:='A'; { ch }
Rec.i:= 5; { i }
writeln(' Field values 1: Rec.ch=',Rec.ch,' Rec.i=',Rec.i); { }
Rec.d:= Rec.d + 1.2345; { d }
writeln(' Field values 2: Rec.ch=',Rec.ch,' Rec.i=',Rec.i,' Rec.d =',Rec.d);
End.
:
i d , d i.
8. :
) TCircle, ,
) Circle_1, Circle_2 .,
) Circle_1 , , , ,
) Circle_2 , with, , .
. , , , , TCircle .
TCircle , . :
1) (xc,yc) r,
2) (xc,yc) d,
3) (x1,y1),(x2,y2),(x3,y3), , .
TCircle , :
type TCircle = record
color: byte; { }
width: real; { }
case g: byte of { }
1:(xc,yc,r: real); { (xc,yc) r }
2:(xc1,yc1,d: real); { (xc,yc) d }
3:(x1,y1,x2,y2,x3,y3:real); {. , } end;
var Circle_1,Circle_2: TCircle; { Circle_1,Circle_2 }
|
|
begin { }
Circle_1.color:=15; { Circle_1 }
Circle_1.width:=0.5; Circle_1.g:=2;
Circle_1.xc1:=20.5; Circle_1.yc1:=33.8; Circle_1.d:=10.0;
writeln(' Circle_1: color=',Circle_1.color, { Circle_1 }
' width',Circle_1.width:8,' variant geom=',Circle_1.g);
writeln(' xc1=',Circle_1.xc1:8,' yc1',Circle_1.yc1:8,' d=',Circle_1.d:8);
with Circle_2 do { Circle_2 with }
Begin
color:=12; width:=1.5; g:=3;
x1:=20.5; y1:=33.8; x2:=20.5; y2:=33.8; x3:=20.5; y3:=33.8;
writeln(' Circle_2: color=',color,' width',width:8,' variant geom=',g);
writeln(' x1=',x1:8,' y1',y1:8,' x2=',x2:8,' y2',y2:8,' x3=',x3:8, 'y3',y3:8);
End;
End.
, .
.
1. ?
2. ?
2. ?
3. ?
4. ?
5. ?
6. ?
7. ?
.
1. :
) TRectangle, , , , ,
) Rect_1, Rect_2 ,
) Rect_1 , , ,
) Rect_2 , with, .
() , , -, (, -) (, ). .
. , . , , , ( ) .. , :
'F1.dat' { }
'c:\ \book1.doc' { MS DOS}
'file2' { , }
, , , .
. . , , . .. , . , . , , .
, , . . .
, , ( ), .. .
9.5.1.
|
|
3 :
1. (, , ). :
= file of ;
2. , . :
= text;
, . EoLN, ( ) EoF. , . .
3. . :
= file;
, . , .
1. :
Type
string_12= String [12] { 12 }
string_25= String [25] { 25 }
string_150= String [150] { 150 }
P_data = record { - }
name: string_150;
adr: string_150;
tel: string_12;
End;
Data_Str = file of string_25; { string_25 }
Var
f_char: file of char; { a -}
f_int: file of integer; { a }
file_dif: file; { a}
f_chapter: text; { a}
f_P_Dat: file of P_data; { a P_data }
fD: Data_Str; { fD Data_Str }
f_str12: file of string_12; { a string_12 }
9.5.2. .
, . , , 0 1. 0 1. .
, , ( ), . :
1) ,
2) ,
3) ,
4) .
, . f_log ( ), , , F_f ( ), ssign:
ssign(f_log, F_f);
F_f , . . .
ssign , . - . MS DOS :
1) CON (), , - ,
2) PRN, LPT1, LPT2, LPT3 , ( ), PRN LPT1 , .. ,
3) AUX ( .Auxilary - )- - ( , .),
4) COM1, COM2 ( . COMmunication port), COM- - ( ) ,
5) NUL - .
( ), - , .
INPUT OUTPUT, .
9.5.3. .
.
. reset, rewrite, append, lose EOF.
( ). reset, rewrite, append, reset rewrite , append - .
reset. , f_log, reset:
Reset(f_log);
, .. , , . , . reset .
rewrite. , f_log, :
Rewrite(f_log);
rewrite , . , . rewrite , - , . rewrite , ( reset, ).
append. , f_log, ( ):
Append(f_log)
lose. , f_log, lose:
lose (f_log);
lose . , f_log .
EOF(End Of File). EOF(f_log), if, TRUE, :
1) , f_log, .. ,
2) .
False, , .
. . ( ) - . reset, rewrite ( 0), . append . read, readln, write, writeln, , ( ). Seek, - Truncate. / IOResult.
read (readln). read :
read (f_log,v1[,v2,,vn]);
f_log - ,
v1,v2,,vn - , , f.
, v1,v2,,vn n , , , n .
:
1) char ,
2) string , , ,
3) -, .
readln read, , , , , .
write(writeln). :
write (f_log,v1[,v2,,vn]);
, , , , n v1,v2,,vn. n , . - , . ( ), . 1.
writeln write, , , , . .
Input () Output ( ), - (, , ).
Read(Input, x,y);
write(Output, ' =',,);
:
1) ( - ) x,y ( x,y ),
2) ' =' .
Input Output , . :
Read(x,y);
write(' =',,);
Seek. , f_log k :
Seek(f_log, k);
. , . - 0 n-1, n .
Truncate. , f_log, , :
Truncate(f_log);
, .
IOResult. , - . 0. IOResult , {$i-}. , , ft, :
{$i-} reset(ft); {$i+}
if IOresult<>0 then writeln ('File ',FileName,' not existent')
else writeln ('File ',FileName,' open for reading');
. rename erase. . fileSize .
rename.
Rename(f_log, F_f);
, f_log, F_f.
erase.
Erase(f_log);
, f_log.
FileSize.
FileSize(f_log);
. , , 0. fileSize . , f_log Seek(f_log, FileSize(f_log)).
, , .
9.5.4.
, .
2. :
1) FPC rmas.txt, 2) n,
3) (2*i+1), (1≤ i ≤ n),
4) ,
5) , .
:
var i:byte;n:integer; ft:text; FileName,st:string;
Begin
FileName:='c:\fpc\rmas.txt'; { }
write(' Vvedite razmernost n:');readln(n); { n }
assign(ft,FileName); { }
rewrite(ft); { }
for i:=1 to n do
begin str(2*i+1,st);writeln(ft,st) end; { }
{$i-} { - }
reset (ft); { }
{$i+} { - }
if IOresult<>0 { }
then writeln ('File ',FileName,' not existent')
else writeln ('File ',FileName,' open for reading');
i:=0; writeln('File ',FileName,' content:');
while not(eof(ft)) do { eof }
Begin
i:=i+1; readln(ft,st);
writeln('file element number ',i,' is equal to ',st);
End;
close(ft); { }
End.
3. , . rewriting, , , , . ft Art n ( ). Art , rewriting . Mas_st 100. test.txt FPC C. 8 (i 2+1) 1£ i £8 .
var i,Lmas:integer; ft:text; FileName:string;
Mas_st:array [1..100] of string;
procedure rewriting (var ftext:text; var Art:array of string; var n:integer);
begin { rewriting }
n:=0;
reset(ftext); { }
While not Eof(ftext) do
Begin
inc(n);readLn(ftext,Art[n-1]); { , }
End;
close(ftext); { }
End;
begin { }
FileName:='c:\fpc\test.txt'; { }
assign(ft, FileName); { }
rewrite(ft); { }
for i:=1 to 8 do writeln(ft,i*i+1);
rewriting(ft,Mas_st,Lmas); { }
writeln(' Lmas = ',Lmas);
for i:=1 to Lmas do writeln(' Mas[',i,']= ',Mas_st[i]);
End.
Lmas = 12 , {2 5 10 17 26 37 50 65}.
4. ( ) . search_word, , . , , , No.
c:\fpc\test.txt, , 3.
os, , 0. :
var n,i:integer; ft:text; FileName:string;
procedure search_word (var ftext:text; var n:integer);
var str,w_s:string;
begin { search_word }
writeln(' Vvedite slovo:'); read(w_s);
n:=-1;
reset(ftext); { }
While not Eof(ftext) do
Begin
inc(n);readLn(ftext,str); { , str }
if pos(w_s,str)<>0 then { }
begin writeln('word ',w_s,' is fined in line,n);close(ftext); exit end;
End;
writeln('NO');
close(ftext); { }
End;
begin { }
FileName:='c:\fpc\test.txt'; { }
assign(ft, FileName); { }
rewrite(ft); { }
for i:=1 to 8 do writeln(ft,i*i+1);
search_word(ft,n); { , , }
End.
.
1. ?
2. ?
3. ?
4. ?
5. , ?
6. ?
7. ?
8. .
9. .
10. MS DOS?
11. INPUT OUTPUT?
12. ?
13. ?
14. ?
.
1. 4 .9.5. , , , .
2. NumWord, , , , . NumWord.
.