.

Программирование на языке Турбо Паскаль

Язык: русский
Формат: реферат
Тип документа: Word Doc
0 2445
Скачать документ

Eaeoeey 1. No?oeoo?a i?ia?aiiu ia ycuea Turbo Pascal

I?eaaae?i i?inoaeoee i?eia? i?ia?aiiu, aaeeinoaaiiay oeaeue eioi?ie (
auaanoe ia ye?ai eaeia-ieaoaeue i?eaaonoaea:

program Hello;

begin

writeln(‘Hello, world!’);

readln;

end.

Ia?aay no?iea ie/aai ia aeaeaao, iia i?inoi niaea?aeeo iacaaiea
i?ia?aiiu. Caoai, iinea neiaa begin ia/eiathony nianoaaiii aeaenoaey. A
iaoae i?ia?aiia eo aeaa: ia?aia ( yoi auaiae no?i/ee «Hello, world» ia
ye?ai, a aoi?ia ( iaeeaeaiea iaaeaoey eeaaeoe «Enter», iii ioaeii aeey
oiai, /oiau iiaeii auei oaeaeaoue ?acoeueoao i?ia?aiiu, a caoai oaea
iaaeaoue «Enter» e aa?iooueny a Oo?ai-Ianeaeue. E, iaeiiaoe, neiai end n
oi/eie a iineaaeiae no?iea aiai?eo i oii, /oi i?ia?aiia caeii/eeanue.
Aeaenoaey, ec eioi?uo ninoieo i?ia?aiia, iacuaathony iia?aoi?aie, iie
ioaeaeythony ae?oa io ae?oaa oi/eie n caiyoie.

A oaia?ue i?eaaae?i i?eia?, a eioi?ii i?ia?aiia oaea ia «aeooay», oi
anoue iiaeao cai?aoeaaoue eaeea-eeai aeaiiua o iieueciaaoaey. Ionoue
o?aaoaony ni?ineoue o iieueciaaoaey aeaa /enea, iinea yoiai auaanoe ia
ye?ai eo i?iecaaaeaiea:

program AxB;

var a,b: integer;

begin

writeln(‘Aaaaeeoa a e b’);

readln(a,b);

writeln(‘I?iecaaaeaiea ?aaii ‘,a*b);

readln;

end;

A yoie i?ia?aiia ia?aae neiaii begin iiyaeyaony iiaay no?i/ea,
ia/eiathuayny neiaii var. A iae iu oeacuaaai, /oi i?ia?aiia iiiaaeiaeony
aeaa ia?aiaiiua (a e b), a eioi?uo iiaeii o?aieoue oeaeua /enea (neiai
integer).

I oii, /oi aeaeaao ia?aue iia?aoi?, iai ecaanoii: ii auaiaeeo ia ye?ai
no?i/eo ‘Aaaaeeoa a e b’. I?e auiieiaiee aoi?iai iia?aoi?a i?ia?aiia
aoaeao aeaeaoue, iiea iieueciaaoaeue ia aaaaeao /enei n eeaaeaoo?u e ia
iaaei?o «Enter»; yoi /enei i?ia?aiia caieoao a ia?aiaiioth a, caoai oi
aea naiia aeaeaaony aeey ia?aiaiiie b. O?aoueei iia?aoi?ii auaiaeei ia
ye?ai nia/aea iaaeienue «I?iecaaaeaiea ?aaii », a iioii cia/aiea
au?aaeaiey a(b («*» ( ciae oiiiaeaiey). *aoa??oue iia?aoi? iiyniaiee ia
o?aaoao.

A oaia?ue ?anniio?ei no?oeoo?o i?ia?aiiu a iauai aeaea. Ethaay i?ia?aiia
ia Oo?ai-Ianeaea ninoieo ec o?ao aeieia: aeiea iauyaeaiee, aeiea
iienaiey i?ioeaaeo? e ooieoeee e aeiea iniiaiie i?ia?aiiu. Ieaea yoe
aeiee ?anienaiu aieaa iiae?iaii.

Aeie iauyaeaiee:

program … (iacaaiea i?ia?aiiu)

uses … (eniieuecoaiua i?ia?aiiie aiaoiea iiaeoee)

const … (iauyaeaiey eiinoaio)

type … (iauyaeaiey oeiia)

var … (iauyaeaiey ia?aiaiiuo)

Aeie iienaiey i?ioeaaeo? e ooieoeee:

procedure (function)

begin

end;

Aeie iniiaiie i?ia?aiiu:

begin

… (iia?aoi?u iniiaiie i?ia?aiiu) …

end;

?anniio?ei iaeaieaa aaaeiua /anoe auoaiienaiiuo aeieia. Iiae caaieiaeii
i?ia?aiiu iiieiaaony eiy, iiiiaathuaa ii?aaeaeeoue a? iacia/aiea. Eiy,
eee eaeaioeoeeaoi?, no?ieony ii neaaeothuei i?aaeeai: iii iiaeao
ia/eiaoueny n aieueoie eee iaeie aoeau eaoeineiai aeoaaeoa eee ciaea
«_», aeaeaa iiaoo neaaeiaaoue aoeau, oeeo?u eee ciae «_»; aioo?e
eaeaioeoeeaoi?a ia iiaeao noiyoue i?iaae. Iinea eiaie i?ia?aiiu neaaeoao
iinoaaeoue «;», yoio ciae neoaeeo a Ianeaea aeey ?acaeaeaiey
iineaaeiaaoaeueiuo eino?oeoeee. Caiaoei, /oi eiy i?ia?aiiu iiaeao ia
niaiaaeaoue n eiaiai niioaaonoaothuaai oaeea ia aeenea.

Iinea neiaa const iiiauathony iienaiey iinoiyiiuo, eioi?ua aoaeoo
eniieueciaaiu a i?ia?aiia, iai?eia?:

const Zero = 0;

pi = 3.1415926;

my_const = -1.5;

Hello = ‘I?eaao !’;

Ca neiaii var neaaeotho iauyaeaiey ia?aiaiiuo, eioi?ua iiiaaeiayony iai
i?e iaienaiee i?ia?aiiu. Ia?aiaiiua Ianeaey iiaoo o?aieoue aeaiiua
?acee/iie i?e?iaeu: /enea, no?iee oaenoa, ioaeaeueiua neiaieu e o. i.
Ieaea i?eaiaeeony /anoue oeiia ia?aiaiiuo, eioi?ua iiaeii i?eiaiyoue.

Iacaaiea oeia Aiciiaeiua cia/aiey I?eia?u cia/aiee

integer oeaeua: -32768 … 32767 12, -10000

real aeaenoaeoaeueiua (ii iiaeoeth): 2,9×10-39… 1,7×1038 -9.81,
6.02e-23

string[n] no?iea aei n neiaieia aeeeiie, anee [n] ia oeacaii, oi aei 255
‘abcde’, ‘i?eaao’

char iaeeii/iue neiaie ‘F’, ‘!’, ’_’,’th’

Iauyaeaiey ia?aiaiiuo caienuaathony a neaaeothuae oi?ia: var
: ;

Anee iienuaathony ianeieueei ia?aiaiiuo iaeiiai oeia, oi aeinoaoi/ii
caienaoue eo eiaia /a?ac caiyooth, a iinea aeaiaoi/ey iinoaaeoue iauee
oei.

I?eia?u iauyaeaiey:

var Number: integer;

d,l: real;

Name: string[20];

Line: string;

Key1,Key2: char;

Aeie iniiaiie i?ia?aiiu. Caeanue, iaaeaeo neiaaie begin e end.
?aniieaaathony eiiaiaeu (oi/iaa, iia?aoi?u), eioi?ua aoaeoo auiieiyoueny
iaeei ca ae?oaei i?e caionea i?ia?aiiu. ?anniio?ei i?inoaeoea oeiu
iia?aoi?ia ia neaaeothuai i?eia?a:

program First;

const a2 = 3;

a1 = -2;

a0 = 5;

var x,f: real;

begin

write(‘Aaaaeeoa cia/aiea o ’);

readln(x);

f := a2*x*x+a1*x+a0;

writeln(‘Cia/aiea eaaae?aoiiai o?ao/eaia: ’,f);

end.

Ia?aay no?iea eniieiyaiie (iniiaiie) /anoe i?ia?aiiu auaiaeeo ia ye?ai
iaaeienue «Aaaaeeoa cia/aiea o », aeey yoiai eniieuecoaony i?ioeaaeo?a
write iaienaiiay ?ac?aaio/eeaie Oo?ai Ianeaey, oi anoue iaai? eiiaiae,
iaaeaeeiue aeey ian, ii nouanoaothuee ?aaeueii a iaae?ao nenoaiu Oo?ai
Ianeaeue. A ea/anoaa ia?aiao?a yoie i?ioeaaeo?u eniieuecoaony iaoa
no?i/ea. Ia?aiao?u anaaaea caienuaathony a e?oaeuo neiaeao, aiino?iou
icia/atho, /oi ia?aiao? eiaao no?ieiaue oei. Eoae, a ia?aie no?iea iu
aeaeei oae iacuaaaiue iia?aoi? auciaa i?ioeaaeo?u. Eaaeaeue iia?aoi?
ioaeaeyaony io neaaeothuaai ciaeii «;». Ai aoi?ie no?iea aucuaaaony
i?ioeaaeo?a aaiaea readln(x), eioi?ay aeaeao, iiea iieueciaaoaeue
iaaa?ao cia/aiea x n eeaaeaoo?u e iaaeiao eeaaeoo «Enter», a caoai
ia?aaiaeeo eo?ni? ia neaaeothuoth no?ieo (ln ( Line ( no?iea). A
o?aoueae no?iea au/eneyaony cia/aiea o?ao/eaia e caienuaaaony a
ia?aiaiioth f; yoio iia?aoi? iacuaaaony iia?aoi?ii i?enaaeaaiey, e
iaicia/aaony neiaieii “:=”. A iineaaeiae no?iea ia ye?ai auaiaeeony
no?iea «Cia/aiea eaaae?aoiiai o?ao/eaia: » e cia/aiea ia?aiaiiie f.
Ianeiaeii caiaoeoue, /oi caeanue i?ioeaaeo?a writeln ia?aaeaaony oaea ia
iaeei, a aeaa ia?aiao?a, i?e/ai iie iiaoo eiaoue ?aciua oeiu. Aiiaua,
i?ioeaaeo?u aaiaea e auaiaea (o.a. write, writeln, read, readln) iiaoo
eiaoue ethaia /enei ia?aiao?ia ?acee/iuo oeiia, ia?aiao?aie iiaoo
yaeyoueny ia?aiaiiua, eeoa?aeu (o.a. iaiin?aaenoaaiii caienaiiua /enea,
no?iee; a iaoai i?eia?a aeaaaeaeu auee eniieueciaaiu no?ieiaua
eeoa?aeu), a oaeaea au?aaeaiey. Eniieuecoy au?aaeaiea i?e auaiaea,
iiaeii caiaieoue aeaa iineaaeiea no?i/ee iaoae i?ia?aiiu iaeiie:

writeln(‘Cia/aiea eaaae?aoiiai o?ao/eaia: ‘, a2*x*x+a1*x+a0);

A a?eoiaoe/aneeo au?aaeaieyo ia Ianeaea eniieuecothony neaaeothuea ciaee
aeey iaicia/aiey iia?aoeee: +, -, *, /. Aeey ii?aaeaeaiey ii?yaeea
aeaenoaee eniieuecothony e?oaeua neiaee niaeanii iauai?eciaiiui
iaoaiaoe/aneei i?aaeeai.

Caia/aiea ia eiaiao. Aeey iaicia/aiey ia?aiaiiuo cai?auaaony
eniieueciaaiea ?yaea neia, iacuaaaiuo ca?aca?ae?iaaiiuie, iie ea?atho a
ycuea iniaoth ?ieue. Iai oaea ano?a/aeny ?yae ca?aca?ae?iaaiiuo neia:
program, begin, end, string, const, var, e o.i.

Eaeoeey 2. I?ioeaaeo?u aaiaea-auaiaea. Iaeioi?ua ano?iaiiua ooieoeee
Oo?ai-Ianeaey.

1. I?ioeaaeo?u aaiaea-auaiaea. Ii/oe eaaeaeay i?ia?aiia aeieaeia
iauaoueny n iieueciaaoaeai, oi anoue auaiaeeoue ?acoeueoaou naiae ?aaiou
ia ye?ai e cai?aoeaaoue o iieueciaaoaey eioi?iaoeeth n eeaaeaoo?u. Aeey
oiai /oiau yoi noaei aiciiaeiui, a Oo?ai-Ianeaea eiathony niaoeeaeueiua
i?ioeaaeo?u (oi anoue iaaieueoea aniiiiaaoaeueiua i?ia?aiiu),
iacuaathony ii i?ioeaaeo?aie aaiaea-auaiaea. Aeey oiai /oiau canoaaeoue
i?ioeaaeo?o ?aaioaoue a iaoae i?ia?aiia, ioaeii iaienaoue a? eiy, ca
eioi?ui a neiaeao, /a?ac caiyooth ia?a/eneeoue ia?aiao?u, eioi?ua iu
oioei ae ia?aaeaoue. Aeey i?ioeaaeo?u auaiaea eioi?iaoeee ia ye?ai
ia?aiao?aie iiaoo neoaeeoue /enea eee oaenoiaua niiauaiey, eioi?ua
aeieaeia ia/aoaoue iaoa i?ia?aiia ia ye?ai. Iieoai iacia/aiea yoeo
i?ioeaaeo?.

write(p1,p2,… pn); ( auaiaeeo ia ye?ai cia/aiey au?aaeaiee p1,p2,…
pn, eiee/anoai eioi?uo (n) iaia?aie/aii. Au?aaeaiey iiaoo auoue
/eneiaua, no?ieiaua, neiaieueiua e eiae/aneea. Iiae au?aaeaieai aoaeai
iiieiaoue niaieoiiinoue iaeioi?uo aeaenoaee, i?eiai?iiuo e ia?aiaiiui,
eiinoaioai eee eeoa?aeai, iai?eia?: a?eoiaoe/aneea aeaenoaey e
iaoaiaoe/aneea ooieoeee aeey /enae, ooieoeee aeey ia?aaioee no?ie e
ioaeaeueiuo neiaieia, eiae/aneea au?aaeaiey e o.i. Aiciiaeai oi?iaoiue
auaiae, o.a. yaiia oeacaiea oiai, neieueei auaeaeyoue iiceoeee ia ye?aia
aeey auaiaea cia/aiey. I?eia? aeey aauanoaaiiuo oeiia: write(r+s:10:5);
( auaanoe cia/aiea au?aaeaiey r+s n auaeaeaieai aeey yoiai 10 iiceoeee,
ec ieo 5 ( iinea caiyoie. Aeey ae?oaeo oeiia ana ianeieueei i?iua:
write(p:10); ( auaanoe cia/aiea au?aaeaiey p, auaeaeea iiae yoi 10
iiceoeee. Auaiae ia ye?ai a ethaii neo/aa i?iecaiaeeony ii i?aaiio e?ath
auaeaeaiiiai iiey.

writeln(p1,p2,… pn); ( aiaeiae/ii write, auaiaeeo cia/aiey p1,p2,…
pn, iinea /aai ia?aaiaeeo eo?ni? ia iiaoth no?ieo. Niune ia?aiao?ia (
oio aea, caia/aiey i oi?iaoiii auaiaea inoathony a neea. Nouanoaoao
aa?eaio writeln; (aac ia?aiao?ia), /oi icia/aao eeoue ia?aaiae eo?ni?a
ia ia/aei iiaie no?iee.

readln(v1,v2,…vn); ( aaiae n eeaaeaoo?u cia/aiee ia?aiaiiuo v1,…vn.
Ia?aiaiiua iiaoo eiaoue no?ieiaue, neiaieueiue eee /eneiaie oei. I?e
aaiaea neaaeoao ?acaeaeyoue cia/aiey i?iaaeaie, neiaieaie oaaoeyoeee eee
ia?aaiaea no?iee (o.a., iaaeeiay Enter).

read(v1,v2,…vn); ( ii iacia/aieth noiaeii n readln; ioee/ea ninoieo a
oii, /oi neiaie ia?aaiaea no?iee (Enter), iaaeaoue i?e caaa?oaiee
aaiaea, ia «i?iaeaouaaaony», a aeaeao neaaeothuaai iia?aoi?a aaiaea.
Anee ei ieaaeaony iia?aoi? aaiaea no?ieiaie ia?aiaiiie eee i?inoi
readln; oi no?ieiaie ia?aiaiiie aoaeao i?enaiaii cia/aiea ionoie no?iee,
a readln aac ia?aiao?ia ia noaiao aeaeaoue, iiea iieueciaaoaeue iaaeiao
Enter, a n?aaae?oao ia oaea aaaaeaiiue.

I?eia?. I?ia?aiia i?ineo iieueciaaoaey aaanoe n eeaaeaoo?u aeaa oeaeuo
/enea e ia/aoaao ia ye?aia eo noiio:

program PrintSum;

var a,b: integer;

begin

write(‘Aaaaeeoa aeaa /enea:’);

readln(a,b);

writeln(‘Noiia a e b ?aaia ‘,a+b);

readln;

end.

Ooieoeee /eneiauo ia?aiao?ia.

Iacaaiea Cia/aiea

abs(x) iiaeoeue x

cos(x) eineion x

frac(x) ae?iaiay /anoue x

int(x) oeaeay /anoue x (o.a. aeeaeaeoaa oeaeia, ia i?aainoiaeyuaa x)

pi /enei (

round(x) x, ie?oae?iiia aei oeaeiai

sin(x) neion x

sqr(x) eaaae?ao x

sqrt(x) eaaae?aoiue ei?aiue ec x

trunc(x) /enei, iieo/aiiia ec x ioa?anuaaieai ae?iaiie /anoe

Eaeoeey 3. Iia?aoi?u oneiaiiai auiieiaiey.

1. Iia?aoi? if.

Eiiaaea o?aaoaony, /oiau /anoue i?ia?aiiu auiieiyeanue ia anaaaea, a
eeoue i?e auiieiaiee iaeioi?iai oneiaey (a i?e iaauiieiaiee yoiai
oneiaey auiieiyeanue ae?oaay /anoue i?ia?aiiu). A yoii neo/aa
iieuecothony iia?aoi?ii oneiaiiai auiieiaiey, eioi?ue caienuaaaony a
neaaeothuai aeaea:

if then else ;

Iiae iia?aoi?ii iiieiaaony eeai iaeeii/iue iia?aoi? (iai?eia?,
i?enaaeaaiey, auciaa i?ioeaaeo?u), eeai o.i. ninoaaiie iia?aoi?,
ninoiyuee ec ianeieueeeo i?inouo iia?aoi?ia, iiiau?iiuo iaaeaeo neiaaie
begin e end. Aaaeii caiaoeoue, /oi ia?aae else ia noaaeony oi/ea n
caiyoie. *anoue else iiaeao e ionoonoaiaaoue.

I?eia? 1: ionoue o?aaoaony iaeoe /enei m=max(a,b). Yoie caaea/a
niioaaonoaoao neaaeothuee o?aaiaio i?ia?aiiu ia Ianeaea:

if a>b then m:=a else m:=b;

I?eia? 2: (aac else) ionoue aeaii oeaeia /enei i. O?aaoaony inoaaeoue
aai aac eciaiaiey, anee iii aeaeeony ia 2, e au/anoue ec iaai 1, anee
yoi ia oae.

var i: integer;

…….

if i mod 2 = 1 then i:=i-1; {else – ie/aai ia aeaeaoue}

I?eia/aiea: a i?eia?a eniieueciaaia iia?aoeey iaoiaeaeaiey inoaoea io
aeaeaiey (mod), aeey iaoiaeaeaiey iaiieiiai /anoiiai a Oo?ai-Ianeaea
eniieuecoaony div.

I?eia? 3: (n eniieueciaaieai ninoaaiiai iia?aoi?a). Ionoue aeaiu aeaa
ia?aiaiiua oeia real. O?aaoaony iiiaiyoue ianoaie cia/aiey yoeo
ia?aiaiiuo, anee a1>a2.

var a1,a2,buf :real;

………

if a1>a2 then begin

buf:=a1;

a1:=a2;

a2:=buf;

end;

Neaaeothuee i?eia? eniieuecoao aeiaeaiiua iia?aoi?u if.

I?eia? 4: Iiene ei?iae eaaae?aoiiai o?aaiaiey.

program SqEquation;

var a,b,c,d: real;

begin

writeln;

write(‘Aaaaeeoa eiyooeoeeaiou a,b,c eaaae?aoiiai o?aaiaiey : ‘);

readln(a,b,c);

d:=sqr(b)-4*a*c;

if d>=0 then

if d=0 then writeln(‘Aaeeinoaaiiue ei?aiue: x=’,-b/(2*a):8:3)

else writeln(‘Aeaa ei?iy : x1=’,(-b+sqrt(d))/(2*a):8:3,

‘, x2=’,(-b-sqrt(d))/(2*a):8:3)

else {d ‘); readln(n);

write(n,’ o/aiee’);

if n1 then writeln(‘a’);

end

else

writeln(‘ia’);

readln;

end.

A yoii i?eia?a i?eoeinue eniieueciaaoue ninoaaiie iia?aoi? (begin …
end;) aeey oiai /oiau /anoue else ioiineeanue ia e iia?aoi?o if n>1, a e
if n ‘); readln(n);

write(n,’ o/aiee’);

case n of

2..4: write(‘a’);

5..10: write(‘ia’);

end;

readln;

end.

Iiaeii oaeaea oniaa?oainoaiaaoue i?ia?aiio aeey i?iecaieueiiai
iaoo?aeueiiai n:

write(n,’ o/aiee’);

case n mod 100 of

11..19: write(‘ia’);

else case n mod 10 of

2..4: write(‘a’);

0,5..9: write(‘ia’);

end;

end;

Eaeoeey 4. Iia?aoi?u oeeeeia a Ianeaea

A ?aaeueiuo caaea/ao /anoi o?aaoaony auiieiyoue iaeie e oa aea iia?aoi?u
ianeieueei ?ac. Aiciiaeiu ?acee/iua aa?eaiou: auiieiyoue o?aaiaio
i?ia?aiiu oeene?iaaiiia /enei ?ac, auiieiyoue, iiea iaeioi?ia oneiaea
yaeyaony enoeiiui, e o. i. A nayce n iaee/eai aa?eaioia a Ianeaea
nouanoaoao 3 oeia oeeeeia.

1. Oeeee n iinooneiaeai (Repeat)

Ia Ianeaea caienuaaaony neaaeothuei ia?acii: repeat until
. (Ii-?onnee: iiaoi?youe /oi-oi iiea_ia_auiieieeinue oneiaea).
Iiae iaicia/aieai caeanue iiieiaaony eeai iaeeii/iue, eeai
iineaaeiaaoaeueiinoue iia?aoi?ia, ?acaeae?iiuo oi/eie n caiyoie. Oeeee
?aaioaao neaaeothuei ia?acii: auiieiyaony iia?aoi?, caoai i?iaa?yaony
oneiaea, anee iii iiea aua ia auiieieeinue, oi iia?aoi? auiieiyaony
aiiaue, caoai i?iaa?yaony oneiaea, e o. ae. Eiaaea oneiaea, iaeiiaoe,
noaiao enoeiiui auiieiaiea iia?aoi?a, ?aniieiaeaiiiai aioo?e oeeeea,
i?ae?aoeony, e aeaeaa aoaeao auiieiyoueny neaaeothuee ca oeeeeii
iia?aoi?. Iiae oneiaeai, aiiaua aiai?y, iiieiaaony au?aaeaiea
eiae/aneiai oeia.

I?eia? (iiaen/ao noiiu iaoo?aeueiuo /enae io 1 aei 100):

var i,sum: integer;

begin

sum:=0; i:=0;

repeat

i:=i+1;

sum:=sum+i;

until i=100;

writeln(‘Noiia ?aaia: ‘,sum);

readln;

end.

Aaaeii caiaoeoue, /oi iia?aoi?u noiyuea aioo?e oeeeea repeat (eia/a ( a
oaea oeeeea) auiieiythony oioy au iaeei ?ac (oieueei iinea yoiai
i?iaa?yaony oneiaea auoiaea).

2. Oeeee n i?aaeoneiaeai (While)

Yoio oeeee caienuaaaony oae: while do . (Iiea
oneiaea enoeiii, auiieiyoue iia?aoi?). Nooue a neaaeothuai: iiea oneiaea
enoeiii, auiieiyaony iia?aoi? (a yoii neo/aa iia?aoi? iiaeao ia
auiieieoueny ie ?aco, o.e. oneiaea i?iaa?yaony aei auiieiaiey). Iiae
iia?aoi?ii caeanue iiieiaaony eeai i?inoie, eeai ninoaaiie iia?aoi?
(o.a. ianeieueei iia?aoi?ia, caeeth/?iuo a begin … end).

?anniio?ei oio aea i?eia?, auiieiaiiue n iiiiuueth while:

var i,sum: integer;

begin

sum:=0; i:=0;

while i:= to do . Aianoi
to aiciiaeii neiai downto. ?anniio?ei oaeie i?eia?: o?aaoaony auaanoe ia
ye?ai oaaeeoeo eaaae?aoia iaoo?aeueiuo /enae io 2 aei 20.

var i: integer;

begin for i:=2 to 20 do writeln(i,’ ‘,sqr(i)); end.

I?e auiieiaiee oeeeea i?ienoiaeeo neaaeothuaa: ia?aiaiiie i
i?enaaeaaaony ia/aeueiia cia/aiea (2), caoai auiieiyaony iia?aoi?
(i?inoie eee ninoaaiie), iinea yoiai e i i?eaaaeyaony 1, e i?iaa?yaony,
ia noaei ee cia/aiea i ?aaii eiia/iiio (20). Anee iao, oi aiiaue
auiieiyaony iia?aoi?, aeiaaaeyaony 1, e o. ae. A neo/aa, eiaaea aianoi
to eniieuecoaony downto, ana i?ienoiaeeo iaiai?io: aaeeieoea ia
i?eaaaeyaony, a au/eoaaony. Iai?eia?, neaaeothuee oeeee auaaaeao oo aea
oaaeeoeo, ii a ia?aoiii ii?yaeea:

for i:=20 downto 2 do writeln(i,’ ‘,sqr(i));

A caaa?oaiea caieoai i?ia?aiio i iiaen/aoa noiiu /enae io 1 aei 100 n
iiiiuueth for:

var i, sum: integer;

begin

sum:=0;

for i:=1 to 100 do sum:=sum+i;

writeln(sum);

end.

Eaeoeey 5. Neiaieueiua e no?ieiaua ia?aiaiiua

A iaoaiaoeea iiae ia?aiaiiie iau/ii iiieiatho iaeoth aaee/eio, cia/aiey
eioi?ie iiaoo auoue oieueei /eneaie. A ycueao i?ia?aiie?iaaiey ii/oe ana
aeaiiua, n eioi?uie ?aaioatho i?ia?aiiu, o?aiyony a aeaea ia?aiaiiuo. A
/anoiinoe, auaatho ia?aiaiiua aeey o?aiaiey oaenoiauo aeaiiuo:
i?aaeeiaeaiee, neia e ioaeaeueiuo neiaieia.

1. Neiaieueiue oei

Oei aeaiiuo, ia?aiaiiua eioi?iai o?aiyo ?iaii iaeei neiaie (aoeao,
oeeo?o, ciae i?aieiaiey e o.i.) iacuaaaony neiaieueiui, a a Ianeaea —
char. Iauyaeoue ia?aiaiioth oaeiai oeia iiaeii oae: var ch: char;. Aeey
oiai /oiau iieiaeeoue a yoo ia?aiaiioth neiaie, ioaeii eniieueciaaoue
iia?aoi? i?enaaeaaiey, a neiaie caienuaaoue a aiino?ioao, iai?eia?:
ch:=’R’;. Aeey neiaieueiuo ia?aiaiiuo aiciiaeii oaeaea eniieueciaaiea
i?ioeaaeo?u readln, iai?eia?:

write(‘Aueoe ec ea?u? (Aea/Iao)’); readln(ch);

if ch=’Ae’ then …{auoiaeeoue}…

else …{i?iaeieaeaoue}…;

Neiaieueiua ia?aiaiiua a iaiyoe eiiiuethoa?a o?aiyony a aeaea /eneiauo
eiaeia, eia/a aiai?y, o eaaeaeiai neiaiea anoue ii?yaeeiaue iiia?. E
i?eia?o, eiae i?iaaea ?aaai 32, eiae ‘A’ — 65, ‘B’ — 66, ‘C’ — 67, eiae
neiaiea ‘1’ — 48, ‘2’ — 49, ‘.’ — 46 e o. i. Iaeioi?ua neiaieu (n
eiaeaie, iaiueoeie 32) yaeythony oi?aaeythueie, i?e auaiaea oaeeo
neiaieia ia ye?ai i?ienoiaeeo eaeia eeai aeaenoaea, iai?eia?, neiaie n
eiaeii 10 ia?aiineo eo?ni? ia iiaoth no?ieo, n eiaeii 7 — aucuaaao
caoeiaie neaiae, n eiaeii 8 — naeaeaaao eo?ni? ia iaeio iiceoeeth aeaai.
Iiae o?aiaiea neiaiea auaeaeyaony 1 aaeo (aaeo ninoieo ec 8 aeo, a aeo
iiaeao i?eieiaoue cia/aiey 0 eee 1), iiyoiio anaai iiaeii caeiaee?iaaoue
28=256 ?acee/iuo neiaieia. Eiaee?iaea neiaieia, eioi?ay eniieuecoaony
Oo?ai-Ianeaea, iacuaaaony ASCII (American Standard Code for Information
Interchange — aia?eeaineee noaiaea?oiue eiae aeey iaiaia eioi?iaoeeae).

Aeey oiai /oiau iieo/eoue a i?ia?aiia eiae neiaiea ioaeii eniieueciaaoue
ooieoeeth chr, iai?eia?:

var i: byte; {/enei, caieiathuaa 1 aaeo, cia/aiey — io 0 aei 255}

ch: char;

readln(i); writeln(‘neiaie n eiaeii ‘,i,’ — yoi ‘,chr(i));

Anee a ea/anoaa eiaea eniieuecoaony eiie?aoiia /enei, a ia au?aaeaiea e
ia ia?aiaiiay, oi iiaeii eniieueciaaoue neiaie «#», neaaeai oae:
ch:=#7;. Aeey oiai ia?aoiaea io eiaea e neiaieo eniieuecoaony ooieoeey
ord (io neiaa ordinal — ii?yaeeiaue). Eiathueany ciaiey iicaieytho iai
iaienaoue i?ia?aiio, eioi?ay auaea?o ia ye?ai oaaeeoeo n eiaeaie
neiaieia:

program ASCII;

var ch: char;

begin

for ch:=#32 to #255 do write(ord(ch),’—>’,ch,’ ‘);

readln;

end.

A yoie i?ia?aiia a ea/anoaa n/?o/eea oeeeea auea eniieueciaaia
neiaieueiay ia?aiaiiay, yoi ?ac?aoaaony, iineieueeo oeeee for iiaeao
eniieueciaaoue a ea/anoaa n/?o/eea ia?aiaiiua ethaiai oeia, cia/aiey
eioi?iai o?aiyony a aeaea oeaeuo /enae.

N eniieueciaaieai eiaeia ?aaioatho au? aeaa ooieoeee, cia/aiey eioi?uo
neiaieueiua:

succ (io succeedent — iineaaeothuee), iia auaea?o neiaie ni neaaeothuei
eiaeii.

pred (io predecessor — i?aaeoanoaaiiee), auaea?o neiaie n i?aaeuaeouei
eiaeii.

Anee iiiuoaoueny a i?ia?aiia iieo/eoue succ(#255) eee pred(#0), oi
aicieeiao ioeaea. Iieuecoynue yoeie ooieoeeyie iiaeii ia?aienaoue
i?aaeuaeouoth i?ia?aiio e ii-ae?oaiio:

ch:=#32;

while ch#255 do begin

write(ord(ch),’—>’,ch,’ ‘);

ch:=succ(ch);

end;

N?aaiaiea neiaieia. Oaeaea eae e /enea, neiaieu iiaeii n?aaieaaoue ia =,
, , =. A yoii neo/aa Ianeaeue n?aaieaaao ia naie neiaieu, a
eo eiaeu. Oaaeeoea ASCII ninoaaeaia oaeei ia?acii, /oi eiaeu aoea
(eaoeineeo e aieueoeinoaa ?onneeo) aic?anoatho i?e aeaeaeaiee a
aeoaaeoiii ii?yaeea, a eiaeu oeeo? ?aniieiaeaiu ii ii?yaeeo:
ord(‘0’)=48, ord(‘1’)=49, … ord(‘9’)=57. N?aaiaiey neiaieia iiaeii
eniieueciaaoue aacaea, aaea o?aaothony eiae/aneea au?aaeaiey: a
iia?aoi?a if, a oeeeeao e o.i.

2. No?ieiaue oei

Aeey o?aiaiey no?ie (oi anoue iineaaeiaaoaeueiinoae ec neiaieia) a
Oo?ai-Ianeaea eiaaony oei string. Cia/aieyie no?ieiauo ia?aiaiiuo iiaoo
auoue iineaaeiaaoaeueiinoe ?acee/iie aeeeiu (io ioey e aieaa, aeeeia 0
niioaaonoaoao ionoay no?iea). Iauyaeoue no?ieiaoth ia?aiaiioth iiaeii
aeaoiy niiniaaie: eeai var s: string; (iaeneiaeueiay aeeeia no?iee — 255
neiaieia), eeai var s: string[n]; (iaeneiaeueiay aeeeia — n neiaieia, n
— eiinoaioa eee eiie?aoiia /enei).

Aeey oiai /oiau iieiaeeoue cia/aiea a no?ieiaoth ia?aiaiioth
eniieuecothony oa aea i?e?iu, /oi e i?e ?aaioa n neiaieaie. A neo/aa
i?enaaeaaiey eiie?aoiie no?iee, yoi no?iea aeieaeia caienuaaoueny a
aiino?ioao (s:=’Hello, world!’). I?eaaae?i i?inoaeoee i?eia? ni
no?ieaie: i?ia?aiia ni?aoeaaao eiy o iieueciaaoaey, a caoai i?eaaonoaoao
aai:

program Hello;

var s: string;

begin

write(‘Eae Aan ciaoo: ‘);

readln(s);

write(‘I?eaao, ‘,s,’!’);

readln;

end.

O?aiaiea no?ie. A iaiyoe eiiiuethoa?a no?iea o?aieony a aeaea
iineaaeiaaoaeueiinoe ec neiaieueiuo ia?aiaiiuo, o ieo iao
eiaeeaeaeoaeueiuo ei?i, ii anoue iiia?a, ia/eiathueany n 1). Ia?aae
ia?aui neiaieii no?iee eiaaony au? e ioeaaie, a eioi?ii o?aieony neiaie
n eiaeii, ?aaiui aeeeia no?iee. Iai aaniethoii aac?acee/ii, eaeea
neiaieu o?aiyony a aaeoao, iaoiaeyueony ca i?aaeaeaie eiioea no?iee.
?anniio?ei i?eia?. Ionoue no?iea s iauyaeaia eae string[9], oiaaea iinea
i?enaaeaaiey s:=’I?eaao’; iia aoaeao o?aieony a neaaeothuai aeaea:

Iiia? aaeoa 0 1 2 3 4 5 6 7 8 9

Niaea?aeeiia #6 ‘I’ ‘?’ ‘e’ ‘a’ ‘a’ ‘o’ ‘th’ ‘s’ ‘%’

Aeey oiai /oiau a i?ia?aiia iieo/eoue aeinooi e n-io neiaieo no?iee
eniieuecoaony caienue s[n]. Anee iiiaiyoue cia/aiea s[0] oi yoi
io?aceony ia aeeeia no?iee. A neaaeothuai i?eia?a ec no?iee ‘I?eaao’ iu
naeaeaai ‘I?eaao!’: s[0]:=#7; s[7]:=’!’;.

N?aaiaiea no?ie. No?iee n?aaieaathony iineaaeiaaoaeueii, ii neiaieai.
N?aaieaathony ia?aua neiaieu no?ie, anee iie ?aaiu — oi aoi?ua, e o. ae.
Anee ia eaeii-oi yoaia iiyaeeinue ?acee/ea a neiaieao, oi iaiueoae
aoaeao oa no?iea, a eioi?ie iaiueoee neiaie. Anee no?iee ia
?acee/aeenue, a caoai iaeia ec ieo caeii/eeanue, oi iia e n/eoaaony
iaiueoae. I?eia?u: ‘aiaian’‘naeieia’, ”Fri then writeln(‘Naaiaeiy auoiaeiie’);

if day=Mon then writeln(‘Ia/aeanue ?aai/ay iaaeaey’);

Eae au oaea caiaoeee cia/aiey ia?a/eneeiiai oeia iiaeii n?aaieaaoue, i?e
yoii iaiueoei n/eoaaony oi, eioi?ia iauyaeaii ?aiueoa (eaaaa) a
ii?aaeaeaiee oeia.

Aeey ia?aiaiiuo ia?a/eneyaiuo oeiia aiciiaeii i?eiaiaiea ooieoeee succ e
pred, iai?eia?, succ(Wed) aeaao Thu, Pred(Sun) aeaao Sat. Anee
iiiuoaoueny iaienaoue Pred(Mon) eee Succ(Sun), oi oaea ia yoaia i?iaa?ee
i?ia?aiiu eiiieeyoi?ii i?iecieaeao ioeaea.

O?aiaiea cia/aiee ia?a/eneyaiiai oeia ono?iaii aioo?e aeiaieueii i?inoi:
o?aiyony oeaeua /enea io 0 aei n, a iaoai neo/aa n=6. Nouanoaoao
ooieoeey Ord, eioi?ay iicaieyao iieo/eoue oi /enei, a aeaea eioi?iai
o?aieony eaeia-eeai cia/aiea ia?a/eneyaiiai oeia, iai?eia? Ord(Wed)
aeaao 2. I?e iaiaoiaeeiinoe iiaeii iieo/eoue cia/aiea ia?a/eneyaiiai
oeia ii aai /eneaiiiio i?aaenoaaeaieth, iai?eia?, Days(1) anoue Tue.
Iinea anaai neacaiiiai iiaeii caiaoeoue, /oi i?e n?aaiaiee aaee/ei
ia?a/eneyaiiai oeia a aeaenoaeoaeueiinoe n?aaieaathony eo ii?yaeeiaua
iiia?a (Ord).

I?eia? eniieueciaaiey ia?a/eneyaiuo oeiia:

Ionoue ei?aaeue iiaeao aeaeaaoueny oieueei ii /aou?ai iai?aaeaieyi: ia
naaa?, ia caiaae, ia tha e ia ainoie, oi anoue oaeouaa iai?aaeaiea
aeaeaeaiey ii?aaeaeyaony ia?aiaiiie oeia Directions = (North, West,
South, East);. Yoiio ei?aaeth iiaeii iiaeaaaoue i?eeacu neaaeothueo
oeiia: aia??ae, iacaae, aeaai, ai?aai, oi anoue ethaie i?eeac caaeaoue
ia?aiaiiie oeia Orders = (Ahead, Back, Left, Right);. Ionoue ei?aaeue
aeaeaaeny ii iai?aaeaieth d1, iinea /aai aio aeaee i?eeac p. I?ia?aiia
aeieaeia ii?aaeaeeoue, a eaeii iai?aaeaiee ei?aaeue aoaeao aeaeaaoueny
iinea auiieiaiey i?eeaca.

program Ship;

type Courses = (North, West, South, East);

Orders = (Ahead, Back, Left, Right);

var d1, d2: Courses;

p: Orders;

i: integer;

s: string;

begin

{Cai?aoeaaai o iieueciaaoaey eioi?iaoeeth i eo?na e i?eeaca}

writeln(‘Aaaaeeoa ia?aiia/aeueiue eo?n ei?aaey ‘);

write(‘(0-naaa?, 1-caiaae, 2-tha, 3-ainoie) ‘);

readln(i);

d1:=Courses(i);

writeln(‘Aaaaeeoa i?eeac, aeaiiue ei?aaeth ‘);

write(‘(0-i?yii, 1-iacaae, 2-aeaai, 3-ai?aai) ‘);

readln(i);

p:=Orders(i);

{Ii?aaeaeyai iiaue eo?n}

case p of

Ahead : d2:=d1;

Back : d2:=Courses((ord(d1)+2) mod 4);

Left : d2:=Courses((ord(d1)+1) mod 4);

Right : d2:=Courses((ord(d1)+3) mod 4);

{-1 – iaeuecy, oae eae (Ord(North)-1) mod 4 = -1}

end;

{Auaiaeei ?acoeueoao ia ye?ai}

case d2 of

North : s:=’naaa?’;

West : s:=’caiaae’;

South : s:=’tha’;

East : s:=’ainoie’;

end;

writeln(‘Oaia?ue ei?aaeue aeaeaeaony ia ‘+s);

readln;

end.

2. Ia?aie/aiiue oei

Yoio oei oaeaea ?anniio?ei ia i?eia?a. Ionoue a iaeioi?ie ia?aiaiiie
ioaeii o?aieoue oaeouaa /enei, oi anoue iiia? aeiy a ianyoea. A Oo?ai
Ianeaea iiaeii caaeaoue oei DaysInMonth = 1..31;. Ia?aiaiiua e eiinoaiou
yoiai oeia iiaoo i?eieiaoue oieueei oaeea cia/aiey, anee iiiuoaoueny
caaeaoue /oi-eeai ae?oaia, oi eiiieeyoi? auaeano ioeaeo. A ea/anoaa
a?aieoe iiaoo oiio?aaeyoueny e io?eoeaoaeueiua /enea, iai?eia?
Temperature=-60..50;

A ea/anoaa aaciaiai oeia (oi anoue oeia, ec eioi?iai auae?aaony
aeeaiacii cia/aiee) iiaoo eniieueciaaoueny ii/oe ana ii?yaeeiaua oeiu,
oi anoue oa, eioi?ua o?aiyony a aeaea oeaeuo /enae. E ii?yaeeiaui oeiai
ioiinyony: ana oeaeua oeiu (byte, integer, e o. i.), char, boolean,
ia?a/eneyaiua oeiu e ia?aie/aiiua oeiu. A ea/anoaa aaciaiai oeia iaeuecy
eniieueciaaoue eeoue nai ia?aie/aiiue oei (o?oaeii i?aaenoaaeoue, eae
yoi iiaeii naeaeaoue). N o/aoii yoiai i?aaeea aeiionoeiu oaeea
iauyaeaiey oeiia:

type SmallLatin = ‘a’..’z’; {iaeua eaoeineea aoeau}

MyBoolean = True..False; {oioy yoi e aanniuneaiii}

Holidays = Sat..Sun; {auoiaeiua}

Iaeuecy a ea/anoaa aaciaiai oeia oiio?aaeoue eaeie-eeai aauanoaaiiue
oei, neaaeothuaa iauyaeaiea i?eaaaeao e ioeaea:

type Wrong = -1.25..1.25;

Caiaoei, /oi ooieoeee Ord, Succ e Pred iiaoo i?eiaiyoueny e ethaui
ii?yaeeiaui oeiai, e, a /anoiinoe, e ia?aie/aiiui.

Eaeoeey 7. Ianneau

1. Iiiyoea ianneaa. Iaeiiia?iua ianneau

Ianneau yaeythony i?aaenoaaeoaeyie no?oeoo?e?iaaiiuo oeiia aeaiiuo, oi
anoue oaeeo, ia?aiaiiua eioi?uo ninoaaeaiu ec aieaa i?inouo yeaiaioia
niaeanii ii?aaeae?iiiio ii?yaeeo. Aeey ianneaia oa?aeoa?ii oi, /oi iie
yaeythony niaieoiiinoueth iaeioi?iai /enea iaeeiaeiauo yeaiaioia. A
i?inoaeoai neo/aa yoe yeaiaiou iiaoo auoue caioia?iaaiu iaoo?aeueiuie
/eneaie ec iaeioi?iai aeeaiaciia. ?anniio?ei i?eia? oaeie ia?aiaiiie a
Oo?ai Ianeaea:

var a: array [1..10] of real;

Ia?aiaiiay a ninoieo ec aeanyoe y/aae oeia real, iiaeii caienuaaoue e
ecaeaeaoue cia/aiey ec ieo, iieuecoynue caienueth a[].

I?eia? 1. Iiene iaeaieueoaai /enea n?aaee yeaiaioia ianneaa.

program FindMaximumInArray;

var a: array[1..10] of real;

i,max: integer;

begin

for i:=1 to 10 do begin

write(‘Aaaaeeoa yeaiaio iiia? ‘,i,’ -> ‘);

readln(a[i]);

end;

max:=a[1];

for i:=2 to 10 do

if a[i]>max then max:=a[i];

writeln(‘Iaeneioi ?aaai ‘,max);

readln;

end.

A ea/anoaa oeia yeaiaioia ianneaa iiaeii eniieueciaaoue ana oeiu,
ecaanoiua iai ia aeaiiue iiiaio (e iei ioiinyony ana /eneiaua,
neiaieueiue, no?ieiaue e eiae/aneee oeiu).

Ioia?iaaoue yeaiaiou ianneaia iiaeii ia oieueei io aaeeieoeu, ii e io
ethaiai oeaeiai /enea. Aiiaua aeey eiaeaenia ianneaia iiaeoiaeeo ethaie
ii?yaeeiaue oei, oi anoue oaeie, eioi?ue a iaiyoe iaoeiu i?aaenoaaeyaony
oeaeui /eneii. Aaeeinoaaiiia ia?aie/aiea ninoieo a oii, /oi ?acia?
ianneaa ia aeieaeai i?aauoaoue 64 Ea. ?anniio?ei iaeioi?ua i?eia?u
iauyaeaiey ianneaia.

var Numbers: array [0..1000] of integer;

Names: array [1..10] of string;

Crit: array[shortint] of boolean;

CountAll: array[char] of integer;

Count: array[‘a’..’z’] of integer;

A neaaeothuai i?eia?a iieacaii aeey /aai iiaeao iiiaaeiaeoueny
iineaaeiee oei.

I?eia? 2. Iiaen/ao eiee/anoaa ?acee/iuo aoea a no?iea.

program CountLetters;

var s: string;

count: array[‘a’..’z’] of byte;

ch: char;

i: byte;

begin

write(‘Aaaaeeoa no?ieo > ‘);

readln(s);

for i:=1 to length(s) do

if (s[i]>=’a’)and(s[i]0 then

writeln(ch,’: ‘,count[ch]);

readln;

end.

2. Iiiaiia?iua ianneau

I?e iaiaoiaeeiinoe iiaeii ioia?iaaoue ianneau ia iaeiei eiaeaenii a
aeaoiy e aieaa. Aeaoia?iiio ianneao niioaaonoaoao iao?eoea a iaoaiaoeea,
oi anoue i?yiioaieueiay oaaeeoea.

I?eia?u iienaiee iiiaiia?iuo ianneaia:

var Matrix: array[1..4,1..3] of real;

Cube3D: array[1..5,1..5,1..5] of integer;

?anniio?ei i?eia? eniieueciaaiey aeaoia?iiai ianneaa.

I?eia? 3. Iino?ieoue eaeaiaea?ue ia neaaeothuee aiae, oi anoue i?e
aaiaea iiia?a ianyoea e /enea auaeaaaoue aeaiue iaaeaee.

program Calendar;

type tWeekDay = (Mon,Tue,Wed,Thu,Fri,Sat,Sun,NoDay);

{NoDay – iao aeiy (iai?eia?, 30.02)}

tCalendar = array [1..12,1..31] of tWeekDay;

var CL: tCalendar;

m,d: byte; {ianyoe e /enei}

wd: tWeekDay; {aeaiue iaaeaee}

begin

{No?iei iannea:}

{1. Caiieiei aanue eaeaiaea?ue cia/aieyie “iao aeiy”:}

for m:=1 to 12 do

for d:=1 to 31 do CL[m,d]:=NoDay;

{2. No?iei iannea-eaeaiaea?ue:}

m:=1; d:=1;

wd:=Mon;

repeat

CL[m,d]:=wd;

case m of

4,6,9,11: if d=30 then begin m:=m+1; d:=1; end else d:=d+1;

1,3,5,7,8,10,12: if d=31 then begin m:=m+1; d:=1; end else d:=d+1;

2: if d=28 then begin m:=m+1; d:=1; end else d:=d+1;

end;

wd:=tWeekDay((ord(wd)+1) mod 7);

until m=13;

{Auaiaeei ia ye?ai:}

repeat

write(‘Iiia? ianyoea > ‘); readln(m);

write(‘*enei > ‘); readln(d);

case CL[m,d] of

Mon: writeln(‘Iiiaaeaeueiee’);

Tue: writeln(‘Aoi?iee’);

Wed: writeln(‘N?aaea’);

Thu: writeln(‘*aoaa?a’);

Fri: writeln(‘Iyoieoea’);

Sat: writeln(‘Noaaioa’);

Sun: writeln(‘Aine?anaiuea’);

NoDay: writeln(‘Oaeiai aeiy iao a eaeaiaea?a’);

end;

until false;

end.

3. Ni?oe?iaea e iiene

A i?eeeaaeiuo i?ia?aiiao oe?iei ?ani?ino?aiaiu aeaa oeia iia?aoeee,
naycaiiuo n ianneaaie:

Oii?yaei/eaaiea yeaiaioia ianneaa ii aic?anoaieth eee oauaaieth
(ni?oe?iaea)

Iiene yeaiaioa a ianneaa.

?anniio?ei i?inoaeoee aa?eaio ni?oe?iaee ianneaa (ni?oe?iaea auai?ii).
Ionoue anoue iannea ec n yeaiaioia; nia/aea iaeae?i a i?i naiue
iaeaiueeee n?aaee yeaiaioia n iiia?aie 2,3,…n e iiiaiyai ianoaie n
ia?aui yeaiaioii, caoai n?aaee yeaiaioia n iiia?aie 3,4,…n iaeae?i
iaeiaiueoee e iaiaiyai ni aoi?ui, e o. ae. A ?acoeueoaoa iao iannea
ieaaeaony ioni?oe?iaaiiui ii aic?anoaieth.

program SelectSort;

const n = 10;

var a: array [1..n] of integer;

i,j,jmin,buf: integer;

{jmin – iiia? iaeiaiueoaai yeaiaioa,

buf eniieuecoaony i?e iaiaia cia/aiee aeaoo yeaiaioia}

begin

for i:=1 to 10 do begin

write(‘Aaaaeeoa yeaiaio iiia? ‘,i,’ -> ‘);

readln(a[i]);

end;

for i:=1 to n-1 do begin

jmin:=i;

for j:=i+1 to n do

if a[j]999999)

then writeln(‘Ioeaea’);

end.

Caiaoei, /oi a yoii i?eia?a iinoiyiii i?eoiaeeony ia?auaoueny e iieyi
iaeiie e oie aea ia?aiaiiie oeia caienue, e, neaaeiaaoaeueii, iinoiyiii
ienaoue a? eiy. Anoue aiciiaeiinoue ecaaaeoueny io yoiai iaoaeianoaa. A
Oo?ai Ianeaea anoue iia?aoi? i?eniaaeeiaiey (with), eioi?ue iicaieyao
iaeei ?ac oeacaoue, eaeie caienueth iu iieuecoainy e a aeaeueiaeoai
ienaoue oieueei eiaia iieae. Iau/ii yoio iia?aoi? auaeyaeeo oae:

with do ;

*aua anaai a ea/anoaa iia?aoi?a eniieuecoaony ninoaaiie iia?aoi?.

I?eia?:

with p do begin

Surname:=’ Eaaiia’;

Name:=’Eaai’;

end;

Caiene iiaeii aeeth/aoue a ninoaa aieaa neiaeiuo ia?aiaiiuo, iai?eia?
ianneaia e ae?oaeo caienae. I?e iaiaoiaeeiinoe o?aiaiey eioi?iaoeee i
nio?oaeieeao iaeioi?ie i?aaiecaoeee iiaeao ieacaoueny iieaciui iannea:

const N = 30;

type tStaff = array [1..N] of tPerson;

?anniio?ei ae?oaie i?eia?, aaea eeethno?e?oaony eniieueciaaiea
aeiaeaiiuo caienae. Ionoue i?yiioaieueiee ii?aaeaeyaony eii?aeeiaoaie
oi/ee, yaeythuaeny aai eaaui aa?oiei oaeii, oe?eiie, aunioie e oeaaoii
eeiee. Ia Oo?ai Ianeaea yoe naaaeaiey iiaeii iauaaeeieoue a oaeoth
caienue:

type tPoint = record

x,y: integer;

end;

tRectangle = record

LeftTop: tPoint;

Width, Height: integer;

Color: integer;

end;

Aeey oaeie caiene iiaeii i?eiaiyoue au? iaeio oi?io iia?aoi?a with,
eioi?ay iiaeao «i?eniaaeeiyoue» ianeieueei ei?i caienae, iai?eia?:

var rect: tRect;

with rect, LeftTop do begin

x:=100;

y:=150;

Color:=11;

end;

Aac eniieueciaaiey with iiyaeeenue au au?aaeaiey aeaea rect.Color,
rect.LeftTop.x, rect.LeftTop.y e o. i.

Iieaaeai oaia?ue, eae iiaeii eniieueciaaoue ianneau aioo?e caienae.
I?aaeiieiaeei, /oi o?aaoaony o?aieoue eioi?iaoeeth oaea ia i
i?yiioaieueieea, a i i?iecaieueiii iiiaioaieueieea. A yoii neo/aa
iio?aaoaony caaeaoue eiee/anoai oi/ae a i?i e nienie anao yoeo oi/ae, oi
anoue iannea. O?aaoaony i?aaeoniio?aoue aiciiaeiinoue o?aiaiey naaaeaiee
i iiiaioaieueieeao n ?acee/iui /eneii aa?oei, iiyoiio naeaeaai iannea
aeiaieueii aieueoei, a ?aaeueiia /enei aa?oei aoaeai o?aieoue a
ioaeaeueiii iiea caiene. An? yoi aoaeao auaeyaeaoue neaaeothuei ia?acii:

const MaxVertex = 200;

type tPolygon = record

size: integer;

V: array [1..MaxVertex] of tPoint;

Color: tColor;

end;

Nouanoaoao ?aciiaeaeiinoue caienae, eioi?ay niaea?aeeo oae iacuaaaioth
aa?eaioioth /anoue. Aeey eo/oaai iiieiaiey ?anniio?ei eo ia i?eia?a.
Ionoue caienue aeieaeia o?aieoue iieioth eioi?iaoeeth i aaiiao?e/aneie
oeao?a: oeaao, iieiaeaiea e ?acia?u (aeey ie?oaeiinoe — eii?aeeiaou
oeaio?a e ?aaeeon, aeey i?yiioaieueieea — eii?aeeiaou eaaie aa?oiae e
i?aaie ieaeiae aa?oei, aeey eaaae?aoa — eii?aeeiaou eaaie aa?oiae
aa?oeiu e aeeeia noi?iiu). A i?eioeeia, iiaeii auei au aeeth/eoue a
caienue ana ia?a/eneaiiua auoa iiey, ii a oaeii neo/aa aieueoeinoai ec
ieo /anoi inoaaaeenue au iacaiyouie, iiyoiio oaeiaiaa aoaeao oaeia
?aoaiea:

type tFKind = (fCir,fRect,fSqr);

tFigure = record

Color: integer;

case kind: tFKind of

fCir: (Center: tPoint; r: integer);

fRect: (LeftTop,RightBottom: tPoint);

fSqr: (LT: tPoint; size: integer);

end;

A yoie caiene eiaaony iaeii iau/iia iiea (Color), a inoaeueiua 6 e
i?aaenoaaeytho niaie aa?eaioioth /anoue. Aeey ie?oaeiinoe a iae eiathony
iiey Center e r, aeey i?yiioaieueieea — LeftTop e RightBottom, aeey
eaaae?aoa — LT e size. O?aca kind: tFKind ia yaeyaony iaycaoaeueiie, iia
neoaeeo aeey iiieiaiey oiai, eaeea iiey e eaeei oeao?ai ioiinyony.
Iiaeii iaienaoue i?inoi case integer of … e ioia?iaaoue aa?eaiou
oeaeuie /eneaie. Caiaoei oaeaea, /oi a iauyaeaiee iaoae caiene iao neiaa
end, ioiinyuaainy e case.

Iu iiaeai ia?auaoueny e ethaiio iieth aa?eaioiie /anoe, iaeiaei neaaeoao
iiiieoue, /oi i?e caiene aeaiiuo a iiea aeey iaeiie oeao?u iiey aeey
ae?oaeo oeao? iiaoo eciaieoueny. *oiau iiiyoue, ii/aio oae i?ienoiaeeo,
aeinoaoi/ii ?anniio?aoue niinia o?aiaiey ia?aiaiiie oeia tFigure:

Ec ?enoiea aeaeii, /oi aa?eaioiay /anoue o?aieony a iaeiie /anoe iaiyoe,
oi anoue iiey iiaoo iaeeaaeuaaoueny ae?oa ia ae?oaa.

Eaeoeey 9. I?ioeaaeo?u e ooieoeee

I?ioeaaeo?a ( iineaaeiaaoaeueiinoue aeaenoaee (caienaiiuo ia Ianeaea),
iacaaiiay eaeei-eeai eiaiai. Aeey oiai /oiau auiieieoue yoo
iineaaeiaaoaeueiinoue, ioaeii a niioaaonoaothuai ianoa i?ia?aiiu
oeacaoue a? eiy (oae, iai?eia?, aeey i/enoee ye?aia i?e ?aaioa n
a?aoeeie iu oeacuaaai ClearDevice;). E?iia oiai, /oi i?ia?aiia
noaiiaeony i?e eniieueciaaiee i?ioeaaeo? ei?i/a e iiiyoiaa, i?ioeaaeo?u
iiaeii aucuaaoue ec ?aciuo iano i?ia?aiiu (a i?ioeaiii neo/aa i?eoeinue
au iiaoi?youe a oaenoa i?ia?aiiu iaeeiaeiaua iineaaeiaaoaeueiinoe
aeaenoaee ianeieueei ?ac).

Oa aeaenoaey, eioi?ua aoiaeyo a i?ioeaaeo?o, caienuaathony aei ia/aea
iniiaiie i?ia?aiiu a neaaeothuai aeaea:

program …

const …

type …

var …

procedure MyProc;

begin

{aeaenoaey}

end;

begin

{iniiaiay i?ia?aiia}

end.

?anniio?ei i?eia? iaoiaeaeaiey iaeneioia ec o??o /enae:

program Max1;

var a,b,c,m: integer;

begin

write(‘Aaaaeeoa a: ‘); readln(a);

write(‘Aaaaeeoa b: ‘); readln(b);

write(‘Aaaaeeoa c: ‘); readln(c);

if a>b then m:=a else m:=b;

if c>m then m:=c;

writeln(‘Iaeneioi = ‘,m);

readln;

end.

Ia?aieoai aai n eniieueciaaieai i?ioeaaeo?u:

program Max2;

var a,b,c,m: integer;

procedure FindMax;

begin

if a>b then m:=a else m:=b;

if c>m then m:=c;

end;

begin

write(‘Aaaaeeoa a: ‘); readln(a);

write(‘Aaaaeeoa b: ‘); readln(b);

write(‘Aaaaeeoa c: ‘); readln(c);

FindMax;

writeln(‘Iaeneioi = ‘,m);

readln;

end.

Yoio aa?eaio iiaeii oeo/oeoue. Iiea iaoa i?ioeaaeo?a iiaeao eneaoue
ieieioi oieueei n?aaee cia/aiee eiie?aoiuo ia?aiaiiuo a, b e c. Canoaaei
a? eneaoue ieieioi n?aaee ethauo o??o oeaeuo /enae e iiiauaoue
?acoeueoao a ioaeioth iai ia?aiaiioth, a ia anaaaea a m.

*oiau auea aeaeia iieueca io oaeie i?ioeaaeo?u, ?anniio?ei i?eia?
i?ia?aiiu aeey iienea iaeneioia n?aaee /enae a+b, b+c e a+c:

program Max3;

var a,b,c,m: integer;

procedure FindMax(n1,n2,n3: integer; var max: integer);

begin

if n1>n2 then max:=n1 else max:=n2;

if n3>max then max:=n3;

end;

begin

write(‘Aaaaeeoa a: ‘); readln(a);

write(‘Aaaaeeoa b: ‘); readln(b);

write(‘Aaaaeeoa c: ‘); readln(c);

FindMax(a+b,b+c,a+c,m);

writeln(‘Iaeneioi ec noii = ‘,m);

readln;

end.

A neiaeao iinea eiaie i?ioeaaeo?u (a a? iienaiee) caienaiu oae
iacuaaaiua ia?aiao?u. Yoa caienue iaicia/aao, /oi aioo?e i?ioeaaeo?u
iiaeii eniieueciaaoue oeaeua /enea, iaicia/aiiua n1, n2 e n3, a oaeaea
caiineoue cia/aiey a ia?aiaiioth oeia integer, eioi?ay aioo?e
i?ioeaaeo?u iacuaaaony max (a ?aaeueii ai a?aiy ?aaiou i?ia?aiiu ana
aeaenoaey i?iecaiaeyony iaae ia?aiaiiie m). Ia?aiao?u, a eioi?uo
o?aiyony /enea (n1,n2,n3) iacuaathony ia?aiao?aie-cia/aieyie; a oa,
eioi?ua iaicia/atho ia?aiaiiua (max) ( ia?aiao?aie-ia?aiaiiuie, ia?aae
ieie a iienaiee noaaeony neiai var. Ia?aiao?u, ia eioi?ua eiathony
nnueee aioo?e i?ioeaaeo?u (n1, n2, n3, max), iacuaathony oi?iaeueiuie, a
oa, eioi?ua ?aaeueii eniieuecothony i?e auciaa (a+b, b+c, a+c, m) —
oaeoe/aneeie.

I?ioeaaeo?u iineaaeiaai aeaea ieacuaathony aeinoaoi/ii oaeiaiuie. Iiaeii
iaeei ?ac iaienaoue oaeoth i?ioeaaeo?o, oaaaeeoueny a a?
?aaioiniiniaiinoe e eniieueciaaoue a ae?oaeo i?ia?aiiao. I?eia?aie oaeeo
i?ioeaaeo? yaeythony i?ioeaaeo?u aeey ?aaiou ni no?ieaie, ano?iaiiua a
Oo?ai-Ianeaeue.

A iaoai i?eia?a iiaeii ia?aienaoue i?ia?aiio e ii-ae?oaiio. Iaeneioi ec
o??o /enae ii?aaeaeyaony ii iei iaeiicia/ii, eee, aiai?y iaoaiaoe/aneei
ycueii, yaeyaony ooieoeeae yoeo o??o /enae. Iiiyoea ooieoeee anoue
oaeaea e a Ianeaea. ?anniio?ei oaeoth i?ia?aiio:

program Max4;

var a,b,c,m: integer;

function Max(n1,n2,n3: integer) : integer;

var m: integer;

begin

if n1>n2 then m:=n1 else m:=n2;

if n3>m then m:=n3;

Max:=m;

end;

begin

write(‘Aaaaeeoa a: ‘); readln(a);

write(‘Aaaaeeoa b: ‘); readln(b);

write(‘Aaaaeeoa c: ‘); readln(c);

writeln(‘Iaeneioi = ‘,Max(a+b,b+c,a+c));

readln;

end.

Iai oaea ecaanoii eae aucuaaoue ooieoeeth ec i?ia?aiiu (iai?eia? sqrt,
sin e o. i.). ?anniio?ei iienaiea ooieoeee. Iii i/aiue iioiaea ia
iienaiea i?ioeaaeo?, ii anoue aeaa ioee/ey:

Iinea eiaie ooieoeee e nienea ia?aiao?ia (anee anoue) /a?ac aeaiaoi/ea
caienuaaaony oei cia/aiey ooieoeee (aiciiaeiu ia oieueei /eneiaua oeiu,
ii e eiae/aneea, no?ieiaua, neiaieueiua);

N?aaee iia?aoi?ia a oaea ooieoeee iaeaieaa aaaeiuie yaeythony iia?aoi?u
i?enaaeaaiey cia/aiey ooieoeee (a iaoai neo/aa yoi no?i/ea Max:=m;).

A caienaiiie auoa ooieoeee eniieuecoaony oae iacuaaaiay eieaeueiay
ia?aiaiiay m, oi anoue ia?aiaiiay, eioi?ay «aeaeia» oieueei iaoae
ooieoeee, a ae?oaea i?ioeaaeo?u e ooieoeee, a oaeaea aeaaiay i?ia?aiia
a? «ia aeaeyo». E?iia eieaeueiuo ia?aiaiiuo a Oo?ai-Ianeaea iiaeii
ii?aaeaeyoue eieaeueiua eiinoaiou e oeiu.

I?eaaae?i ae?oaea i?eia?u i?ioeaaeo? e ooieoeee.

.

function Cube(x: real): real;

begin

Cube:=x*x*x;

end;

, aaea p ( iieoia?eiao? o?aoaieueieea, a, b, c ( aeeeiu noi?ii.

function Square(a,b,c: real): real;

var p: real;

begin

p:=(a+b+c)/2;

Square:=sqrt(p*(p-a)*(p-b)*(p-c));

end;

I?ioeaaeo?a aeey ?aoaiey eaaae?aoiiai o?aaiaiey. Aoaeai ia?aaeaaaoue
yoie i?ioeaaeo?a eiyooeoeeaiou o?aaiaiey, a ?acoeueoaou naiae ?aaiou iia
aoaeao auaeaaaoue a o??o ia?aiao?ao-ia?aiaiiuo. *a?ac ia?aoth,
eiae/aneiai oeia, i?ioeaaeo?a niiaueo, anoue ee aauanoaaiiua ei?ie, a
aua a aeaoo iia auaeano naie yoe ei?ie (anee ei?iae iao, oi ia yoe aeaa
ia?aiaiiua iieueciaaoaeue iaoae i?ioeaaeo?u iiaeao ia ia?auaoue
aieiaiey).

procedure SqEquation(a,b,c: real; var RootsExist: boolean;

var x1,x2: real);

var d: real;

begin

d:=sqr(b)-4*a*c;

if d>=0 then begin

RootsExist:=true;

x1:=(-b+sqrt(d))/(2*a);

x2:=(-b-sqrt(d))/(2*a);

end

else RootsExist:=false;

end;

Iiaeii aianoi i?ioeaaeo?u iaienaoue e ooieoeeth, ii eiae/aneiio
cia/aieth eioi?ie iu ii?aaeaeyai, anoue ee ei?ie, a naie ei?ie
ia?aaeathony oaeaea eae e a i?ioeaaeo?a:

function EqHasRoots(a,b,c: real; var x1,x2: real) : boolean;

var d: real;

begin

d:=sqr(b)-4*a*c;

if d>=0 then begin

EqHasRoots:=true;

x1:=(-b+sqrt(d))/(2*a);

x2:=(-b-sqrt(d))/(2*a);

end

else EqHasRoots:=false;

end;

Eniieueciaaoue oaeoth ooieoeeth aeaaea i?iua /ai iineaaeithth
i?ioeaaeo?o:

if EqHasRoots(1,2,1,r1,r2) then writeln(r1,’ ‘,r2) else writeln(‘Iao
ei?iae’);

Eaeoeey 10. Iiaeoeue CRT

Iiaeoeue CRT – iaai? n?aaenoa aeey ?aaiou n ye?aiii a oaenoiaii ?aaeeia,
eeaaeaoo?ie e aeey oi?aaeaiey caoeii. Aeey oiai /oiau eniieueciaaoue yoe
n?aaenoaa o?aaoaony iinea caaieiaea i?ia?aiiu caienaoue: uses CRT;.

1. Oi?aaeaiea ye?aiii

A oaenoiaii ?aaeeia ye?ai i?aaenoaaeyaony ?acaeoui ia iaeaiueeea
i?yiioaieueieee iaeeiaeiaiai ?acia?a, a eaaeaeii ec eioi?uo iiaeao
iaoiaeeoueny eaeie-eeai neiaie ec iaai?a ASCII. Aeey neiaieia iiaeii
caaeaaaoue oeaao naiiai neiaiea e oeaao i?yiioaieueieea, a eioi?ii ii
?enoaony (oeaao oiia). No?iee ye?aia ioia?othony naa?oo aiec, a noieaoeu
neaaa iai?aai, ioia?aoeey e no?ie, e noieaoeia ia/eiaaony n aaeeieoeu.

Iaeaieaa ?ani?ino?ai?iiui a ianoiyuaa a?aiy yaeyaony oaenoiaue ?aaeei
80×25 i?e 16 aiciiaeiuo oeaaoao oaenoa e oiia. Iiiaea a?aoe/aneea
aaeaioa?u iicaieytho eniieueciaaoue ae?oaea ?aaeeiu, iai?eia?: 40×25,
80×43, 80×50 e o. ae.

A oi?aaeaiee oaenoiaui ye?aiii aaaeioth ?ieue ea?aao eo?ni?. Auaiae
neiaieia ia ye?ai (o.a. write e writeln) inouanoaeyaony ia/eiay n
iiceoeee eo?ni?a, eiaaea ana neiaieu auaaaeaiu, eo?ni? inoaiaaeeaaaony a
neaaeothuae iiceoeee iinea iineaaeiaai neiaiea. Aaiae oaeaea aoaeao
i?iecaiaeeoueny ia/eiay n iiceoeee eo?ni?a.

Ieaea i?eaaaeaiu iniiaiua i?ioeaaeo?u e ooieoeee aeey oi?aaeaiey ye?aiii
a oaenoiaii ?aaeeia.

Iacaaiea Iacia/aiea

InsLine Anoaaeoue no?ieo a oii ianoa aaea iaoiaeeony eo?ni?, ana no?iee
ieaea eo?ni?a naeaeaathony aiec ia iaeio iiceoeeth. Eo?ni? inoa?ony ia
oii aea ianoa.

DelLine Oaeaeeoue no?ieo a iiceoeee eo?ni?a. Eo?ni? inoa?ony ia oii aea
ianoa.

GotoXY(x,y: byte) Ia?aianoeoue eo?ni? a iiceoeeth (x,y); x — iiia?
no?iee, y — iiia? noieaoea.

ClrEOL I/enoeoue no?ieo io eo?ni?a e aei i?aaiai e?ay ye?aia. Eo?ni?
inoa?ony ia i?aaeiai ianoa

HighVideo Onoaiaaeeaaao iiauoaiioth y?einoue aeey auaiaea oaenoa

LowVideo Iiieaeaiiay y?einoue

NormVideo Ii?iaeueiay y?einoue

TextColor(color: byte) Onoaiaaeeaaao oeaao aeey auaiaea oaenoa. Cia/aiey
oeaaoia — iau/ii /enea io 0 aei 15. Aianoi yoeo /enae iiaeii oeacuaaoue
e nouanoaothuea eiinoaiou (black, white, red, green, blue, magenta,
cyan, brown, lightgray e o. i.). I?e iaiaoiaeeiinoe iiaeii canoaaeoue
oaeno ia?oeaoue i?eaaaeyy e iiia?o oeaaoa /enei 128 eee eiinoaioo Blink.

TextBackGround(color: byte) Onoaiaaeeaaao oeaao aeey oiia.

ClrScr I/enoeoue ye?ai e iiianoeoue eo?ni? a eaaue aa?oiee oaie, o.a. a
iiceoeeth (1,1) — 1-y no?iea, 1-e noieaaoe. I?e i/enoea ye?ai
caiieiyaony oeaaoii oiia (ni. TextBackground)

WhereX: byte Yoa ooieoeey aica?auaao iiia? no?iee, a eioi?ie iaoiaeeony
eo?ni?.

WhereY: byte Iiia? noieaoea, a eioi?ii iaoiaeeony eo?ni?

2. ?aaioa n eeaaeaoo?ie

I?e ?aaioa n eeaaeaoo?ie eiiiuethoa? iiiauaao anth eioi?iaoeeth i
iaaeaoee eeaaeo a i/a?aaeue aei oao ii?, iiea yoa eioi?iaoeey ia
iio?aaoaony i?ia?aiia (iai?eia?, aeey auaiaea ia ye?ai, aeey aeaeaeaiey
iauaeoia a ea?ao e o.i.). Aeey ?aaiou n eeaaeaoo?ie aaaeiu 2 ooieoeee:

KeyPressed: boolean — aica?auaao true, anee i/a?aaeue eeaaeaoo?u ia
ionoa (oi anoue auea iaaeaoa). I?inoaeoee i?eia? eniieueciaaiey —
iiaoi?youe eaeea eeai aeaenoaey, iiea ia iaaeaoa eeaaeoa: repeat …
until KeyPressed;.

ReadKey: char — aica?auaao neiaie, niioaaonoaothuee iaaeaoie eeaaeoa (ec
i/a?aaee eeaaeaoo?u). Anee iieueciaaoaeue iaaeae eeaaeoo, aeey eioi?ie
eiaaony eiae ASCII, oi a i/a?aaeue aoaeao iieiaeai iaeei
niioaaonoaothuee neiaie, a anee yoi niaoeeaeueiay eeaaeoa (F1, F2, …
F12, eeaaeoe oi?aaeaiey eo?ni?ii, Ins, Del, Home, End, PgUp, PgDn), oi
nia/aea a i/a?aaeue aoaeao iieiaeai neiaie n eiaeii 0, a caoai
aeiiieieoaeueiue neiaie. Anee i/a?aaeue eeaaeaoo?u ionoa, oi Readkey
aoaeao aeaeaoue, iiea iieueciaaoaeue ia iaaei?o eaeoth-eeai eeaaeoo.

Aeey aeaiiino?aoeee ?aaiou ReadKey iiaeii iaienaoue oaeoth i?ia?aiio:

uses Crt;

var c: char;

begin

repeat

c:=ReadKey;

writeln(ord(c));

until c=#27 {eeaaeoa Escape};

end.

I?e iaaeaoee auoaia?a/eneaiiuo niaoeeaeueiuo eeaaeo yoa i?ia?aiia aoaeao
auaiaeeoue ii aeaa eiaea n?aco.

3. Ae?oaea aiciiaeiinoe

I?e iaiaoiaeeiinoe i?aaiecaoeee caaea?aeae a i?ia?aiia iiaeii
eniieueciaaoue i?ioeaaeo?o Delay(time: word). Ia?aiao? time — a?aiy a
ieeeenaeoiaeao, ia eioi?ia ioaeii i?einoaiiaeoue i?ia?aiio.

Au? iaeia aiciiaeiinoue iiaeoey CRT — ?aaioa n nenoaiiui aeeiaieeii.
Aeey aeeth/aiey caoea ioaeia i?ioeaaeo?a Sound(f: word) (f — /anoioa a
aa?oeao). Iinea aeeth/aiey o?aaoaony caaea?aeea (Delay) ia iaiaoiaeeiia
a?aiy cao/aiey, caoai — aueeth/aiea n iiiiuueth NoSound. Anee ia
ainiieueciaaoueny NoSound, oi caoe aoaeao neuoai aeaaea iinea auoiaea ec
i?ia?aiiu ia Ianeaea.

Eaeoeey 11. A?aoeea a Oo?ai Ianeaea

A ioee/ea io oaea ciaeiiiai oaenoiaiai ?aaeeia, ye?ai a a?aoe/aneii
?aaeeia ?acaeo ia aieueoia eiee/anoai oi/ae, eaaeaeay ec eioi?uo iiaeao
eiaoue ii?aaeae?iiue oeaao. Oi/ee n/eoathony iaeeiaeiauie e
i?yiioaieueiuie, ana iie ieioii «oeiaeaiu» ia ye?aia, oi anoue aeey
ethaie oi/ee iiaeii oeacaoue, a eaeie no?iea e a eaeii noieaoea iia
iaoiaeeony. Iiia?a no?ie e noieaoeia a a?aoe/aneii ?aaeeia
eniieuecothony eae eii?aeeiaou oi/ee, neaaeiaaoaeueii, eii?aeeiaou
anaaaea oeaei/eneaiiua. A a?aoe/aneii ?aaeeia ia/aei eii?aeeiao
iaoiaeeony a eaaii aa?oiai oaeo ye?aia, inue x iai?aaeaia ai?aai, inue y
iai?aaeaia aiec.

Caiaoei, /oi nouanoaotho ?aciua a?aoe/aneea ?aaeeiu, iie ioee/athony
eiee/anoaii oi/ae ii ai?eciioaee e aa?oeeaee (?ac?aoaieai), a oaeaea
eiee/anoaii aiciiaeiuo oeaaoia, iai?eia?: 320x200x16, 640x480x16,
640x200x16, 800x600x256 e o. i.

Ana n?aaenoaa aeey ?aaiou n a?aoeeie niaea?aeaoueny a noaiaea?oiii
iiaeoea Graph, iiyoiio aai ioaeii aoaeao oiiieiaoue iinea neiaa uses.

1. Aeeth/aiea e aueeth/aiea a?aoe/aneiai ?aaeeia.

Aeey aeeth/aiey a?aoe/aneiai ?aaeeia eniieuecoaony i?ioeaaeo?a
InitGraph(driver,mode,path) iieoai iacia/aiea a? ia?aiao?ia:

driver ( ia?aiaiiay oeia integer, a eioi?ii caaea?ony oei
aeaeaiaaeaioa?a, onoaiiaeaiiiai a eiiiuethoa?a. A iiaeoea ii?aaeaeaiu
eiinoaiou aeey ?acee/iuo aaeaioa?ia, eioi?ua ecaaaeytho ian io
iaiaoiaeeiinoe caiiieiaoue /enea. Eiathony oaeea eiinoaiou: CGA, EGA,
EGA64, EGAMono, VGA, MCGA, IBM8514 e o. i. Aeey ian iaeaieaa aaaeiie
aoaeao eiinoaioa detect, i?e oeacaiee eioi?ie InitGraph naia iiaeuuao
iaeaieaa iiuiue oei aaeaioa?a, niaianoeiue n oai aaeaioa?ii, eioi?ue
onoaiiaeai ia eiiiuethoa?a.

mode ( oaeaea ia?aiaiiay oeia integer, caaea?o ?aaeei, a eioi?ii
?aaioaao aua?aiiue aeaeaiaaeaioa? (caeanue oaeaea ii?aaeaeaiu
eiinoaiou). Ii/oe eaaeaeue aeaeaiaaeaioa? iiaeao ?aaioaoue a ianeieueeeo
?aaeeiao, iai?eia?, o VGA anoue 640x200x16 (VGALo), 640x350x16 (VGAMed),
640x480x16 (VGAHi). Anee a ia?aii ia?aiao?a auei oeacaii cia/aiea
detect, oi InitGraph ia ia?auaao aieiaiey ia mode, a onoaiaaeeaaao
iaeeo/oee, ia a? acaeyae, ?aaeei.

path ( no?ieiaue ia?aiao?. Aeey eaaeaeiai aeaeaiaaeaioa?a (eee aeey
a?oiiu noiaeiuo aeaeaiaaeaioa?ia) nouanoaoao i?ia?aiia-ae?aeaa?, n
iiiiuueth eioi?ie iiaeoeue Graph iauaaony n aeaeaiaaeaioa?ii. Oaeea
ae?aeaa?u o?aiyony a oaeeao n ?anoe?aieai «bgi». A ia?aiao?a path
oeacuaaaony eaoaeia, a eioi?ii o?aiyony ae?aeaa?u. Anee iie iaoiaeyony a
oaeouai eaoaeiaa, oi yoio ia?aiao? ?aaai ionoie no?iea.

Iau/ii aeey aeeth/aiey a?aoeee iu aoaeai eniieueciaaoue InitGraph a
oaeii aeaea:

const gpath = ‘Y:\WIN_APPS\BP\BGI’

var gd,gm: integer;

begin

gd:=Detect;

InitGraph(gd,gm,gpath);

Aeey caaa?oaiey ?aaiou n a?aoeeie e auoiaea a oaenoiaue ?aaeei
eniieuecoaony i?ioeaaeo?a CloseGraph.

2. Iino?iaiea yeaiaioa?iuo ecia?aaeaiee

Nenoaia eii?aeeiao i?e ?aaioa n a?aoeeie eiaao ia/aei (oi/eo (0,0)) a
eaaii aa?oiai oaeo ye?aia. Inue x iai?aaeaia ai?aai, inue y ( aiec.
I/aaeaeii, /oi ana oi/ee ye?aia eiatho oeaei/eneaiiua eii?aeeiaou.

I?e iino?iaiee i?inoaeoeo yeaiaioia ecia?aaeaiee eniieuecothony
neaaeothuea i?ioeaaeo?u e ooieoeee:

Iacaaiea Iacia/aiea

PutPixel(x,y: integer; c: word); Iinoaaeoue oi/eo (x,y), eniieuecoy
oeaao c. Cia/aiea oeaaoa iau/ii iaiyaony io 0 aei 15, aianoi iiia?a
oeaaoa iiaeii oiio?aaeyoue oeaaoiaua eiinoaiou iiaeoey Graph.

SetColor(c: word); Onoaiiaeoue oaeouee oeaao aeey ?eniaaiey io?aceia,
ie?oaeiinoae e o. i. Ana eeiee iinea oiio?aaeaiey yoiai iia?aoi?a aoaeoo
?eniaaoueny onoaiiaeaiiui oeaaoii.

SetBkColor(c: word); Onoaiiaeoue oaeouee oeaao aeey oiia (oi anoue oeaao
anaai ye?aia).

GetMaxX; GetMaxY; Yoe ooieoeee aica?auatho iaeneiaeueiua aeiionoeiua
cia/aiey eii?aeeiao x e y, niioaaonoaaiii.

Line(x1,y1,x2,y2: integer); ?eniaaoue io?acie ec (x1,y1) a (x2,y2)
oaeouei oeaaoii.

Rectangle(x1,y1,x2,y2: integer); ?enoao oaeouei oeaaoii i?yiioaieueiee,
eaaue oaie eioi?iai ( (x1,y1), a i?aaue ieaeiee ( (x2,y2).

Circle(x,y: integer; r: word); ?enoao oaeouei oeaaoii ie?oaeiinoue n
oeaio?ii a oi/ea (x,y) ?aaeeona r.

Arc (x,y: integer; a1,a2,r: word); ?enoao aeoao ie?oaeiinoe. a1 e a2 (
ia/aeueiue e eiia/iue oaeu (a a?aaeonao), niioaaonoaaiii. Oaie
ion/eouaaaony o?aaeeoeeiiii, i?ioea /aniaie no?aeee, oaie aaee/eiie 0(
niioaaonoaoao eo/o y=0, x>0.

Ellipse(x,y: integer; a1,a2,xr,yr: word); ?enoao aeoao yeeeina n
iieoinyie xr e yr io oaea a1 aei a2.

DrawPoly(n: word; P); ?enoao iiiaioaieueiee, eiee/anoai noi?ii a eioi?ii
( n, a eioi?iaoeey i aa?oeiao o?aieony a iaoeiece?iaaiiii ia?aiao?a P. A
ea/anoaa P oaeiaiaa anaai eniieueciaaoue iannea ec caienae, eaaeaeay ec
eioi?uo niaea?aeeo iiey x,y: integer;

MoveTo(x,y: integer); Yoa i?ioeaaeo?a iie?aaony ia iiiyoea oaeouae
iiceoeee. Iia «caiiieiaao» iiceoeeth (x,y) ia ye?aia, a a aeaeueiaeoai
ec yoie iiceoeee iiaeii ?eniaaoue io?acee.

LineTo(x,y: integer); ?enoao io?acie ec oaeouae iiceoeee a oi/eo (x,y).
I?e yoii oaeouay iiceoeey ia?aiauaaony a eiiaoe ia?eniaaiiiai io?acea.

MoveRel(dx,dy: integer); Ia?aiauaao oaeouee oeacaoaeue ec i?aaeiaai
iieiaeaiey (x,y) a oi/eo (x+dx,y+dy).

LineRel(dx,dy: integer); Oi aea, /oi e i?aaeuaeouay i?ioeaaeo?a, ii i?e
ia?aiauaiee ?enoao io?acie io (x,y) aei (x+dx,y+dy).

GetX; GetY; Aica?auatho eii?aeeiaou oaeouaai oeacaoaey (ii
ioaeaeueiinoe).

ClearDevice; I/euaao ye?ai.

Ana i?eaaae?iiua auoa i?ioeaaeo?u aeey ?eniaaiey auiieiytho oieueei
eiioo?iua ?enoiee (ia cae?aoeaay i?yiioaieueiee, ie?oaeiinoue eee yeeein
aioo?e). Ii oiie/aieth ?eniaaiea i?ienoiaeeo n eniieueciaaieai oiieie
nieioiie eeiee, iaeiaei oieueio e aeae eeiee iiaeii iaiyoue n iiiiuueth
i?ioeaaeo?u SetLineStyle(style,pattern,width: word). ?anniio?ei
iacia/aiea ia?aiao?ia yoie i?ioeaaeo?u.

style ( aeae eeiee. Caeanue oaeiaii caaeaaaoue ia eiie?aoiua /enea, a
eiinoaiou: SolidLn, DottedLn, CenterLn, DashedLn, UserBitLn. Ia?aay
iaicia/aao nieioioth eeieth, neaaeothuea o?e ( ?aciua aeaeu i?a?uaenouo
eeiee, iineaaeiyy ( eeieth, aeae eioi?ie ii?aaeaeyaony iieueciaaoaeai
(ni. ieaea).

pattern ( ia?acaoe aeey aeaea eeiee, ii?aaeaeyaiiai iieueciaaoaeai. Yoio
ia?aiao? anooiaao a aeaenoaea eeoue oiaaea, eiaaea a i?aaeuaeouai
oeacaii UserBitLn. Ia?acaoe ( yoi o?aaiaio eeiee, caaeaiiue a aeaea
/enea. Ia?aoiae io eiie?aoiiai o?aaiaioa e /eneo auiieiyaony, iai?eia?,
oae:

Oaeiaiaa anaai ia?aaiaeeoue iieo/aiiia /enei a oanoiaaeoeaoa?e/iue aeae,
a iaoai i?eia?a iieo/eony $999C. I?e ecia?aaeaiee eeiee caeiaee?iaaiiue
iaie o?aaiaio aoaeao iiaoi?youeny noieueei ?ac, neieueei ioaeii.

width ( oieueia eeiee. Iiaeii eniieueciaaoue /enea, iaeiaei ii?aaeaeaiu
2 eiinoaiou: NormWidth e ThickWidth (ii?iaeueiay e oienoay eeiee).

Ia?aeae?i oaia?ue e ?eniaaieth cae?aoaiiuo oeao?. Ii oiie/aieth
aioo?aiiyy iaeanoue oeao?u aoaeao cae?aoeaaoueny aaeui oeaaoii, i?e/?i
cae?anea aoaeao nieioiie. Aeey oi?aaeaiey oeaaoii e aeaeii cae?anee
eniieuecoaony i?ioeaaeo?a SetFillStyle(style, color: word); Oaeaea eae e
aeey noeey eeiee, aeey style i?aaeoniio?aiu eiinoaiou: EmptyFill,
SolidFill, LineFill, LtSlashFill, SlashFill, BkSlashFill, LtBkSlashFill,
HatchFill, XHatchFill, InterleaveFill, WideDotFill, CloseDotFill,
UserFill. Ia?aay iaicia/aao ionoonoaea cae?anee, aoi?ay ( nieioioth,
iineaaeothuea ( ?acee/iua niaoeeoe/aneea aeaeu cae?anee, naiay
iineaaeiyy ( cae?aneo, caaeaaaaioth iieueciaaoaeai. *oiau caaeaoue
iieueciaaoaeueneee ia?acaoe cae?anee, ioaeii eniieueciaaoue i?ioeaaeo?o
SetFillPattern(Pattern: FillPatternType; Color: Word); FillPatternType
ii?aaeaeyaony eae array[1..8] of byte, eaaeaeue yeaiaio ianneaa
eiaee?oao iaeio no?i/eo ia?acoea cae?anee (eae e aeey eeiee), a anaai
oaeeo no?i/ae 8. A ?acoeueoaoa cae?anea auiieiyaony n iiiiuueth
iaeeiaeiauo eaaae?aoeeia 8×8.

Ieaea i?eaiaeyony i?ioeaaeo?u ?eniaaiey cae?aoaiiuo oeao?.

Iacaaiea Iacia/aiea

Bar(x1,y1,x2,y2: integer); ?enoao cae?aoaiiue i?yiioaieueiee.

FillEllipse(x,y: integer; xr,yr: word); Cae?aoaiiue yeeein.

FillPoly(n: word; P); Cae?aoaiiue iiiaioaieueiee.

PieSlice(x,y: integer; a1,a2,r: word); Cae?aoaiiue e?oaiaie naeoi?.

Sector (x,y: integer; a1,a2,xr,yr: word); Cae?aoeaaao yeeeioe/aneee
naeoi?.

FloodFill(x,y: integer; Cborder: word); Aueeaaao e?aneo a oi/eo (x,y),
ioeoaea iia ?anoaeaaony ai ana noi?iiu, iiea ia aeinoeaiao a?aieoeu
oeaaoa Cborder. Anee oaeie a?aieoeu iao eee iia iacaieiooa, oi e?anea
iiaeao caeeoue aanue ye?ai.

3. Auaiae oaenoiaie eioi?iaoeee.

Aeey auaiaea oaenoa ia ye?ai eniieuecothony aeaa i?ioeaaeo?u:

OutText(s: string). Yoa i?ioeaaeo?a auaiaeeo no?ieo s ia/eiay n oaeouae
iiceoeee, oi anoue eaaue aa?oiee oaie auaiaeeiie no?iee iaoiaeeony a
oaeouae iiceoeee (ii oiie/aieth yoi oae). Oaeouay iiceoeey caaea?ony,
iai?eia?, n iiiiuueth MoveTo.

OutTextXY(x,y: integer; s: string). Eniieuecoaony aeey auaiaea no?iee a
eiie?aoiie iiceoeee.

Anee o?aaoaony auaanoe eaeea eeai /enea, oi i?aaeaa?eoaeueii o?aaoaony
i?aia?aciaaoue eo a no?ieo, iai?eia?, n iiiiuueth i?ioeaaeo?u Str.

I?eia?:

var r: integer;

s: string;

……………

Str(r,s);

OutTextXY(100,200,’?acoeueoao=’+s);

Oo?ai Ianeaeue iicaieyao eniieueciaaoue ianeieueei ?acee/iuo o?eooia
aeey auaiaea oaenoa. E?iia oiai, iiaeii iaiyoue iai?aaeaiea auaiaea
oaenoa, a oaeaea ?acia? neiaieia. A yoeo oeaeyo eniieuecoaony
i?ioeaaeo?a SetTextStyle(Font, Direction, CharSize : word). Ia?a/eneei
aiciiaeiua eiinoaiou e cia/aiey aeey ia?aiao?ia yoie i?ioeaaeo?u.

Font (o?eoo):

DefaultFont ( o?eoo 8×8 (ii oiie/aieth)

TriplexFont ( iieoaee?iue o?eoo

SmallFont ( oiieee o?eoo

SansSerifFont ( o?eoo aac cana/ae

GothicFont ( aioe/aneee o?eoo.

Direction (i?eaioaoeey e iai?aaeaiea auaiaea neiaieia):

0 ( i?eau/iue auaiae neaaa iai?aai

1 ( nieco aaa?o (iaaeienue «iieiaeaia ia aie»)

2 ( neaaa iai?aai, ii «eaaea/eie» aoeaaie.

Size ( ?acia? o?eooa (oeaeua /enea io 0 aei 10).

Ae?oaay aiciiaeiinoue i?e ?aaioa n oaenoii ( yoi au?aaieaaiea aai
ioiineoaeueii caaeaaaaiuo eii?aeeiao auaiaea. Aeey yoiai eniieuecoaony
i?ioeaaeo?a SetTextJustify(horiz,wert: word). Horiz oeacuaao eae oaeno
?aniieiaeai ioiineoaeueii caaeaiiie iiceoeee ii ai?eciioaee, a vert ( ii
aa?oeeaee. Aiciiaeiua eiinoaiou:

aeey horiz:

LeftText ( oeacaiiay iiceoeey yaeyaony eaaui e?aai no?iee

CenterText ( iiceoeey yaeyaony na?aaeeiie auaiaeeiie no?iee

RightText ( i?aaui e?aai no?iee;

aeey vert:

BottomText ( iiceoeey iaoiaeeony ia ieaeiai e?aa ecia?aaeaiey

CenterText ( ii oeaio?o

TopText ( iiceoeey yaeyaony aa?oiei e?aai ecia?aaeaiey.

Eaeoeey 12. Oaenoiaua oaeeu

Ieaea aoaeoo ianoaeaeaoueny niiniau acaeiiaeaenoaey i?ia?aiiu ia Ianeaea
n oaenoiauie oaeeaie, caienaiiuie ia eaeii-eeai aeenea. I?eia?aie
oaenoiauo oaeeia iiaoo neoaeeoue oaenou i?ia?aii ia Ianeaea, i?inoua
oaenoiaua aeieoiaiou e o.i.

Ethaie oaeno a oaeea o?aieony a aeaea iineaaeiaaoaeueiinoe neiaieia
(char), aeey ?acaeaiey oaenoa ia no?iee eniieuecothony iaaeaeeiua i?e
i?iniio?a neiaieu eiioea no?iee.

1. Iauyaeaiea oaeeiaie ia?aiaiiie e i?eaycea e oaeeo ia aeenea

Aeey oiai /oiau i?ia?aiia iiaea ?aaioaoue n oaenoiaui oaeeii, iai
iio?aaoaony ia?aiaiiay niaoeeaeueiiai oaeeiaiai oeia text:

var f: text;

Yoa ia?aiaiiay ia niaea?aeeo a naaa aanue oaeno ec oaeea, iia neoaeeo
aeey /oaiey aeaiiuo ec oaeea e aeey caiene iiauo aeaiiuo a iaai.

I?aaeaea /ai ?aaioaoue n eiie?aoiui oaeeii ia aeenea, oaeeiaoth
ia?aiaiioth neaaeoao naycaoue n yoei oaeeii, eniieuecoy oaeoth
i?ioeaaeo?o:

assign(TxtFile: text, name: string);

Ia?aue ia?aiao? (TxtFile) — oaeeiaay ia?aiaiiay, aoi?ie — no?iea,
niaea?aeauay eiy oaeea ia aeenea. Anee oaee eaaeeo a oaeouai eaoaeiaa,
oi aeinoaoi/ii oeacaoue oieueei aai eiy e ?anoe?aiea, anee a eaeii-eeai
ae?oaii, oi iio?aaoaony oeacuaaoue iooue e yoiio oaeeo, iai?eia?:

assign(f,’Z:\SCHOOL\text1.txt’);

2. *oaiea aeaiiuo ec oaeea

Ia?aae oai eae ?anniao?eaaoue i?ioeaaeo?u /oaiey, caiaoei /oi oaee
iiaeii iaoiaeeoue oieueei iineaaeiaaoaeueii. Oi?ioae aiaeiaeae oaeea
iiaeao iineoaeeoue iaaieoiay eaioa, n eioi?ie aieiaea iiaeao /eoaoue
eioi?iaoeeth oieueei ii ii?yaeeo, a aeey aica?aoa e ia/aeo aeiea aeaiiuo
o?aaoaony aeiiieieoaeueiia oneeea (ia?aiioea).

*oiau ioe?uoue aeey /oaiey oaee, eioi?ue aue oeacai i?e auciaa assign,
ioaeii eniieueciaaoue i?ioeaaeo?o

reset(TxtFile: text);

Iinea oaeiai aeaenoaey «/eoathuay aieiaea» aoaeao onoaiiaeaia ia ia/aei
oaeea. ?acoiaaony, oeacaiiue oaee aeieaeai nouanoaiaaoue ia aeenea, a
i?ioeaiii neo/aa a i?ia?aiia aicieeiao ioeaea.

Iinea ioe?uoey oaeea iiaeii ia/eiaoue /oaiea aeaiiuo. Aeey yoiai
eniieuecothony i?ioeaaeo?u read e readln, eioi?ua eniieuecothony a
neaaeothuai oi?iaoa:

read(TxtFile: text, v1: type1, v2: type2, … vN: typeN);

readln(TxtFile: text, v1: type1, v2: type2, … vN: typeN);

Ia?aay i?ioeaaeo?a /eoaao iineaaeiaaoaeueii ec oaeea cia/aiey e iiiauaao
eo a ia?aiaiiua v1, v2, … vN. Iinea eaaeaeiai i?i/eoaiiiai cia/aiey
oeacaoaeue oaeea («/eoathuay aieiaea») niauaaony e ia/aeo neaaeothuaai
cia/aiey. I?ioeaaeo?a readln aeaeaao oi aea naiia, iinea /aai ia?aiauaao
oeacaoaeue ia ia/aei neaaeothuae no?iee; readln n iaeiei eeoue ia?aui
ia?aiao?ii ia?aaiaeeo oeacaoaeue ia ia/aei iiaie no?iee. A ea/anoaa
ia?aiao?ia aeey i?ioeaaeo? read e readln iiaeii eniieueciaaoue
ia?aiaiiua neaaeothueo oeiia:

oeaeua: integer, byte, shortint, word, longint;

aauanoaaiiua: real, single, double, extended, comp;

no?ieiaua (string);

neiaieueiua (char).

I?e /oaiee no?ieiauo cia/aiee ec oaeea aa??ony any iineaaeiaaoaeueiinoue
neiaieia io iiceoeee oeacaoaey aei eiioea no?iee. Anee iinea yoiai
iiiuoaoueny aiiaue i?i/eoaoue no?ieo, oi ?acoeueoao aoaeao ionoie
no?ieie ( ‘ ‘ ). Anee iiiuoaoueny i?i/eoaoue /enei, eiaaea oeacaoaeue
oaeea noieo a eiioea no?iee, oi aoaeao i?i/eoai 0.

I?e /oaiee /enae read e readln ?aaioatho oae: nia/aea oeacaoaeue
i?iioneaao ana i?iaaeu e neiaieu oaaoeyoeee, a caoai, iaeaey ia?aue
cia/auee neiaie, iuoaaony i?i/eoaoue /enei. Anee yoi iaaiciiaeii
(ano?aoeeanue aoeaa eee /enei caienaii iaaa?ii), oi i?iecieae?o ioeaea.

I?eia? eniieueciaaiey i?ioeaaeo?u /oaiey:

var f: text; s: string; n: integer;

readln(f,n,s);

Iaiaoiaeeii iiiieoue, /oi anee oaee ia aue ioe?uo aeey /oaiey n
iiiiuueth reset, oi ethaay iiiuoea i?i/eoaoue ec iaai aeaiiua i?eaaae?o
e ioeaea.

Aeiaieueii /anoi a i?ia?aiia auaaao iaiaoiaeeii ii?aaeaeeoue, aeio?e ee
oeacaoaeue oaeea aei eiioea no?iee eee aei eiioea oaeea. A yoii neo/aa
iieacii eniieueciaaoue oaeea ooieoeee:

eoln(TxtFile: text): boolean;

eof(TxtFile: text): boolean;

Ia?aay i?eieiaao cia/aiea true (enoeia), anee oeacaoaeue noieo ia eiioea
no?iee, aoi?ay — oi aea naiia aeey eiioea oaeea.

Iinea oiai eae ana iia?aoeee /oaiey caeii/aiu, oaee iaiaoiaeeii cae?uoue
n iiiiuueth i?ioeaaeo?u

close(TxtFile: text);

anee yoiai ia naeaeaoue, oi niaea?aeeiia oaeea iiaeao ieacaoueny
enii?/aiiui iinea auiieiaiey iaoae i?ia?aiiu.

I?eia? 1 (i?ioeaaeo?u /oaiey). Ionoue eiaaony oaenoiaue oaee, iai?eia?
i?ia?aiia ia Ianeaea. O?aaoaony ?ania/aoaoue aai niaea?aeeiia ia ye?aia:

program ShowFile;

var f: text;

c: char;

begin

assign(f,’showfile.pas’);

reset(f);

while not eof(f) do begin

while not eoln(f) do begin read(f,c); write(c); end;

readln(f);

writeln;

end;

close(f);

readln;

end.

3. Caienue aeaiiuo a oaee

A oaia?ue ia?aeae?i e i?ioeaaeo?ai caiene a oaee. Ia?aae oai eae
/oi-eeai caienuaaoue, ioaeii nicaeaoue iiaue (ionoie) oaee eee noa?aoue
niaea?aeeiia nouanoaothuaai. Aeey yoiai eniieuecoaony i?ioeaaeo?a

rewrite(TxtFile: text);

Aei a? auciaa oaeeiaay aeieaeia auoue i?eaycaia e eiaie oaeea ia aeenea
n iiiiuueth assign. Anee oaee ia nouanoaiaae, oi rewrite nicaeano aai,
anee nouanoaiaae, oi niaea?aeeiia aoaeao no??oi. A ethaii neo/aa oaee
aoaeao ionoui, a oeacaoaeue caiene noieo ia ia/aea oaeea.

Aeey caiene eniieuecothony i?ioeaaeo?u

write(TxtFile: text, p1: type1, p2: type2, … pN: typeN);

writeln(TxtFile: text, p1: type1, p2: type2, … pN: typeN);

Caeanue a ea/anoaa ia?aiao?ia p1, p2, … pN iiaeii eniieueciaaoue ia
oieueei ia?aiaiiua, ii e au?aaeaiey: /eneiauo oeiia, no?ieiaua,
neiaieueiua e eiae/aneea (boolean). A ioee/ea io write, writeln iinea
caiene a oaee cia/aiee p1, p2, … pN ia?aaiaeeo oeacaoaeue caiene ia
ia/aei iiaie no?iee; writeln n iaeiei ia?aiao?ii (oaenoiaue oaee) eeoue
ia?aaiaeeo oeacaoaeue ia iiaoth no?ieo.

Oae aea eae e a neo/aa n /oaieai ec oaeea, iinea oiai eae ana aeaiiua
caienaiu oaee ioaeii cae?uoue n iiiiuueth close.

I?eia? 2 (caienue a oaee). Ionoue aeai i?iecaieueiue oaenoiaue oaee,
o?aaoaony iieo/eoue ae?oaie oaee, a eaaeaeie no?iea eioi?iai caienaia
aeeeia niioaaonoaothuae no?iee enoiaeiiai oaeea:

program WriteLength;

var f1,f2: text;

s: string;

begin

assign(f1,’writelen.pas’); reset(f1);

assign(f2,’result.txt’); rewrite(f2);

while not eof(f1) do begin

readln(f1,s);

writeln(f2,length(s));

end;

close(f1); close(f2);

end.

Au? iaeei niinia caiene — yoi ioe?uoea aeey aeiaaaeaiey eioi?iaoeee a
eiiaoe oaeea. Aeey yoiai eniieuecoaony i?ioeaaeo?a

append(TxtFile: text);

Anee oaee ioe?uo n iiiiuueth append, oi an? aai niaea?aeeiia
nio?aiyaony. I?e caaa?oaiee aeiienuaaiey a eiiaoe oaeea aai oaeaea
neaaeoao cae?uoue n iiiiuueth close.

Eaeoeey 13. Aeaie/iua oaeeu

Aeaie/iue oaee i?aaenoaaeyao niaie iineaaeiaaoaeueiinoue iaeeiaeiauo
yeaiaioia, caienaiiuo ia aeenea. A ioee/ea io oaenoiauo oaeeia, a
aeaie/iuo iao ?acaeaiey ia no?iee, oaee iaiiieiaao iannea, n oie eeoue
?acieoeae, /oi aeinooi e yeaiaioai iiaeao auoue oieueei
iineaaeiaaoaeueiui. Aeey oiai, /oiau ii?aaeaeeoue, aeinoeaioo ee eiiaoe
oaeea, ii-i?aaeiaio eniieuecoaony ooieoeey eof. Ooieoeey eoln,
i/aaeaeii, caeanue iai?eiaieia.

Aeey anao ianoaeaeaaiuo ieaea oaeeia iiaeii auiieiyoue oa aea
i?ioeaaeo?u ioe?uoey, cae?uoey e i?eaycee, /oi e aeey oaenoiauo: Append,
Assign, Close, Reset, Rewrite. E?iia oiai, iiyaeyaony i?ioeaaeo?a
Truncate(var f: file), eioi?ay oie/oiaeaao an? niaea?aeeiia oaeea,
iaoiaeyuaany iinea oaeouaai oeacaoaey /oaiey.

Aeaie/iua oaeeu aoaeai aeaeeoue ia oeiece?iaaiiua e iaoeiece?iaaiiua.

1. Oeiece?iaaiiua oaeeu

Oaeeu yoiai aeaea ninoiyo ec yeaiaioia iaeeiaeiaiai oeia, oi anoue a ieo
iaeuecy caienuaaoue (eee /eoaoue) cia/aiey ia?aiaiiuo ?aciuo oeiia, a
ioee/ea io oaenoiauo oaeeia.

Iauyaeythony oeiece?iaaiiua oaeeu oae:

var f: file of oei_yeaiaioa;

A ea/anoaa oeia yeaiaioa iiaeii eniieueciaaoue eae i?inoua oeiu, oae e
no?oeoo?e?iaaiiua (ianneau, caiene e o.i.).

2. Iaoeiece?iaaiiua oaeeu

Iaoeiece?iaaiiue oaee, a ioee/ea io oeiece?iaaiiiai, eniieuecoaony aeey
o?aiaiey ?acii?iaeiie eioi?iaoeee, a ia iaeeiaeiauo yeaiaioia. A iaai
iiaeii caienuaaoue (a oaeaea /eoaoue) cia/aiey ia?aiaiiuo i?aeoe/anee
ethaiai oeia (i?inouo oeiia, ianneaia, caienae, e o. i.). Iienuaathony
ia?aiaiiua, niioaaonoaothuea iaoeiece?iaaiiui oaeeai, neaaeothuei
ia?acii:

var f: file;

Aeey /oaiey e caiene i?ioeaaeo?u read e write ia iiaeoiaeyo.
Eniieuecothony oaeea i?ioeaaeo?u:

BlockRead(var f: file; var buf; count: word [; var result: word]); (
/eoaao a ia?aiaiioth Buf count caienae ec oaeea, ia?aiaiiay result
iieacuaaao neieueei caienae auei neiie?iaaii a aeaenoaeoaeueiinoe. Iiae
caienueth iiieiaaony «eonie» oaeea a ianeieueei aaeo, ?acia? caiene
iiaeii onoaiiaeoue i?e ioe?uoee oaeea, iai?eia?: reset(f,1).

BlockWrite(var f: file; var buf; count: word [; var result: word]); (
caienuaaao oeacaiiia eiee/anoai caienae a oaee. Anee aeey ioe?uoey
eniieuecoaony rewrite, oi ai aoi?ii a? ia?aiao?a oaeaea iiaeii oeacaoue
?acia? caiene.

Eaeoeey 14. Iiaeoee a Oo?ai Ianeaea

A Oo?ai Ianeaea aeiioneaaony ?acaeaaoue i?ia?aiiu ia /anoe e o?aieoue
yoe /anoe a ioaeaeueiuo oaeeao ia aeenea. E?iia iniiaiie i?ia?aiiu
iiyaeythony oae iacuaaaiua iiaeoee, eioi?ua i?aaeinoaaeytho iniiaiie
i?ia?aiia eee ae?oaei iiaeoeyi naie ia?aiaiiua, eiinoaiou, oeiu,
i?ioeaaeo?u, ooieoeee e o. i. *oiau eniieueciaaoue iiaeoeue a i?ia?aiia,
ioaeii oeacaoue aai eiy iinea uses.

I?e iaienaiee iiaeoey nia/aea iienuaaaony oi, /oi ii i?aaeinoaaeyao aeey
iauaai iieueciaaiey (naeoeey eioa?oaena), a caoai ( eae ii ono?iai
(naeoeey ?aaeecaoeee). Eiiaaea nouanoaoao naeoeey eieoeeaeecaoeee, aaea
caienaiu aeaenoaey, eioi?ua auiieiythony i?e iiaeeeth/aiee yoiai
iiaeoey. Caienuaaaony yoi an? neaaeothuei ia?acii:

unit MyUnit;

interface

(*Eioa?oaeniay naeoeey*)

uses …;

const …;

type …;

procedure …; {Oieueei

function …; caaieiaee}

implementation

(*Naeoeey ?aaeecaoeee*)

uses …;

const …;

type …;

procedure …; {?aaeecaoeey anao iienaiiuo

begin i?ioeaaeo? e ooieoeee}

end;

function …;

begin

end;

[begin]

(*Naeoeey eieoeeaeecaoeee*)

end.

?anniio?ei /anoe iiaeoey iiae?iaiaa. Uses a eioa?oaeniie naeoeee iiaeao
auoue ioaeai, anee a iae eniieuecothony eaeea-eeai ?ano?nu ec ae?oaeo
iiaeoeae. I?ioeaaeo?u e ooieoeee caeanue oieueei iienuaathony, ii ia
?aaeecothony, oi anoue ia caienuaathony oaea i?ioeaaeo? e ooieoeee
(begin … end;). A naeoeee ?aaeecaoeee iiaeii oaeaea iiaeeeth/aoue
ae?oaea iiaeoee; nicaeaaaoue ia?aiaiiua, eiinoaiou, oeiu, i?ioeaaeo?u e
ooieoeee, eioi?ua «aeaeiu» oieueei aioo?e yoiai iiaeoey, ieeaeie ae?oaie
iiaeoeue eee i?ia?aiia ia iiaeao eie iieueciaaoueny. Caeanue aea
iaycaoaeueii aeieaeiu auoue caienaiu ana i?ioeaaeo?u e ooieoeee
(iieiinoueth). Ia?aiao?u (a neiaeao) iinea eiaie i?ioeaaeo?u e ooieoeee
a naeoeee ?aaeecaoeee iiaeii ia oeacuaaoue.

Naeoeey eieoeeaeecaoeee niaea?aeeo oa aeaenoaey, eioi?ua aeieaeiu
auiieiyoueny eiaaea iao iiaeoeue iiaeeeth/aaony e i?ia?aiia, oi anoue
aei oiai eae ia/i?o ?aaioaoue naia i?ia?aiia. Iiaeoeue graph, iai?eia?
onoaiaaeeaaao a naeoeee eieoeeaeecaoeee cia/aiey ii oiie/aieth oeaaoa
eeiee e oiia, noeeue eeiee, noeeue caeeaee o.i.

I?e nio?aiaiee iiaeoey aio ioaeii aeaoue oaeia aea eiy, eae e iinea unit
a oaenoa iiaeoey. Eiaia oaeeia, niaea?aeaueo iiaeoee, aeieaeiu eiaoue
?anoe?aiea «pas», oaeaea eae e i?ia?aiiu.

?anniio?ei i?eia?. Iao iiaeoeue i?aaeiacia/aaony aeey iia?aoeee n
o?aoia?iuie aaeoi?aie:

unit Vectors;

interface

type tVec3D = record

x,y,z: real;

end;

procedure VecAdd(a,b: tVec3D; var c: tVec3D);

procedure VecSub(a,b: tVec3D; var c: tVec3D);

procedure VecMultNum(k: real; a: tVec3D; var b: tVec3D);

function ScalarProduct(a,b: tVec3D): real;

implementation

procedure VecAdd(a,b: tVec3D; var c: tVec3D);

begin

c.x:=a.x+b.x;

c.y:=a.y+b.y;

c.z:=a.z+b.z;

end;

procedure VecSub(a,b: tVec3D; var c: tVec3D);

begin

c.x:=a.x-b.x;

c.y:=a.y-b.y;

c.z:=a.z-b.z;

end;

procedure VecMultNum(k: real; a: tVec3D; var b: tVec3D);

begin

b.x:=k*a.x;

b.y:=k*a.y;

b.z:=k*a.z;

end;

function ScalarProduct(a,b: tVec3D): real;

begin

ScalarProduct:=a.x*b.x+a.y*b.y+a.z*b.z;

end;

end.

A i?ia?aiia iao iiaeoeue iiaeii eniieueciaaoue, iai?eia?, oae:

program xxx;

uses Vectors;

var v1,v2,res: tVec3D;

begin

VecMultNum(0.2,v1,res);

VecSub(v2,res,res);

{a ?acoeueoaoa res = v2-0.2(v1}

end.

A neo/ayo, eiaaea ianeieueei iiaeoeae niaea?aeao iauaeou n iaeeiaeiauie
eiaiaie, ia?auaoueny e iei ioaeii n oeacaieai eiaie iiaeoey: . . Ionoue, iai?eia?, iiaeoee unit1 e unit2
niaea?aeao i?ioeaaeo?u n iaeeiaeiauie eiaiaie proc1, oiaaea ia?auaoueny
e iei neaaeoao oae: unit1.proc1; e unit2.proc2; .

I?aeiouanoaa iiaeoeae:

N?aaenoaa, acyoua ec iiaeoeae iicaieytho ia iiaoi?youe a i?ia?aiiao
iaeie e oa aea o?aaiaiou.

Ia?aiaiiua, i?ioeaaeo?u e ae?oaea iauaeou iiaeii ne?uoue a naeoeee
?aaeecaoeee, anee eo iaiaaeoiaiiia auiieiaiea iiaeao enii?oeoue
i?ia?aiio.

Iiaeoee eiiieee?othony ioaeaeueii io aeaaiie i?ia?aiiu, iiyoiio i?e
eiiieeyoeee anae i?ia?aiiu ia?aaaouaaaony oieueei aeaaiay i?ia?aiia
(iaiueoea cao?aou a?aiaie i?e ioeaaeea i?ia?aii). Yoi iniaaiii aaaeii
aeey aieueoeo i?ia?aii.

Aieueoay i?ia?aiia noaiiaeony aieaa iiiyoiie, anee ?aciua a? /anoe
?aniieiaeeoue a ?aciuo iiaeoeyo, a niioaaonoaee n eo iacia/aieai.

Eaeoeey 15. Aeeiaie/aneea ia?aiaiiua

Ana ecaanoiua iai ia aeaiiue iiiaio ia?aiaiiua yaeythony noaoe/aneeie,
yoi icia/aao, /oi iaiyoue iiae ieo auaeaeyaony iaeei ?ac i?e caionea
i?ia?aiiu, e a oa/aiea anaai a?aiaie a? ?aaiou ia?aiaiiua caieiatho
ioaaae?iiua ei o/anoee. Eiiaaea oaeie iiaeoiae iiaeao ieacaoueny
iaauaiaeiui. Iai?eia?, i?e o?aiaiee oaaee/iuo aeaiiuo a aeaea ianneaa,
i?eoiaeeony caaiaeeoue iannea aieueoiai ?acia?a, iineieueeo ca?aiaa
iaecaanoii, neieueei no?ie niaea?aeeony a oaaeeoea. A ?acoeueoaoa /anoue
iaiyoe, caiyoay iiae iannea, ia eniieuecoaony. A iiaeiaiuo caaea/ao
oioaeinue au eniieueciaaoue noieueei iaiyoe, neieueei iaiaoiaeeii a
eaaeaeue eiie?aoiue iiiaio a?aiaie, oi anoue ?ani?aaeaeyoue iaiyoue
aeeiaie/anee.

A Oo?ai Ianeaea anoue aiciiaeiinoue nicaeaiey aeeiaie/aneeo ia?aiaiiuo
(oi anoue oaeeo, eioi?ua iiaeii caaiaeeoue e oie/oiaeaoue ai a?aiy
?aaiou i?ia?aiiu ii ia?a iaiaoiaeeiinoe). Aeey yoiai a i?ia?aiia
iauyaeytho ia naio ia?aiaiioth ioaeiiai iai oeia, a oeacaoaeue ia yoo
ia?aiaiioth, iai?eia?:

var p: ^real;

caeanue p ( eiy ia?aiaiiie-oeacaoaey; ciae “^” iieacuaaao, /oi p
yaeyaony ia iau/iie ia?aiaiiie, a oeacaoaeai; real ( oei oie ia?aiaiiie,
ia eioi?oth oeacuaaao p. Ia?aiaiiay p i?aaenoaaeyao niaie ia /oi eiia
eae aae?an oiai ianoa a iaiyoe, aaea aoaeao o?aieoueny naia
aeeiaie/aneay ia?aiaiiay (a iaoai neo/aa /enei oeia real).

Aeey anao aeeiaie/aneeo ia?aiaiiuo a iaiyoe ioaiaeeony i?ino?ainoai,
iacuaaaiia aeeiaie/aneie iaeanoueth, eee eo/ae. Ia?aae oai eae
iieueciaaoueny aeeiaie/aneie ia?aiaiiie, o?aaoaony auaeaeeoue aeey ia?
ianoi a eo/a. Yoi aeaeaaony n iiiiuueth i?ioeaaeo?u New, iai?eia?:

New(p);

A ?acoeueoaoa oaeiai aeaenoaey a eo/a auaeaeaii ianoi iiae ia?aiaiioth
oeia real, ia?aoeoueny e iae iiaeii, caienaa p^, iai?eia? p^:=123.5.

Anee iio?aaoaony eciaieoue cia/aiea oeacaoaey, iai?eia?, canoaaeoue aai
oeacuaaoue ia ae?oaoth ia?aiaiioth, oi noa?oth ia?aiaiioth neaaeoao
oie/oiaeeoue, oi anoue iauyaeoue caieiaaioth noa?ie ia?aiaiiie iaiyoue
naiaiaeiie. Anee yoiai ia naeaeaoue, oi i?e eciaiaiee oeacaoaey naia
ia?aiaiiay noaiao ioni?ii (ianoi a iaiyoe iauyaeaii caiyoui, a iieo/eoue
e iaio aeinooi oaea iaaiciiaeii). Oie/oiaeaiea aeeiaie/aneie ia?aiaiiie
auiieiyaony i?ioeaaeo?ie Dispose: Dispose(p);

?anniio?ei oaia?ue iia?aoeee, eioi?ua iiaeii auiieiyoue iaae
oeacaoaeyie.

I?enaaeaaiea. Oeacaoaeth iiaeii i?enaaeaaoue cia/aiea ae?oaiai oeacaoaey
oaeiai aea oeia, a oaeaea cia/aiea nil, eioi?ia icia/aao «ie ia /oi ia
oeacuaaao». A oeacaoaeue iiaeii oaeaea iieiaeeoue aae?an eaeie-eeai
ia?aiaiiie, iai?eia?: p:=Addr(a); eee p:[email protected]; oioy iaiaoiaeeiinoue a yoii
aicieeaao ?aaeei.

N?aaiaiea. Aeaa oeacaoaey iiaeii n?aaieaaoue oieueei ia ?aaainoai (eee
ia?aaainoai). Iiaeii n?aaieaaoue oeacaoaeue n nil, n aae?anaie
ia?aiaiiuo.

N aeeiaie/aneeie ia?aiaiiuie iiaeii auiieiyoue ana aeaenoaey,
?ac?ao?iiua aeey noaoe/aneeo ia?aiaiiuo, iai?eia?:

if p^ >= q^ then p^ := q^;

?anniio?ei oaia?ue ianeieueei eneonnoaaiiue i?eia? eniieueciaaiey
aeeiaie/aneeo ia?aiaiiuo: ionoue o?aaoaony neiaeeoue aeaa /enea, ia
eniieuecoy noaoe/aneeo ia?aiaiiuo:

var pa,pb: ^real;

begin

new(pa); new(pb);

write(‘Aaaaeeoa a: ‘); readln(pa^);

write(‘Aaaaeeoa b: ‘); readln(pb^);

writeln(‘a+b=’,pa^+pb^);

dispose(pa); dispose(pb);

readln;

end.

E?iia iienaiiuo oeacaoaeae nouanoaotho au? oae iacuaaaiua
iaoeiece?iaaiiua oeacaoaee (oei pointer), eioi?ua iiaoo neoaeeoue
oeacaoaeyie ia ia?aiaiiua ethauo oeiia, iaeiaei iaiaoiaeeiinoue a ieo
aicieeaao ?aaeei, iiyoiio ?anniao?eaaoue eo iiae?iaii iu ia aoaeai.

Aeeiaie/aneea no?oeoo?u aeaiiuo

Aa?i?iny oaia?ue e aii?ino ia yeiiiiee iaiyoe i?e o?aiaiee oaaee/iuo
aeaiiuo. N eniieueciaaieai oeacaoaeae iiaeii ioeacaoueny io ianneaa e
eniieueciaaoue aeeiaie/aneea no?oeoo?u. Naiie i?inoie ec ieo yaeyaony
nienie, eioi?ue noaiaoe/ii ecia?aaeaaony oae:

I?yiioaieueieee ia yoie noaia ( aeeiaie/aneea ia?aiaiiua oeia caienue,
Data ( iiea (eee iiey), niaea?aeauea iieacioth eioi?iaoeeth (iai?eia?
oaieeee e iiia?a oaeaoiiia), iiea, eioi?ia ecia?aaeaii ieaea Data ( yoi
oeacaoaeue ia neaaeothuoth caienue. Ia?aiaiiay List oaeaea yaeyaony
oeacaoaeai ia caienue. AEe?iay oi/ea a iiea «neaaeothuee yeaiaio» a
naiie iineaaeiae caiene icia/aao, /oi oai eaaeeo cia/aiea nil, /oiau
iieacaoue, /oi yoa caienue ( iineaaeiyy a nienea.

Aeey iienaiey nienea ia Ianeaea aeinoaoi/ii iienaoue oei oeacaoaey ia
caienue e oei naiie caiene. Auaeyaeeo an? yoi oae:

type tItemPtr = ^tItem; {oeacaoaeue ia yeaiaio}

tItem = record

Data: tData; {iieaciua aeaiiua}

Next: tItemPtr; {oeacaoaeue ia neaaeothuee yeaiaio nienea}

end;

A ia?aie no?iea yoiai iauyaeaiey a?inaaony a aeaca eniieueciaaiea
iaii?aaeae?iiiai oeia tItem. Oaeia eneeth/aiea ec i?aaee a Oo?ai Ianeaea
naeaeaii oiuoeaiii, a i?ioeaiii neo/aa ia auei au aiciiaeiinoe no?ieoue
nienee e ae?oaea naycaiiua no?oeoo?u ec aeeiaie/aneeo ia?aiaiiuo.

Iauyaeoue nai nienie iiaeii eae oeacaoaeue ia yeaiaio: var List :
tItemPtr; iiea iao nienie iono, a List neaaeoao iieiaeeoue cia/aiea nil.
I?e nicaeaiee ia?aiai yeaiaioa aoaeai auiieiyoue aeaenoaey New(List);
List^.Next:=nil.

A nieneao anaaaea o?aieony ?iaii noieueei yeaiaioia, neieueei ioaeii;
anee eaeie-eeai yeaiaio aeaiiuo iioa?ye naith oeaiiinoue, oi aai anaaaea
iiaeii oaeaeeoue ec nienea; anee iiyaeeenue iiaua aeaiiua, oi iiaeii
aeiaaaeoue iiaue yeaiaio.

Iaieoai oaia?ue iiaeoeue aeey ?aaiou ni nieneaie. A i?i niaea?aeaony
i?ioeaaeo?u ia?aiia/aeueiie iiaeaioiaee nienea; aeiaaaeaiey yeaiaioa a
ia/aei nienea; oaeaeaiey yeaiaioa, neaaeothuaai ca oeacaiiui;
iaoiaeaeaiey yeaiaioa n caaeaiiui iiia?ii; iiaen/aoa yeaiaioia e i/enoee
nienea.

unit Lists;

interface

type tData = record

Name: string[50];

Phone: longint;

end;

tItemPtr = ^tItem;

tItem = record

Data: tData;

Next: tItemPtr;

end;

procedure InitList(var l: tItemPtr);

procedure AddItemToHead(var l: tItemPtr; d: tData);

function DeleteItemAfter(var l: tItemPtr; num: word): boolean;

function Count(l: tItemPtr): word;

function GetItem(l: tItemPtr; num: word; var d: tData): boolean;

procedure ClearList(var l: tItemPtr);

{—————————————————————}

implementation

procedure InitList(var l: tItemPtr);

begin l:=nil end;

procedure AddItemToHead(var l: tItemPtr; d: tData);

var p: tItemPtr;

begin

new(p);

p^.data:=d;

p^.next:=l;

l:=p;

end;

function DeleteItemAfter(var l: tItemPtr; num: word): boolean;

var p,q: tItemPtr;

i: word;

begin

i:=1;

p:=l;

while (inum)and(pnil) do begin

i:=i+1;

p:=p^.next;

end;

if pnil then begin

if p^.nextnil then begin

q:=p^.next^.next;

dispose(p^.next);

p^.next:=q;

DeleteItemAfter:=true;

end

else DeleteItemAfter:=false; {ia oaeae?i}

end

else DeleteItemAfter:=false;

end;

function Count(l: tItemPtr): word;

var p: tItemPtr;

i: word;

begin

i:=0;

p:=l;

while pnil do begin

i:=i+1;

p:=p^.next;

end;

count:=i;

end;

function GetItem(l: tItemPtr; num: word; var d: tData): boolean;

var p: tItemPtr;

i: word;

begin

i:=1;

p:=l;

while (inum)and(pnil) do begin

i:=i+1;

p:=p^.next;

end;

if pnil then begin

d:=p^.data;

GetItem:=true;

end

else GetItem:=false;

end;

procedure ClearList(var l: tItemPtr);

var p: tItemPtr;

begin

while (lnil) do begin

p:=l^.next;

dispose(l);

l:=p;

end;

end;

end.

Eaeoeey 16. Aeeiaie/aneea ia?aiaiiua: ae?oaea aeaeu nieneia, noae e
i/a?aaeue.

1. Ae?oaea aeaeu nieneia

E?iia ?anniio?aiiuo nieneia aiciiaeiu aieaa neiaeiua aa?eaiou, naycaiiua
n iaee/eai aeaoo aeiiieieoaeueiuo naienoa:

Aeaoiai?aaeaiiinoue nienea. A eaaeaeii yeaiaioa oaeeo nieneia anoue ia
oieueei oeacaoaeue ia neaaeothuee yeaiaio, ii e ia i?aaeuaeouee. Oaeay
i?aaiecaoeey iiaeao ieacaoueny iieaciie i?e aeiaaaeaiee eee oaeaeaiee
yeaiaioa, i?aaeoanoaothuaai oeacaiiiio.

Caieiooinoue nienea. Iiea next a iineaaeiai yeaiaioa oeacuaaao ia ia?aue
yeaiaio. Eia/a oaeea nienee iacuaathony eieueoeaauie. Yoio aeae
iicaieyao oi?inoeoue i?ioeaaeo?o oaeaeaiey yeaiaioa nienea e ae?oaea
iia?aoeee.

N o/?oii yoeo naienoa aiciiaeiu /aou?a ?acee/iuo oeia nieneia.

Aeey i?eia?a ?anniio?ei iienaiea e ?aaeecaoeeth eieueoeaaiai
aeaoiai?aaeaiiiai nienea:

type tItemPtr = ^tItem

tItem = record

data: tData;

next,prev: tItemPtr;

end;

var List: tItemPtr; {nienie – oeacaoaeue ia iaeei ec yeaiaioia}

……..

{Oaeaeeoue iinea oeacaiiiai:}

procedure DelAfter(p: tItemPtr);

var q: tItemPtr;

begin

if (pnil)and(p^.nextp) then begin

q:=p^.next^.next;

dispose(p^.next);

p^.next:=q;

q^.prev:=p;

end;

end;

{Anoaaeoue ia?aae oeacaiiui:}

procedure InsertBefore(p: tItemPtr; d: tData);

var q: tItemPtr;

begin

if pnil then begin

new(q);

q^.data:=d;

q^.next:=p;

q^.prev:=p^.prev;

p^.prev:=q;

q^.prev^.next:=q;

end;

end;

2. Noae e i/a?aaeue

Noaeii iacuaaaony oaeie niinia o?aiaiey aeaiiuo, i?e eioi?ii yeaiaio,
caienaiiue a o?aieeeua aeaiiuo, iineaaeiei anaaaea ecaeaeaaony ia?aui
(aeenoeeieeia LIFO ( «last in – first out»). I?e ecaea/aiee yeaiaioa
i?ienoiaeeo aai oaeaeaiea ni noaea.

?anniio?ei i?inoaeoee i?eia? eniieueciaaiey noaea. I?aaeiieiaeei, /oi
eiaaony no?iea, ninoiyuay ec iaeieo eeoue ioe?uaathueo e cae?uaathueo
neiaie. O?aaoaony ii?aaeaeeoue, yaeyaony ee iia i?aaeeueiui neiai/iui
au?aaeaieai (oi anoue aeey eaaeaeie ioe?uaathuae neiaee aeieaeia
iaeoenue cae?uaathuay). Caaaae?i iannea e ia?aiaiioth aeey o?aiaiey
iiia?a iineaaeiaai cia/eiiai yeaiaioa a ianneaa (oi anoue aa?oeiu
noaea), a eioi?ue i?e i?ioiaea ii no?iea aoaeai neeaaeuaaoue ana
ioe?uaathueany neiaee (n oaaee/aieai iiia?a aa?oeiu ia 1), a i?e ano?a/a
n cae?uaathuae aoaeai oaeaeyoue niioaaonoaothuoth ioe?uaathuoth
(iii?inoo oiaiueoaoue iiia? aa?oeiu noaea). Anee ieaaeaony, /oi «i?eoea»
cae?uaathuay neiaea, a noae iono (oi anoue iiia? aa?oeiu ?aaai 0), oi
au?aaeaiea ioeai/ii. Yoi aea iiaeii neacaoue e a neo/aa, eiaaea no?iea
caeii/eeanue, a noae ia iono.

I/aaeaeii, /oi aeey ?aaeecaoeee oaeiai noaea iannea eniieueciaaoue ia
iaycaoaeueii, aeinoaoi/ii o?aieoue a iaeioi?ie ia?aiaiiie eeoue /enei
ioe?uaathueo neiaie. I?e iinooieaiee cae?uaathuae neiaee ec yoie
ia?aiaiiie au/eoaaony 1. Ioeaea aicieeaao, anee cia/aiea ia?aiaiiie
noaei io?eoeaoaeueiui, eee i?e aeinoeaeaiee eiioea no?iee iii ia ?aaii
ioeth.

Aeey aeaiiuo aieaa neiaeiiai aeaea noae iiaeii i?aaieciaaoue n iiiiuueth
iaeiiiai?aaeaiiiai iaeieueoeaaiai nienea. *oiau iieiaeeoue yeaiaio a
noae, ioaeii aeiaaaeoue aai a ia/aei nienea, /oiau ecaea/ue ni noaea (
iieo/eoue aeaiiua ia?aiai yeaiaioa, iinea /aai oaeaeeoue aai ec nienea.

Ethaay ?aaeecaoeey noaea aeieaeia niaea?aeaoue neaaeothuea i?ioeaaeo?u e
ooieoeee:

procedure InitStack ( eieoeeaeecaoeey noaea;

procedure Push(d: tData) ( iieiaeeoue yeaiaio a noae;

procedure Pop(var d: tData) ( ecaea/ue yeaiaio n aa?oeiu noaea;

function NotEmpty: boolean ( i?iaa?ea noaea ia ionoioo;

I/a?aaeue ioee/aaony io noaea oai, /oi iineaaeiee i?eoaaeoee a ia?
yeaiaio aoaeao ecaea/?i iineaaeiei, a ia?aue ( ia?aui («FIFO»). N
iiiiuueth nieneia a? iiaeii i?aaieciaaoue neaaeothuei ia?acii: aoaeai
o?aieoue ia oieueei oeacaoaeue ia «aieiao» nienea, ii e ia «oaino»;
aeiaaaeyoue aoaeai a «oaino», a ecaeaeaoue ( ec «aieiau».

Ethaay ?aaeecaoeey i/a?aaee (ia iaycaoaeueii n iiiiuueth nieneia)
aeieaeia «oiaoue» auiieiyoue oaeea aeaenoaey:

procedure InitQueue ( eieoeeaeecaoeey i/a?aaee;

procedure AddQueue(d: tData) ( iinoaaeoue yeaiaio a i/a?aaeue;

procedure SubQueue(var d: tData) ( ecaea/ue yeaiaio ec i/a?aaee;

function NotEmpty: boolean ( i?iaa?ea i/a?aaee ia ionoioo;

Eaeoeey 17. Aea?aauey e iiene a aea?aaueyo

Aea?aaueyie iacuaathony no?oeoo?u aeaiiuo neaaeothuaai aeaea:

Yeaiaiou aea?aaa iacuaathony aa?oeiaie. Aa?oeia Tree^ iacuaaaony ei?iai
aea?aaa, a an? iiiaeanoai aa?oei, naycaiiuo n iaeioi?ie aa?oeiie n
iiiiuueth iaeiiai ec oeacaoaeae iacuaaaony iiaeaea?aaii. Aa?oeiu, o
eioi?uo ana oeacaoaee ?aaiu nil, eiiaaea iacuaatho eenoueyie.

Iiae?iaiaa iu ?anniio?ei aa?eaio aeaie/iiai aea?aaa, oi anoue oaeiai, a
eioi?ii eaaeaeay aa?oeia eiaao aeaa iiaeaea?aaa (ethaia ec ieo iiaeao
ieacaoueny ionoui). Oaeea aea?aauey ieacuaathony i/aiue oaeiaiuie aeey
?aoaiey caaea/e iienea, eiaaea eeth/e aeey iaoeo aeaiiuo (iai?eia?
oaieeee i?e iienea oaeaoiiiuo iiia?ia) iiaeii n?aaieaaoue ia “=”, ““. A eaaeaeoth aa?oeio aea?aaa caiineony yeaiaio aeaiiuo, i?e/?i
aeaeaaony yoi oaeei ia?acii, /oiau aeey ethaie aa?oeiu ana eeth/e
aeaiiuo (eee naie aeaiiua a i?inoaeoai neo/aa) ec eaaiai iiaeaea?aaa
auee iaiueoa eeth/a yoie aa?oeiu, a ana eeth/e ec i?aaiai ( aieueoa.
Auiieiaiey oaeiai o?aaiaaiey iiaeii aeinoeaiooue i?e iineaaeiaaoaeueiii
aeiaaaeaiee yeaiaioia (oi anoue iino?iaiee aea?aaa, ia/eiay n «ioey»,
oi/iaa n nil).

I?e iienaiiii iino?iaiee aea?aaa iiene ieacuaaaony aeiaieueii i?inoui
aeaeii: nia/aea iu n?aaieaaai eneiiue eeth/ n eeth/ii ei?iy aea?aaa.
Anee yoe aeaa eeth/a niaiaaeatho, oi yeaiaio iaeaeai, a i?ioeaiii neo/aa
auiieiyai iiene a eaaii iiaeaea?aaa, eia/a ( a i?aaii, aeaeaa a
aua?aiiii iiaeaea?aaa aiiaue auiieiyai n?aaiaiea aai ei?iy n eneiiui
eeth/ii, e o. ae. Yoio i?ioeann caeii/eony eeai eiaaea iu iaoee eeth/,
eeai eiaaea i/a?aaeiia iiaeaea?aai ieacaeinue ionoui (yoi icia/aao, /oi
oaeie eeth/ a aea?aaa ionoonoaoao).

Aeey ?aaeecaoeee aeaie/iiai aea?aaa nia/aea ?anniio?ei aai iienaiea ia
Ianeaea:

type tNodePtr = ^tNode; {oeacaoaeue ia aa?oeio}

tNode = record

data: tMyData;

left,right: tNodePtr;

end;

tTree = tNodePtr; {aeey aeinooia e aea?aao aeinoaoi/ii o?aieoue

oeacaoaeue ia aai ei?aiue}

Iiae aeaiiuie (tMyData) aoaeai iiieiaoue caienue, ninoiyuoth ec eeth/a,
iaiaoiaeeiiai aeey n?aaiaiee, e nianoaaiii aeaiiuo:

type tMyData = record

key: tKey;

data: tData;

end;

Aeey oiai /oiau ?aaeeciaaoue aeaenoaey n aeaie/iui aea?aai, iai
iiiaaeiayony oae iacuaaaiua ?aeo?neaiua i?ioeaaeo?u. Ooieoeey eee
i?ioeaaeo?a iacuaaaony ?aeo?neaiie, anee iia aucuaaao naia naay. Oaeie
aa?eaio ?aeo?nee iacuaaaony i?yiui. E?iia oiai, auaaao e einaaiiay
?aeo?ney, eiaaea iaeia i?ioeaaeo?a aucuaaao ae?oaoth, a oa a naith
i/a?aaeue aucuaaao ia?aoth.

A ea/anoaa i?eia?a ?anniio?ei ooieoeeth aeey au/eneaiey oaeoi?eaea, a
eioi?ie iu caiaiei oeeee (eee eoa?aoeeth) ?aeo?neae. A? eaeay i?inoa:
anee a?aoiaio ?aaai ioeth, oi aica?auaai cia/aiea 1, a i?ioeaiii neo/aa
aica?auaai cia/aiea a?aoiaioa, oiiiaeaiiia ia oaeoi?eae (oi anoue oo aea
ooieoeeth) io /enea, ia aaeeieoeo iaiueoaai. Ia Ianeaea an? yoi aoaeao
auaeyaeaoue neaaeothuei ia?acii:

function factorial(x: byte): longint;

begin

if x=0 then factorial:=1

else factorial:=x*factorial(x-1);

end;

Iiaeiaiui ia?acii iiaeii i?eiaieoue ?aeo?neth aeey au/eneaiey n-ai /enea
Oeaiia//e, oioy yoio niinia o?aaoao iiiai eeoieo aeaenoaee:

function fib(n: integer): integer;

begin

if nnil then begin

Traversal(t^.left);

writeln(‘Key:’,t^.key,’ Data:’,t^.data);

Traversal(t^.right);

end;

end;

Eaeoeey 18. Oaaeeoeu e i?inoaeoea aeai?eoiu iienea.

1. Ii?aaeaeaiey e iienaiey no?oeoo? aeaiiuo

Oaaeeoeae aoaeai iacuaaoue no?oeoo?o aeaiiuo, i?eaiaeioth aeey o?aiaiey
iaai?a aeaiiuo, eiathueo iaeeiaeiaua oeiu. I?inoaeoei i?eia?ii oaeie
no?oeoo?u iiaeao neoaeeoue iannea, iineieueeo oei anao aai yeaiaioia
iaeei e oio aea. *aua anaai yeaiaio oaaeeoeu ninoieo ec ianeieueeeo
/anoae, iaeia ec eioi?uo eiaao iaeaieueoaa cia/aiea (iacuaaaony
eeth/ii), a inoaeueiua niaea?aeao eioi?iaoeeth, naycaiioth n yoei
eeth/ii, eee nianoaaiii aeaiiua. Anee an? yoi ecia?aceoue a?aoe/anee, oi
iieo/eony oi, /oi iacuaaaony oaaeeoeae a iau/iii niunea:

O. E. I. Aae?an Oaeaoii Aiae ?iaeaeaiey

Iao?ia O. I. Naaa?iay 99-88 29-29-29 1962

Eaaiia I. N. Ie?a 111-222 77-88-99 1976

Eiceia I. A. Ieoya?ueneay 135-246 45-67-89 1970

……………..

Caeanue eeth/ii yaeyaony oaieeey, a ana inoaeueiua yeaiaiou — iieaciay
eioi?iaoeey i /aeiaaea n oaeie oaieeeae. A neo/aa, eiaaea iaoa oaaeeoea
noaiiaeony aeiaieueii aieueoie, iaeoe aeaiiua i ioaeiii iai /aeiaaea
noaiiaeony aeiaieueii neiaeii. Aeai?eoiu, i?aaeiacia/aiiua aeey iienea a
oaaeeoea aeaiiuo n oeacaiiui eeth/ii, iacuaathony aeai?eoiaie iienea.
Iiene iiaeao auoue oaea/iui (anee yeaiaio n eneiiui eeth/ii eiaaony a
ianneaa) e iaoaea/iui (a i?ioeaiii neo/aa).

I?e eniieueciaaiee ycuea Ianeaeue aeey ?aaiou n oaaee/iuie aeaiiuie
aeiaieueii oaeiaii eniieueciaaoue caiene a ea/anoaa yeaiaioia aeaiiuo. A
iaoai i?eia?a oaaeeoea aoaeao ninoiyoue ec yeaiaioia neaaeothuaai oeia:

type tItem {yeaiaio} = record

surname: string[30]; {oaieeey, eeth/aaia iiea}

address: string; {aae?an}

phone: longint; {oaeaoii}

birth: word; {aiae ?iaeaeaiey}

end;

I?e ?anniio?aiee aeai?eoiia iienea iu aoaeai iieueciaaoueny aieaa iauae
oi?iie aeey caiene oeia yeaiaioa:

type tItem = record

key: tKey; {eeth/}

data: tData; {aeaiiua}

end;

Oeiu tKey e tData caaenyo io eiie?aoiie caaea/e, eioi?oth ioaeii
?aoaoue. A iaoai i?eia?a tKey — no?iea aei 30 neiaieia aeeeiie, a tData
iiaeii naeaeaoue caienueth ec o??o iieae (address, phone e birth).

?anniio?ei oaia?ue iaeioi?ua niiniau ?aaeecaoeee anae oaaeeoeu:

1. Iannea

Yoi iaeaieaa i?inoie aa?eaio e aeiaieueii oaeiaiue, iineieueeo
iieiaeaiea yeaiaioa a oaaeeoea iaeiicia/ii ii?aaeaeyaony iiia?ii
yeaiaioa a ianneaa. Anee ?acia? oaaeeoeu iaiyaony a oiaea ?aaiou n iae
(aeaiiua a?aiy io a?aiaie aeiaaaeythony eee oaeaeythony), oi iannea
ieacuaaaony ia i/aiue yeiiiie/iui: iineieueeo oi/iia eiee/anoai
yeaiaioia ca?aiaa iaecaanoii, i?eoiaeeony caaiaeeoue iannea ec aieueoiai
eiee/anoaa yeaiaioia, /anoue ec eioi?uo ia aoaeao eniieueciaaoueny, ii
aoaeao caieiaoue ianoi a iaiyoe.

Aeey oiai /oiau o?aieoue oaaeeoeo, iai iio?aaoaony caienue ec aeaoo
iieae: nai iannea e oeaei/eneaiiia iiea, iaicia/athuaa oaeouee ?acia?
ianneaa:

const maxsize = 2000; {iaeneiaeueiue ?acia? oaaeeoeu}

type tTable = record

a: array[1..maxsize] of tItem; {yoi nai iannea}

n: integer; {a yoi – ?aaeueiia /enei yeaiaioia}

end;

var Table: tTable;

I?aaeiieaaaaony, /oi a ethaie iiiaio a?aiaie aeaiiua oaaeeoeu o?aiyony a
ia?auo n yeaiaioao ianneaa, a inoaeueiua n/eoathony ionouie.

2. Nienie

Yoio aa?eaio aieaa yeiiiie/ai a ieaia ?anoiaea iaiyoe, oae eae anaaaea
aoaeao caiyoi ?iaii noieueei ianoa, neieueei ioaeii iiae aeaiiua. A
ioee/ea io ianneaa, iu ia iiaeai eaaei i?iniao?eaaoue aeaiiua
i?iecaieueiiai yeaiaioa, aeey ia?aoiaea io iaeiiai yeaiaioa e ae?oaiio
ioaeii aeieai aeaeaaoueny ii oeaii/ea oeacaoaeae; yoi yaeyaony
iaaeinoaoeii nienea.

Eae auaeyaeeo oaeay oaaeeoea ia Ianeaea iai oaea ecaanoii:

type tItemPtr = ^tItem; {oeacaoaeue ia yeaiaio nienea}

tItem = record {yeaiaio nienea}

key: tKey;

data: tData;

next: tItemPtr;

end;

tList: tItemPtr; {caaea?ony oeacaoaeai ia ia?aue yeaiaio}

var Table: tList {oaaeeoea yaeyaony nieneii}

3. Aea?aai

Eae o?aieoue e eneaoue aeaiiua a aeaie/iii aea?aaa, iu oaea ciaai, a
oaaeeoeo iiaeii caaeaoue oae:

type tItemPtr = ^tItem; {oeacaoaeue ia yeaiaio}

tItem = record {yeaiaio}

key: tKey;

data: tData;

left, right: tItemPtr;

end;

tTree = tItemPtr;

var Table: tTree; {oaaeeoea yaeyaony aea?aaii}

2. Aeai?eoiu

1. Eeiaeiue iiene a ianneaa

Ionoue oaaeeoea i?aaenoaaeaia a aeaea ianneaa. Oiaaea ia?aia, /oi
i?eoiaeeo a aieiao ii iiaiaeo iienea yeaiaioa — yoi iaoiae anao
yeaiaioia, ia/eiay n ia?aiai, aei oao ii?, iiea ia aoaeao iaeaeai
yeaiaio n eneiiui eeth/ii, eee iiea iannea ia eii/eony. Oaeie niinia
iacuaaaony eeiaeiui iieneii a iaoii?yaei/aiiii ianneaa. Ioi?iei aai ia
Ianeaea a aeaea i?ioeaaeo?u:

procedure LinearSearch(var T:tTable; k:tKey; var index:integer);

var i: integer;

begin

i:=1; index:=0;

while (ik do index:=index-1;

end;

A oaeii aa?eaioa noaiiaeony cia/eoaeueii iaiueoa n?aaiaiee,
neaaeiaaoaeueii, aeai?eoi ?aaioaao auno?aa i?aaeuaeouaai.

2. Aeaie/iue iiene

Neaaeothuee aeai?eoi oaeaea i?eiaiyaony aeey oaaeeoeu, i?aaenoaaeaiiie a
aeaea ianneaa, e?iia oiai, iannea aeieaeai auoue ioni?oe?iaaiiui ii
cia/aieyi eeth/a (aeey ii?aaeae?iiinoe — ii aic?anoaieth). Oiaaea i?e
iienea iiaeii eniieueciaaoue neaaeothuea niia?aaeaiey: aicuei?i yeaiaio,
iaoiaeyueeny a na?aaeeia ianneaa, anee aai eeth/ ?aaai eneiiiio eeth/o,
oi iu iaoee ioaeiue yeaiaio, anee iaiueoa — i?iaeieaeaai iiene a ia?aie
iieiaeia ianneaa, anee iaiueoa — oi ai aoi?ie. Iiae i?iaeieaeaieai
iiieiaai aiaeiae/iue i?ioeann: aiiaue aa??i n?aaeiee yeaiaio ec
aua?aiiie iieiaeiu ianneaa, n?aaieaaai aai eeth/ n eneiiui eeth/ii, e o.
ae. Yoio oeeee caeii/eony, eiaaea /anoue ianneaa, a eioi?ie
i?iecaiaeeony iiene, ia aoaeao niaea?aeaoue ie iaeiiai yeaiaioa. Oae eae
yoio aeai?eoi iiiaie?aoii ?acaeaaao iannea ia aeaa /anoe, oi ii
iacuaaaony aeai?eoiii aeaie/iiai iienea. Ieaea i?eaaaeaia
niioaaonoaothuay i?ioeaaeo?a ia Ianeaea.

procedure BinarySearch(var T:tTable; k:tKey; var index:integer);

var l,c,r: integer;

begin

index:=0;

l:=1; r:=T.n;

while (index=0)and(lk then r:=c-1

else l:=c+1;

end;

end;

Ia?aiaiiua l, r e c iaicia/atho niioaaonoaaiii iiia? eaaiai e?ay,
oeaio?a e i?aaiai e?ay /anoe ianneaa, a eioi?ie iu euai yeaiaio n
caaeaiiui eeth/ii. Iiene i?ae?auaaony eeai anee yeaiaio iaeaeai (index
0), eeai anee /anoue ianneaa, a eioi?ie ioaeii eneaoue, auea
en/a?iaia (oi anoue iiia? eaaiai e?ay i?aaunee iiia? i?aaiai). Aioo?e
oeeeea iaoiaeei iiia? na?aaeeiu /anoe ianneaa (c), caoai n?aaieaaai
eeth/ yoiai n?aaeiaai yeaiaioa n eneiiui eeth/ii. Anee auiieieeinue
?aaainoai, oi yeaiaio iaeaeai, anee n?aaeiee aieueoa eneiiiai, oi
onoaiaaeeaaai i?aaoth a?aieoeo /anoe ianneaa ?aaiie c-1, anee aieueoa —
iaiyai eaaoth a?aieoeo ia c+1.

3. Eeiaeiue iiene a nienea

Ionoue oaia?ue aeaiiua oaaeeoeu niaea?aeaony a nienea. A yoii neo/aa
iiaeii eniieueciaaoue aeey iienea aeai?eoi, i/aiue iioiaeee ia aeai?eoi
eeiaeiiai iienea a ianneaa. Ioee/ea eeoue a oii, /oi eciaiaiea iiia?a
oaeouaai yeaiaioa caiaiyaony ia?aoiaeii e oeacaoaeth ia neaaeothuee
yeaiaio nienea:

procedure SearchInList(T: tTable; k: tKey; var p: tItemPtr);

var notfound: boolean;

begin

notfound:=true;

p:=T;

while (pnil) and (notfound) do begin

if p^.key=k then notfound:=false;

p:=p^.next;

end;

end;

Ia?aiao? T a yoii neo/aa ia ioaeii aeaeaoue ia?aiao?ii-ia?aiaiiie,
iineieueeo ii yaeyaony oieueei oeacaoaeai ia ia/aei oaaeeoeu, a naia
oaaeeoea eaaeeo a aeeiaie/aneie iaiyoe. Aianoi iiia?a iaeaeaiiiai
yeaiaioa aoaeai aica?auaoue iieueciaaoaeth iaoae i?ioeaaeo?u oeacaoaeue
ia iaai (anee iiene aue oaea/iui) eee nil, anee iiene iaoaea/ai.

Nie?auaoue /enei i?iaa?ie a oeeeea n iiiiuueth aa?uea?a auei au
ia?acoiii: eaaeaeue ?ac aa?uea? i?eae?ony noaaeoue a «oaino» nienea, a
aeey yoiai ioaeii nia/aea iaieoe aanue nienie, ia/eiay n aieiau,
cao?a/eaay i?e yoii iiiai a?aiaie.

Eaeoeey 19. Ia?aiaoaiiua oaaeeoeu

Iaeaieaa i/aaeaeiui niiniaii o?aiaiey oaaeeoeu yaeyaony iannea, a
eioi?ii ianeieueei ia?auo yeaiaioia i?aaenoaaeytho niaie iieaciua
aeaiiua, a inoaeueiua yeaiaiou n/eoathony ionouie. Ieaea aoaeao
?anniio?ai ae?oaie aa?eaio i?eiaiaiey ianneaa aeey ?aaeecaoeee oaaeeoeu.

Iicaieei aeaiiui ?aniieaaaoueny a ethauo yeaiaioao ianneaa, a ia oieueei
a ia?auo n. *oiau ioee/aoue ionoua yeaiaiou io caiyouo iai iiiaaeiaeony
niaoeeaeueiia cia/aiea eeth/a, eioi?ia iu aoaeai caiineoue a eeth/aaia
iiea anao ionouo y/aae. Anee eeth/ — /enei, a ana iieaciua eeth/e
iieiaeeoaeueiu, oi iiaeii a ea/anoaa eeth/a ionoie y/aeee
eniieueciaaoue 0, anee eeth/e — no?iee, niaea?aeauea oaieeee, oi eeth/ii
ionoie y/aeee iiaeii naeaeaoue ionooth no?ieo e o. i. Ionoue a eeth/aie
yaeythony no?iee, oiaaea aeey oaaeeoeu iio?aaothony oaeea iauyaeaiey:

const empty = ”;

nmax = 1000;

type tKey = string;

tData = …..;

tItem = record

key: tKey;

data: tData;

end;

tTable = array[0..nmax-1] of tItem;

Ia?aae oai eae iiiauaoue aeaiiua a iannea caiieiei eeth/aaua iiey anao
aai yeaiaioia «ionouie» cia/aieyie. Caiineoue a oaaeeoeo aoaeai ia ana
aeaiiua n?aco, a iaeei ca ae?oaei, ii i/a?aaee. Aeey oiai, /oiau
ii?aaeaeeoue iiia? y/aeee ianneaa, a eioi?oth ioaeii iiianoeoue
aeiaaaeyaiue yeaiaio aeaiiuo, iaieoai ooieoeeth, cia/aiea eioi?ie
caaeneo oieueei io eeth/a aeiaaaeyaiiai yeaiaioa. A oaeie neooaoeee
iiene iiaeii aoaeao inouanoaeyoue aeiaieueii i?inoi: iaoiaeei cia/aiea
ooieoeee ia eneiiii eeth/a, e niio?ei ia yeaiaio ianneaa n iieo/aiiui
iiia?ii. Anee eeth/ yeaiaioa ?aaai eneiiiio eeth/o, iu iaoee oi, /oi
eneaee, eia/a — iiene ieacaeny iaoaea/iui.

?aaeeciaaiiay iienaiiui niiniaii oaaeeoea iacuaaaony ia?aiaoaiiie (eee
hash-oaaeeoeae), a ooieoeey — ooieoeeae ?annoaiiaee eeth/ae
(hash-ooieoeeae). Oaeea iacaaiey naycaiu n oai, /oi aeaiiua
aanii?yaei/ii ?aca?inaiu ii ianneao.

Oaia?ue iieaaeai, eae an? neacaiiia aiieioeoue a i?ia?aiio ia Ianeaea. A
ea/anoaa eeth/ae a iaoeo i?eia?ao eniieuecothony no?iee, iiyoiio iiaeii
i?aaeeiaeeoue oaeie aa?eaio oyo-ooieoeee: neiaeeoue eiaeu anao neiaieia
no?iee, e, /oiau iieo/aiiia /enei ia auoiaeeei ca iaeneiaeueii
aiciiaeiue eiaeaen ianneaa, aicuei?i inoaoie io aeaeaiey ia ?acia?
ianneaa:

function hash(key: tKey): integer;

var i: integer;

begin

sum:=0;

for i:=1 to length(key) do sum:=sum+ord(key[i]);

hash := sum mod nmax;

end;

I?ioeaaeo?a aeiaaaeaiey yeaiaioa a oaaeeoeo a i?aaeaa?eoaeueiii aa?eaioa
aoaeao auaeyaeaoue oae:

procedure AddItem(var t: tTable; item: tItem);

var h: integer;

begin

h:=hash(item.key);

t[h]:=item.key;

end;

O iaienaiiie i?ioeaaeo?u anoue iaeei nouanoaaiiue iaaeinoaoie: anee
yeaiaio, iiia? eioi?iai oeacaea iai oyo-ooieoeey aue caiyo, oi iiaua
aeaiiua aoaeoo caienaiu ia ianoi noa?uo, a noa?ua aanneaaeii en/acioo.
*oiau ?aoeoue yoo i?iaeaio aoaeai iuoaoueny iaeoe eaeie-eeai ae?oaie
naiaiaeiue yeaiaio aeey aeiaaaeyaiuo aeaiiuo. Caeanue iiiaaeiaeony au?
iaeia ooieoeey (aoi?e/iay oyo-ooieoeey), eioi?ay ii iiia?o caiyoiai
yeaiaioa e ii cia/aieth eeth/a aeiaaaeyaiuo aeaiiuo oeaaeao iiia?
ae?oaie y/aeee, anee e oai aoaeao caiyoi, auciaai aoi?e/ioth ooieoeeth
au? ?ac, e o. ae. aei oao ii? iiea naiaiaeiay y/aeea ia iaeaeaony.

Iaeaieaa i?inoay oyo-ooieoeey aoaeao aeiaaaeyoue e iiia?o caiyoie y/aeee
eaeia-ieaoaeue iinoiyiiia /enei:

const HC = 7;

function hash2(n: integer, key: tKey): integer;

begin

hash2 := (n + HC) mod nmax;

end;

Inoaoie io aeaeaiey ia nmax iiiaaeiaeeinue au/eneyoue ii oie aea
i?e/eia, /oi e a ia?ae/iie oyo-ooieoeee.

Nae/an iiaeii iaienaoue ieii/aoaeueiue aa?eaio i?ioeaaeo?u aeiaaaeaiey
yeaiaioa aeaiiuo a oaaeeoeo:

procedure AddItem(var t: tTable; item: tItem);

var h: integer;

begin

h:=hash(item.key);

while t[h].keyempty do h:=hash2(h,item.key);

t[h].key:=item.key;

t[h].data:=item.data;

end;

Ionoue a oyo-oaaeeoeo caianaiu ana iaiaoiaeeiua aeaiiua e o?aaoaony
iouneaoue aeaiiua n iaeioi?ui eeth/ii. Aeey yoiai aoaeai aeaenoaiaaoue
ii oaeie noaia: au/eneyai cia/aiea oyo-ooieoeee ia aeaiiii eeth/a, anee
y/aeea n iieo/aiiui iiia?ii naiaiaeia, oi yeaiaio ia iaeaeai, anee
caiyoa, oi n?aaieaaai a? eeth/ n eneiiui. A neo/aa niaiaaeaiey iu iaoee
ioaeiue yeaiaio, eia/a — iaoiaeei cia/aiea aoi?e/iie ooieoeee e niio?ei
ia eeth/ a y/aeea n iieo/aiiui iiia?ii. Anee ii ?aaai «ionoiio»
cia/aieth, oi iiene iaoaea/ai, anee ?aaai eneiiiio eeth/o — oi oaea/ai,
eia/a — aiiaue iaoiaeei cia/aiea aoi?e/iie oyo ooieoeee e o. ae. Ia
Ianeaea an? yoi auaeyaeeo oae:

const notfound = -1;

continue = -2;

procedure Search(var t: tTable; key: tKey; var index: integer);

var h: integer;

begin

h:=hash(key);

index:=continue;

repeat

if t[h].key = key then index:=h

else if t[h].key = empty then index:= notfound

else h:=hash2(h,key);

until indexnontinue;

end;

I?ioeaaeo?a auaea?o ioaao i ?acoeueoaoao iienea /a?ac
ia?aiao?-ia?aiaiioth index. I?e oaea/iii iienea oai aoaeao eaaeaoue
iiia? iaeaeaiiiai yeaiaioa, i?e iaoaea/iii — eiinoaioa notfound.
Eiinoaioa continue icia/aao «iiea ia iaeaeai» e eniieuecoaony oieueei
aioo?e i?ioeaaeo?u. I?e iienea nia/aea au/eneyaony cia/aiea ia?ae/iie
oyo-ooieoeee, a a index caiineony cia/aiea continue Caoai auiieiyaony
i?iaa?ea ia ?aaainoai eeth/ae, anee iii auiieiyaony, oi y/aeea ianneaa
iaeaeaia, e iu caienuaaai a? iiia? a index, eia/a, anee y/aeea ionoa,
oi yeaiaio ia iaeaeai (a index caienuaaai notfound), a o?aoueai neo/aa
iaoiaeei cia/aiea aoi?e/iie ooieoeee. Yoe aeaenoaey i?iaeieaeathony aei
oao ii?, iiea index ia ia?anoaiao auoue ?aaiui continue.

Aaeou:

Color

R

RightBottom

LeftTop

size

LT

Center

Data

Data

Data

Data

. . .

List

………..

…..

Tree

Data

Data

Data

Data

Data

Data

Data

Нашли опечатку? Выделите и нажмите CTRL+Enter

Похожие документы
Обсуждение

Оставить комментарий

avatar
  Подписаться  
Уведомление о
Заказать реферат!
UkrReferat.com. Всі права захищені. 2000-2020