IMD 1.18: 15/07/2013 8:37:55 turbo pascal tutor program disk   DO`  @`! #@%`')+-/1 3@5`79;=?A C@E`GIKMOQ S@U`WY[]_a c@e`gikmoq s@u`y{} @` @ ` @ `  @ ` o ǀ ɠ @ ` ٠  @`/@`!Oa   !Aa!!#A%a')+-/1!3A5a79;=?A!CAoGIKMO/SAUaW[]_a!Oeagikmoq!sAuawy{}!OaAa!Aa!Aa!AaO`  @`! #@%`')+-/1 3@5`79;=?A C@E`GIKMOQ S@U`WY[]_a c@e`gikmoq s@u`y{} @` @ ` @ `  @ ` o ǀ ɠ @ ` ٠  @`/@`!Oa   !Aa!!#A%a')+-/1!3A5a79;=?A!CAoGIKMO/SAUaW[]_a!Oeagikmoq!sAuawy{}!OaAa!Aa!Aa!AaREAD ME TUTOR COMQUIZ DTAwTUTOR HLPINTEGERSEX CHARS EX BINARY EX HEX EX %IFCASE EX $FORDO EX WHILEDO EX REPUNTILEX REALS EX .SCALARS EX <SETS1 EX ESETS2 EX QSTRINGS1EX YSTRINGS2EX cARRAYS1 EX lARRAYS2 EX xRECFILESEX READTEXTEX WRITTEXTEX STACK EX RECUR EX !  WELCOME TO TURBO TUTOR 2.0 -------------------------- For space reasons, the README file and the README.COM program are on the "Source Disk" (disk 2). To access this file, simply put the "Source Disk" in your disk drive and type README.Q)ͫCopyright (C) 1985 BORLAND Inc T0No Terminal Selected0PERm.' tC.PLXuËCKu.&2P2 XHur!.PSr.[XPSPSPS[XÜPSPS[Xûm릻} dPSQRVW..FFGG..#..,.=_^ZY[Xÿ2.t.OOK2.v t0.G u[_)PQYX%;u;&E&]P X[S>r3$ȋ >t%s > &=st +%6&=T`njhjQRȋӋČӃ_3hZYw 33SP&u&5njT&&E&E&E6 &<&D6&<&DÑ[_[S& &Ur3$ >njsW&&]s6 6&&\&D&D& &U&E&]<t&=&E&]& &U&&&]ȋӡ &E&]njKVuQhjJt1&&\&L&T&&])&E&]3É>hjW3_3333>t&=ČӃ3+jr;sȋ[h&j&U[&=>h>j3>>pu2>qu+tȀu tq&p%Ltpp u qq>ru<u2XZPRt5>ruLwt L<uLXXZPXZP 2=tt2tGU!]VQ6XZ<t FFY^Yr^QV6XZ9uFF^Y빋6XZ t >FF3P>XZ3&=&r3p^`b_~ Â#+CSQRWV2P^_ZY[SQRWVLU^.C t^] _.u Ȏ+شJ.DT.DV..LQV[^Y><.D> t 8:>H.DJ t DFV3&l&n& &Pt & &Ptr\ 3ft>8JD ô01 tú7 %  M Not enough memory$Incorrect DOS version$ Program aborted $P8D3l&n&XPuL6T9PV[. t53ҋ tSB[;t +NOJu^.;uPRVt2 t GW t:t \t\GFF.FG u=t_^Zr).B2Ί2Yr?Tr>늲V[RSt L[YSЊ t[+L3ҿ. 2G3.< t< uGI.< t< tGI+tCJuғÈ>[YXSQ#>[ZXEESPY>W2-+v G& :t󑻔CG&:t_&52>[GS38t08ur!>&r>38t->&ù@X62;vBF,D[ڋ_[ڋ+[Y_㑌[_^;sNO[XUPWSPحȭЭPP^XÜWU~ ë«XƫXثXX[];sòv;|;òh+r=r;jròI[XSrLtL&r<tÏdd#3^À>^uÊ^ [XSdRZd-f u RR6f\Zs ^C User Break0w  I/O Run-time error , PC=f Program aborted  yP[ËSQNJ݊2XXظbȸ6؉ y-C2'd 2+sut0C3?$ uCP3X0r% ru rsRZr2s tÊ-uCQYr -u=u-u[& 2A+^. 2A+Z62C6?:v6Ag[2+L6 G[262+ t'y6 A6 AGEtH 9uH -sH !vH wH rH Ë6 2G62Fڊ;v t u:ZYQd62F6 r&62+AV^NOAG&ddXrH62+v;v3҇6&d[62Dd62G6 2F3+r@ tBQWV^_Yt@GJu3&d[&S>WPHB>>6%W[S>WPH u>lP[Xud6\26@6@[6:t22AG u tòp[Z Q t2uY **t2u[ 36Ñ[XS*r2A6sCËFF6| 6D"22$[22 ;tNOG3t5 @3}Hu u3 @_  Q# A# 6G" t3 6"t@ "2܊ȀË$;øu;u@ ;øu;uH  t3> uދ:vއ׈*Ȁ(r߉>&>06΀r 3r ߊ2 t uus^uTÆއ*s6Ҁ u׊2,ruƀuu333À26 to tq233ҿG- u ߊ2s &Nuu͑ƀu  tɑ26 u333 t*;u ;u:&r *&Nu -tOs*&r;u ;u:&ƀu uYr r[333s[É3Հ倈.΀6>WVQY^_WVQY^_WVQY^_WVQY^_R3ZyRZƀtt:u t ;u;u: u33Ê yڸ u xy x3_Yڹ33 Sr!|Et*s2< r ЊRZ uy < r [ŀt-j t yYKy t.It@ux, uðE++ yٰ-/ s:  tF0CË]U u00FFuPR,MZXuQvYhìx-Sx9?+{Η@ uÀ΀QRSPYYYYs uÀ^_ZY[WVǀuπ*r< s t33øËڋ tǀuXSQR[_S;uDv5W} _s&>t &EEL&E&E^"2d6d&E$t&e&M>^u>^uPtD&€t&E>s&E&]&]&] tYB&33&Mr+s33QʋиB&Z&u&<tFBu B&f&E@&E&E&E&E Ïd6d&}u&U&+U t B&*@&3 븏d6d&}@u!Ïd6d&E$u&&E&vt&>s^ù !QS.:t [YFCYY<:u.._CONTRMKBDLSTCAUXUSRINPOUTERR&=u-=t<3ɲRU IZr&È^<u^Ïd8&dd>&Eu^&ddD&dd>&E@u^&d2d8&:WPX t_&d2._~r~_~`2<t9<t5<tC<t+<t'<t5<tC< tE< r:tъ'C s'Cxl Ku묊< r&Cu t uU CCbÊ&rrPX&r>>^uu&E uh$u&]&;] r_&]&C&]?W<u`;br  `C`<uL<uLL"_&E&M &Eðô?&&M&Ubs3&] u&@&]&] WSD[<t"& e< vCtS)[< v&e?_r?t^W&e_[&[St$r s&&Ý[S}tW(_r[S32WSQY[< t<t&e_C&_&[S2WQzY< t<t &e__ [<t&e< t< uG< u&e>>^u?&Mu&]&C&]&;] t%Pttt &M&+Mt@&&U&Ur;t^ t(<v I QxY[XSo[XSQWX+v S QPY[˻SQ@Y[CÒ[YEESQA[YS% u% TRUEFALSECC6*v2S QY[62C t 6SQY[CZ[.2C .SQY[C  d6d&Et RZ:t<t< w t &e3@322d6dQ8Y>^uQ Y>^u&MÏd6d@&3Rd6d&ELd>&}u^&d?@[^S>^uA>&&&Mr!;t#>?u t&M+3à^3ҏd_6d&MʋиB&QRY[r;u;t^[SD& u@ [SB&33f&MO[S[SB&33FPRB&337Y[PRӸB&(ZX&MI[Sht3۹!sË؋Ñ[_SM[_SJ?@dZ^_P>Y>^u ;t^&d?@d[XZ^_SQ _&&d&}tO&}tR&eZ&&`s^3&Mt3 t>?u P+ʎ3X@^Ïd6dAU s^Ïd_6dVU W_r־} ÏdZ6d t(:u,Ar<s܀>t ;r÷9:d6ddX6d uu@:\G^s3ۊ t FC&u&ûT)3ۏd6dPuBS=U Zr0ظB3r$?T*>ۋ&R\ "^!ZY|b4߃t*7PUU2PF2YHP2PF2YHߊF2䢹F2䢺]UULP~Y+}AFQF2䗊C2=t 2HL= t ;= t 2@'2P2PY2P@F2C2PYItFr]QUU~ PH PAP|"]QUUR~W2P \࠿2F2P2P2YHY+}OAFQ2PF2ފF2=t~W~AP~PYItFPP<]UUF2=t =t]UULLP~Y+}$AFQFWFC2K_CYItF~UW~P QP]UU)P~iY+P2P{~P]QUU PH]UUL(~ߊF2=tHPY# u" u(~uFF2=tHF2FF2]UULLv2ՈFF2P~ uF2F$F$2]!UUQFPFP~P܍~W~|PP]5UUQ~FPFP~P܍~W~;Pe P]UUF2=t~W%TRUE P0~WFALSEPP]UUF2PF2Y;|~W~߸ PP~WW~߱PSP]TUUF2PF2Y;|~W P~]P~WW~C߱PmSP]UUF2P~߱P+]SUUF2PF2P~ ޱPWߊF2P]WUULF2PF2PP~aY+}kAFQF2䗊C2PAPZuF2䗊C2PP޸P4F2䗊C2PP޸PYItF]UUUF2PF2PP]UUR~WP ރQPVފF2PPH޸PF2PF2PF2PF2PLDFF2= | =~~GF2PF2Y;|0~W~|݊F2PޱP݊F2PPrT=t>F2=.P Pc޸P\ޱP=~WF2Pm=t~PF2= tHY#P2Y uQ~ܱP3݊F2PP%ݸPF2PF2P~ W~ܱPP]NUUQ~WQF2PF2PPTP܊F2FF2]UUV~WQF 2PF 2PF2PPE܍~܍~W~؋F;F}HPF;F~HY#PF=tHY#P~Y#P~۸-PpY#P2Y FF24u F2 uTQ~۱PۊF2PP۸PF 2PF 2PTFFF] UUZ~WQF2PF2PF2PPMۍ~ۍ~W~׍~~ pP~~xY#PF=tHY#P~Y#P~ڸ.PnY#P~ڸ-P\Y#P~-.HY#P2Y FF24uF2 u$Q~ZڱPڊF2PPڸPF2PF2P,~W~]UULF4u LFF2=t FF2 ]UULPePF2PPF2PF2Y+@Y+}AFQMPXYItF]UUP P*~UٱPٸP]QUUWw*tָ]& P PINTEGERSCHARSBINARYHEXIFCASEFORDOWHILEDOREPUNTILREALSSCALARSSETS1SETS2STRINGS1STRINGS2ARRAYS1ARRAYS2RECFILESWRITTEXTREADTEXTSTACKRECURUUF2=tˊF2䢸]UUF2 umP~ױPV]SUUL~. Press رP ظPLڹ F]QUUFU=u~jױP׸PPFUFU2 ]RUU2䗸2P)]UUF2=tWw*TK=tW5:1=tW5 =tW5ԸPP}2P`F2䢻]UUAUvUP5~UjֱP|P~TֱPf]¢ ~W ӸP F2=t PPPP Pd F2=t^EPIָ-PPFFF=-t& - PuF+FF=*t * PRFnF=DtIF=uDIVP$F~FCannot DIV by zero!PO=MtGF=uMODPyF~FgCannot MOD by zero!PL PQFPP}K0 = AƱP|ŸPQFPPSPbŸP]PI^6GP^6GP+P:^6GP^6GP-P#^6GP^6GP*P ^6GP^6GPDP^6GP^6GPMP]Ã~W~W24u]UU5UvU2=LP P8űPsĸPP PŸ PűPRĸP䠹2HP2HP]UvUF2PƸAPZ uF2PaYPAY+FF2FF2]UvUF2PƸAPZ^uLF2PxF F2~FF2]UvUF2P P0ĸP)ıPdøPLF2PwPPIøP㠹2P2HP]UvUF2PŸ P~ƈFF2 ]UvUESCP¸PPPTr - QuitP¸P["OPPOSITES -- type some characters:P¸PPPPP]LrLFF2=t,LF2PP2=P|HY# u F2P2 u]UUUvUQ~|PPPPPFPTFPY+}OAFQF#F=uD1 PP/0 PPFFYItFQFPPAPPP]UUvU~WQ~&PP~WQ~&PP߱~P~&PP~iP~&P@P~Nd AND s~;iP~&P~X&#PP~) OR 9~/Pj~&P~X& PPK~ٿ XOR ~ƿP/~&P~X&3PPNOT ~薿P~&PP葿NOT ~lPտ~&PPg P賿PFP@P*H Number 1: P萿P<PP~WLL2P2PPPP_&2 uY Number 2: P8P<P@P~WLL2P2PPPPS_&2 u]FF~W~W2 ufP踾]UU0123456789ABCDEF   ~(UvU~WGō~W.6ō~hPY+~gIFQFC2PnP>HF~W~č~Fč~W~ĊF2dYAtN~WW~]SUvUY~W"č~\ĊF2č~J0u~W~6ĊF2H~W菼P蟼~č~ rʼnF~W~MF@.nP2PjPc~W~Í~ËF~ Í~W~ÊF2aÍ~øNus~ W~׻PP]鐾UvULPY+}fAFQF2PF2Y;uCQ~+ÊF2".P2PPڻPPPF2YPFYItF]UvU?UvvUF2=0|=9~ =A|=F~^6G2P^6G2Y;|^6G24u(PP^6&2YPܸ^6GF2PPPgۋ^6W^6胺F2P觻P蠺^6W^6ZPƺ^6&2".P2P^6^6&2PVP^6G2YPP^6&2YP=t^6G2=^6W^6G2PP PfݺPֺPPiڋ^6W^6肹P^6&2".P2P$^6^6&2P~P^6G2YPP^6&2YP=t^6G2=tHP^6G2Y# u0PPJPً^6&2=t^6&^6W^6&2H_&^6G= t=t^6G2=tHP^6G2Y# u0PP跸Pً^6&2=t^6&^6W^6&2@_&^6G]uFF~WP~W~&2"ᗁǁP 貺ߺ뺸 ߺٺ} ~&2".P2FPP~&2YP4L~ Q ѺYֈFF2PF2P2Y u]1NumberP}PPP------P_PP@PDecimal (0..9)P4PPPǶHexadecim al (0..F)PPPP|蚶Binary (0..1)PڶPPPOm^EP轶PP P2P-move up a linePP1 ^XP}Pָ/PPiPReturnPSP-move down a lineP2Pе ESCPPs蹵-exitPP^֍~WGF~P~W~W'2 u]UU UvUR~/P蛵PFY2PFW2P֊F2=tF~貶F~W~蠶P-_~റPLPFY2PFW2@P0F2=t#>PPPFY2-PFW2PL#ӈF~膴PPFY2PFW2PfՊF2=t6QtPƴ~NPjԱP賴PFY2PFW2@P&0F2=t# PP肴PFY2-PFW2P]WUvUP^6WY+}YA^6UQ^6U2Tᗋ^6W~PPP~&2PԃYIt ^6U莳,Press any key to step through the program...P贳]UvUCEnter character: P脳PPP~WL_&~&2P& P~#uEnter character: P)PPP~&2=u~&2PPPP]UvULP^6WY+}CA^6UQ^6U2Tᗋ^6W~&E~&E^6V^6T2=t%~WP^6U2HY@_&~WP^6U2Y_&P~貱nFF2=u{~W^6V2_WF2_&~W~W^6V2_&2_W^6G2_&EP~@F^6V2@^6VxYIt ^6U]UvUUvvU^6G2=t2^6G2=A}HP^6G2=Z~HY#^6G=t2^6G2=a}HP^6G2=z~HY#^6GL=t2^6G2=0}HP^6G2=9~HY#^6G=t ^6G]UvvU^6G2=t$^6G2P#APZ2^6Gj=t$^6G2PaPzϳ^6G>=t$^6G2P˲0P9ڲ裳^6G=t ^6G]ÃR^6T2=tT-F2=t<~W'P^6G2PݱT9' is upper case.=P6=t<~W'P^6G2P虱' is lower case.P=t9~W'P^6G2PU̯豮 ' is numeric.踯P豮P=tH~W'P^6G2P苯p' is not numeric or alphabetic.eP^F2PF2PQF2PͱP胮PF2 u ~PZPΊF2F F 2 ]UvUUvvU^6W^6\W谭if ('P軮蠭' >= 'A') and ('褮P蝮肭' <= 'Z') then舮P聭^6W^ else if ('PdI' >= 'a') and ('MPF+' <= 'z') then1P*^6W else if ('P ' >= '0') and ('PԬ' <= '9') thenڭPӬ^6XW谬elseP輬]UvvU P^6WY+}_A^6UQ^6U2Tᗋ^6W^6V^6V2=~HP~W^6V2_&2=uHY# u~W~߫~W^6V2_&2-P 0 竸P~W^6V2_&2Y-P~&2P~腫PP42 up^6V2@^6V'L^6U2PP^6U2Tᗋ^62@PP2Y uYIt ^6U XXXXXX]ø^6TTesting if/then statement...P+Fы^6Wr2 u ]UvU(UvvU^6W^6\Wrcase 'P|a' ofqPj^6WG 'A'..'Z':PL^6W) 'a'..'z':P.^6XW '0'..'9':P^6W elsePO]UvvU ~W^6  \蜩P輩P^6Z2Y-P^6Y2P~fPҩP2 uP^6WY+}A^6UQ^6U2Tᗋ^6W~W~Pl#P~&2P~ݨPIP2 uZL^6U2HP P^6U2Tᗋ^62PP2Y uYIt ^6U> XXXXXX]ø^6TcTesting case statement...P蜨΋^6W2 u1 end; { case }PbPPP]UvULާPress any key to continue...P/L/ƈFP5]Á2 u!2 usPŧ]UUUvUUvvUdUvvvU~WLL^6GP2PPPP_&~WQ~&PP4Ʊ]鐩#P~趦rFF=u~WF@_&2P0Y+F~WF^6WE藦2 uA~W~FWţ#P~9FFP蘦:P茦]UvvULFF2P~蛧Y;|YF2@FF2䗊C2=#tڥ P*PƊF2@FF2䗊C2PPPZ蝥PO葥PC]QLLPP1^6Wffor I := #1 to #2 do;PaPY+},AFQFQᗋ^6\PtYItF )Enter an integer value for each variable P5P˸PPFQᗋ^6\Wi2 u^6 W^6|P奱P蜤^6\Wy(I <= ^6NP跥r)PkPdK-------------------------------P~P(-P@PĸPY+}EAFQFQᗋ^6УP<P(PFH YPPYItF]UvUS臣~Y耣 #2) and (I <= #3) doPb^6W@ I := I + #4;PBPY+},AFQFQᗋ^6靱PUYItF)Enter an integer value for each variable P1ĸPPo^6 W^6\W^6W2 u$^6W^6 LP赞Pl^6W^6\'P萞PG^6iW^6\P kP"^6W^6ޜPGP-------------------------------P  P(-P@P茽PHY+}EAFQFQᗋ^6viP՜P(PFH YPP@YItF]UvUS2 u~Y ƝFF2=eP[PF2PF2Pϼϛ~F~W輛kP-*~諛PPF2PF2@P芼Q~舛PP蟻P蛸P(PF2H YPPNL幈F2 uF2=cQ(PP?P舛PF2PF2PQPi蟜P PUPF2PF2@PȻQ~ƚP2PݺP&P(PF2H YPP茻]UvUQ蒚+Step through the loop by typing any key... P蹚^6PP~Pu^6#P菚^6 P~~PrPP^6^6;HP^6^6;~HY#P24Y# u^6訙P^6\藙PQ^6^6;HPMPᙸPP.^6iYPř^6\HP贙Q^6^6;~HPP蒙PP^6^6^6^6PP~P.^6ܘPH^6̘P8~P,PPy^6衘P ^6\萘PQ^6^6;HPFPژPP'^6iRP辘^6\AP識Q^6^6;~HPP苘PP]Á?24ugPZu]UU2UvUUvvUdUvvvU~WLL^6GP2PPPPE_&~WQ~&PPɶ薗]%#P~KFF=u~WF@_&2P0Y+F~WF^6lWE,2 uA~W~FWZ#P~Ζ芘FۖP-荳ϖP!聳]UvvULFF2P~聖0Y;|YF2@FF2䗊C2=#to P迖PF2@FF2䗊C2PP藖P2P脖&Pxز]QLLPPƱ^6WI := #1;P^6 WߕrepeatP镋^6\Wƕ I := I + #2;Pȕ^6W覕until (I <= #3) or (I > #4);P蚕PY+},AFQFQᗋ^6iAP譕YItFE)Enter an integer value for each variable Pn艻PPǰ^6W2 uP;蛱ݔP/菱^6\W2 u^6W2 ur^6vW^6nPוP莔^6W^6\IP貕Pi^6W^6%P 莕PE^6iW^6PjP!------------------------------P<P(-P@P谴PY+}AFQF=u|F=t9FQᗋ^6%xP䓸P(PFH YPPO8FQᗋ^6%?P諓P(PF- YPPYItFn]UvUS2 uv咍~Yޒ蚔FF2=eÒP/PF2PF2P裳RF~W萒?P-~P뒸PF2PF2@P^Q~\PȒPsP輒P(PF2H YPP"L蹰F2 uF2=TPkPF2PF2P߲QPLӑ肓PﱱP8PF2PF2@P諲Q~詑PPP P(PF2H YPPo]UvUx+Step through the loop by typing any key... P蟑躷^6vP苑^6PzQ^6nPPSPbPP^6n^6p^6n^6P.^6\豐PQ^6nPPPPP~^6}P鐋^6mPِQ^6n^6;r~HP#P跐PP0^6i/P蛐^6P苐Q^6n^6;tHPկPiPP^6n^6;r~HP^6n^6;tHY P2Y u]Á  24u"規P]UUJìx-UvUS~WQ~PPޮPq~;~W~~WQ~ǖ PP謮P?~ 踐= H^6G^6G2 u~W ERROR P~Ŏ PP*PP@P衯P@Pu]UvU螎+-------------+PᎸPPPYw| |P躎PP@P1O|-------------|P蒎PPP%| = 7 8 9 / |PhPPPݮ| BS 4 5 6 * |P>PPP賮э| 1 2 3 - |PPPP艮觍| C 0 . + |PꍸPPP_}| |PPPP5S+-------------+P薍PPP )EscPxPP P  - QuitPVP训]UvUUvvU~貌ȌYu~W0PPÌ~荌~W~@F=t ~W.W]UvvU^6G2Pn z=tDu^6Wԓܓ^6G24P~豍=|HY#P^6G2P~萍P.P~ҋ莍Y+=|HY#Y P^6G2=.tHP^6G24Y#Y uf~艋0P0u~W莋P螋^6G2=.t ^6G~W~H^6G2PhPa~W_]UvvU~ 0P辋uH~W~袌_&2=.t ^6G~W~ɊxP~W]UvvULL^6G~茊^6W~;F=u .W^6G2 u#^6W^6:^6G2PV0P9e X=R"u^6G2=+t ==t= t(^6W^6耑^6u襑菑=-t(^6W^6P^6E萑_=/tZ^6)5踑u^6W.%%^6W^6^6L-=*t%^6W^6辐^6賐 ͐^6G2^6G^6G^6G2=-tH^6G^6WT~W0PP]UvvU^6G^6W:B^6W%-^6W0PP+^6GC^6G^6G^6G^6W]ÃbfL螦Z|F^6G2PF2P"C.("4Y#4uF2=t=tg=CtY=.t =0|=9~ ~W7<=t ~W])= t==t=+t=-t =/t=*t~WF2=uF2F u$]LN]UU Sunday Monday Tuesday Wednesday Thursday Friday Saturday UvUPPĬPP_P^6G2HY+}.AFQF2ᗁǍXPĆPYItF2F2F^6G2ǍP臆PߦF2PF2@PסP^6G2ᗁǍ蓇Y+}#AFQ-PP7P菦YItF2P2HP}^6G2@PY+}.AFQF2ᗁǍvPⅸP:YItF]UvU~FP貅ͫxNP蠅軫]QUvU~WL衣_&~&2=t\^6G2=t4Undefined, moving to SundayP5h^6G^6G2@^6Gc=t[^6G2=t6蚄Undefined, moving to SaturdayPτ^6G^6G2H^6G]UvUL~WF2PCOIu]UvU' Succ(Day) Pred(Day) QuitP-PP@P褤ƒ^DPPP@P艤觃^SPP$P@Pn范EscPۃP4P@PR]LWF]UUUvUnUvvULF F2PZY+}4AFQF2P~4uF2F YItFXF 2]~ 豂ǂ= كP  PPF2P芣[PPPNAFFLF2P~a/FF2=uF2 u,PP蠂PF2PP节P⢊F2HPF2Y;..PcP転FFF2PF2Y;u6F2 u,PP PxF2PP PbF2@FF F2@FF2=Z]PP΁P&F2 u;PP讁P]YUvULLAFF2PF2PL號FF2=t=t"F2=At ZF F2HF=t=t"F2=Zt AF F2@Fi= taF2P~舃蚄u&~W~q螃F2訃ZŃ#~W~KxF2肃&蟃F2PF2YPAY+PF2PF2P~u-F2PP詂  P-PPMP襠*F2PP| P쀸 P倱P Px2HP2HPo2PF2= tHY uo]UvUzSet1: PPPP>\ABCDEFGHIJKLMNOPQRSTUVWXYZPP2Set2: P~P(PPABCDEFGHIJKLMNOPQRSTUVWXYZPLP褟~.Highlight a letter to include it in the set...P)~8Highlight letter on/off Move left Move rightt~ FinishedvP~PPP&D~SPACEP~PPP$~^SPt~P!PP~^DPW~P1PP̞}EnterP7~PBPP謞]Ã~WҀ~WĀ~WPPN2 u}Set1 :P}~SӀPP ~W.PP2 uJ6}Set2 :P}~臀PPPP|PJ}e| Set1 * Set2 P2}~~豀*PPa| Set1 + Set2 P|~w~mSPP!l| Set1 - Set2 P|~7~-!PP,| Set2 - Set1 Pr|~~~~jPP]UUUvULL~W~ {Counting card:P|P^P4Y+}kAFQQFPPȚP|P|P|P{PL*u.~W~ /~\~Fh~  ~YItFX]UvU A23456789TJQKHDCSLLFH @FFH @FF2.2PF2.2P\}{P{PF2PF2Pt]UvULL{zPz-oz Dealing card:PzP FFF2=tHPF2P~ }#~4Y u 4@ yFF2@FQF2PP9PHzPP@P迚F2PL螟ua~W~ ||F2|~} |~W~ ||F2|i} |l~ \||}u]@~Wu2 u~WV| |~W~W]UUUvUPP]UvULx Position :P/yPPP觙PY+}'AFQQF2PP痱Px蜔YItF]UvU{xEnter up to 10 characters for~=xkyPxstring, and press return: JyPxPPP~UWQ2P2P PޙPx]UUvULL~WwP-xPPFP襘PFPzP~wFyY+}1AFQFC2Pw *zxPwP4YItF]¤UvUPP Jw!Delete character at position (1..Q~wxPPW(x w): xPYwP豗LL2P2PPP~vsxP{F2 u_~F&2F~WFPxv Deleted 'F2Pwv': wPv~XvPvPv]UvUJvEnter a character to insert: PvPPPL2P2PjF2 u~uw=uEnter position (1..Q~u  Sw@PPvu): vPuPPPlLL2P2PPP~Wuw@P FD2 ukF2P~WFP&w~WF2PP;u"u Inserted 'F2P"vu': vPSu~tPGuP]UvU~Wt another Pu+ZW~t~tuPttConcatenated: PtZatPtP]QQe~WWtPgt~WIt a Pt2 uj+tYour String : Plt~sP`tP~W2 u&~W2 u~sPt]UUUvUPP诙]UvU~csuFFHFPFY+})AFQFC2PPsPYItFFC2PPu:t P3t-P,tPgsP迓2P2HP跎F@FFPFY+})AFQFC2PP!sPyYItFrPsg]SUvUr,Which position would you like to highlight? PrPPP/~WLL2P2PPP~rsP̕_&i2 ug r Highlighted Q~&PP3sq : rP5rPPP誒~qPr~&P#qPrd]UUvULL~WqPqP~`qsY+}4AFQ~W~CqFC2eP`rPYqYItF6qUpper Case : PwqPϑ~pPdq^6XPn]UUvULLpCentered : P'qPpPqwPY+})AFQQFP PݏPpPDYItFpPp2POY+}0AFQQF PP葏PpPYItF4pPp挃Q%pPwpPP~oqY+P PVpP讐~oPCp^6XPM]Qo;This procedure demonstrates some simple string functions...PooEnter String: PoPPPA~WQ2P2PP%PXo?oPo謕}2 uPP؊PY+}1AZQQZPP3PBoP蚏YItZnYour String : PoPP@P荏~nPnPRnPnJ~onPnXW2 u%~KnPn\W\5nPnO]UUUvUF2PF2Y+mPF2PF2Y+lYFRFR2]OUvU~W~W~$P,k~(W~$Pk~Wl@_&E~Wl@_&E~W~&E2_W~&E2_&E~&EM~&EL]UvU~W0mX and Y Coordinates: [ , ]PemP(PPڍ~WLL>PPPPP_&2 u~WLLBPPPPPJ_&E2 u~W~&2_W~&E2_&E!2 u<贊Ul-That square was guessed already. Pick again.Pzl蕒(PPƍ~W~&2_W~&E2_&E!2=tkP*lE~W~&EL2@_&EL XXXX]UvULLXPPkP PPYwk PkPP@P=PY+}+AFQQF2PP}PkPYItFYPPnkPPP㋸PY+}sAFQQF2PP# PkP+kPPF2@P蜋PY+}"AFQj O PjPLYItFYItF]NUvU~WXPPjF2PP~&2YP~&E2@P~W~&2_W~&E2_&E!]UvU ~W~W2 u~W~W~&2_W~&E2_&E2_&EM~&EM2 uNه~WPniYOU FOUND IT! --- Tries: Q~&EL2PP脈UjPi諏~WPL~Ngf=t~Wi squarei~Wh squareshhSquare [Q~&2PPih , iQ~&E2PPih] is iQL~NeKPP过i~Xhikh from the treasure.liPhŽXX]N5h1Try to guess the location of the hidden treasure.PVhq~W~N5eB~WF2P2Y u]UUVUvULP Y+}%AFQF2Wcf@_^6AYItF]UvUcg+--+--+--+--+--+--+--+--+--+--+PgPHPP (g| | | | | | | | | | |P[gPHPPχf+--+--+--+--+--+--+--+--+--+--+P gPHPP蔇f SortArrayPfP- PPmf | | | | | | | | | | |PfP]UvULLHPPP Y+}nAFQQF^6A2PPQPgPg Pge gPBfP2@P2P赆2P2HP腁YItF]UvUQF^6A2PPՄPfPf PfPePPFHYPP7Ue--PePQF^6A2PPrP?fP8f P1fPleP2@PPޅd--PLeP褅]UvULLFPFPXXF^6A2FFWF^6A2_^6AFF^6AXWFPFPXW]UvULLYd+Sorting the array elements (bubble sort)...PdP P@P PY+~IFQPF2HY+}uAFQL貉uqF2䗋^6A2PF2@^6A2Y;F2PF2@PF2PF2@PXV.YItFYAtNmXX]à ]UUUvULLmaFF=uR&c I/O error #QFPPP!dc occurred.dPKcPPP^6G^6G2FF2 ]UvU^6Wb RECFILES.DTArz^6mzL9u]UvUQcbPb P`PbP(PPQ9bPb P6PbP(PPQbPabP PUbP(PPʂ]UvUQ^6zPPPbP"PP荂]UvUQ^6zPPɀPaP)P@PO]UvUQ~:aPa HPPPaP(PPQ~ aPxa HP"PkaP(PPQFPP7PFaP(PP軁]UvUL^6W^6y\yL^u~WQ(PP HP^ `2 u~WQ(PP HP/ b`2 uULL(PPPPcPƃF2 u'^6?x~]xLu Ds]UvU^6xFFF=}HPFP^6xY;|HY# u[^6WF4xL6uC^6w~wLu%~\^6WFw}]UvU~W_/The data file currently contains records.P^ZW^.The file pointer is currently at record .P^~^P^PPPdZd^P^PP@PG_^A: P^PP[E^ Add recordsP^P~*^B: Py^PP&^Forward one recordPP^P~]C: P=^PP~]Backward one recordP^Pk~]ESCapeP]PP~] First Name:P]P(- PPM~k] Last Name:P]P(- PP%~C]Age:P]P(-PP~!]Choice: Pk]PPP}]UvUL PPxLR{QFF2=At!=Bt P=CtP^6G2P2Y u]UvU^6tLu^6vLu]ÃMFy7]UU UvU[A: P<\ P@P|[AssignP!\Py|[B : P\ PP|[ResetP[PJ|[C: P[ PP|v[ReadP[P|b[D: P[ PP^|H[ReadlnP[P{2[E: P[ PP.|[ClosePe[P{[ESCapePO[ PP{ZChoice:P1[PPP{]UvUL PPdvL]APE]]] ]zyFF2=At FW=Bt FF=Ct F5=Dt F$=Et F=t=tFF2]UvUQF2=tC~WY2 The file operation was successful.PY=tC~WY2 The file has not been assigned yet (use Assign).PsY=tC~WJY2 The file needs to be opened first (use Reset).P(YB=tC~WX2 The file needs to be closed first (use Close).PX=t~WXPX=tC~WX2 At End-of-File. Cannot read any more data.PyX=tC~WPX2 At End-of-Line. Cannot read any more data.P.XH=t@~WX2The data file does not exist. Please run WRITTEXT.PWF2PZPZPZ[uvPPLyJ~qWPWPPPRx]UvU^62nu^60F2=t:^62nu^60^62Zj~l5U^62?j~llU^602=tWVLast line read:PWPPP}wQ~{VPVPvPVP.PPPw]UvU^612 WF2_^6 W~&E2^60^602=tF2=t^62WUTEXT.DTAf(Ti=t1^62gT=u^60~&0=t=t F2P/=t^62gS^602Pm~&2=tHP^612=tHY# u^62gpS~&2^61]1 W$9RL5P12=t]UUUvUTA: PT P@PuTAssignPTP.utTB: PT PPpuZTRewritePTPtCTC: PT PP?u)TWritePvTPtTD: PcT PPuSWritelnPETPtSE: P2T PPtSClosePTPntSESCapePT PPtSChoice:PSPPPWt]UvUL PPoLiVAPExVkVeV V+rFF2=At FW=Bt FF=Ct F5=Dt F$=Et F=t=tFF2]UvUQF2=tC~WR2 The file operation was successful.PoR=tC~WFR2 The file has not been assigned yet (use Assign).P$R=tC~WQ2 The file needs to be opened first (use Rewrite).PQa=tC~WQ2 The file needs to be closed first (use Close). PQ=t~WeQPuQF2PmTP|TEUuoPPriD~ QPyQPPPq]UvUQPText to write:P8QPPPq~WQ-PPPrPPF2=t^62d~vPgN^62c~WPggNPP r]UvU^612 WF2_^6 W~&E2PZ~&E2=tF2=t^62WOTEXT.DTA`NX=t ^62aM^6 0=t=t F2P=t^62aM~&2=tHP^612=tHY# u^62ayM~&2^61] 1 W$;LJLP12=t 2 u:N.Now run READTEXT to see  what you have written.PNu]UUUvU^6G‰FV P^6G2Y+FFRP33[YRuQQQ~&PPvmPNP0nPyNPPF2PnF2@F~&E‰FV^6G2=F<PP/NPP P^6G2Y+PnM StackTopPMPUn]UvU^6G2= tOkqM=The stack is full. You cannot push any more numbers onto it.PMs%MNumber to push onto stack: P\MPPPmLL2P2PPPcPzpFPPyn2 u~A~F&~W^6G_&E&UF‹^6G^6W^6G2@^6GQFPPkRL was pushed onto the stack.KMPLr]UvU^6G2=tQ]jK?The stack is empty. You cannot pop any more numbers off of it.PL,r^6&F^6G‰FV^6&E‹^6G^6W~@^6G2H^6GQ[KPKPXkPKPP P^6G2Y+HPlQFPP[jK was popped off of the stack. LPFKaq]UvULP^6G2Y+}AFQYItF]Ã33҉FVFJA: PJPPkxJPush a number onto the stackPJPkLJB: PJPPHk2JPop a number off of the stackPgJPjJESCapePQJPPjPPeLSh>FIP"J=pF2=At =Bt2 u]UUu UvUUvvUF 2=F RP33[YMPF2Y u6 PPIPF2PPF 2HYPiF2~ &2PPQIPF2PPF 2HYPi~ &ERPF 2@PF2PF2Y+PF2PF2P"~ &E RPF 2@PF2PF2YPF2PF2P] ^6GRPP PPPQ^6GPPwgPHPPPh]UvUUvvU~ &RP33[Y1Lux~  D<~ &=W^6G2_&~ &=W33_&E&U~ &=W33_&E &U ~ &=WF_&E&U^6G@^6G_^6G2P~ &=&2Y;~"~ &=W~ &RPF2@P$~ &= W~ &RPF2@P] GNType in the characters to add. Press the space bar to stop adding characters.PG!mL!e^6G2 uc^6G2PI P~IsJu^6G2= u^6W33RPP?^6G2= t7FPFl]UvU~&}&ERPF[YIJPFRP33[Y8JY FF2 ]UvU;UvvU^6GRP^6G[YIuML^6GRPlu^6&}W33_&E&U^6&}W33_&E &U ]UvvU^6&} W^6&E_&E&U^6GRP^6G[YXIu_L^6GRPu'^6&}W^6&E _&E&U$^6&}W^6&E _&E &U ]UvvU^6&}W^6&E_&E&U^6GRP^6G[YHu_L^6GRPu'^6&}W^6&E_&E&U$^6&}W^6&E_&E &U ]UvvU^6&E‹^6G^6W^6&E RP33[YGu^6&E ‹^6G^6W^6&} W^6G_&E&U^6W^6&E _&E &U ^6&}W^6&E_&E&U^6&ERP33[YUGu_L^6GRPu'^6&}W^6&E_&E&U$^6&}W^6&E_&E &U ]Ã~&ERP33[YFu%~&E RP33[YFu"~&E RP33[YFuQFRP^6G[YcFux~&ERP33[YYFu~&E‹^6G^6WE~&E RP33[Y&Fu~&E ‹^6 G^6W33ҋ^6G^6W~ 6^6GH^6G]UvU~&RP33[YEuWSAThe character 'PUB^6G2PDB'P=B"A is not in the tree."BP]Axgk^6G2P~&=&2Y;t~&RP=^6G2P~&=&2Y;|~&=W+~&= W]UvU|@Enter the character to delete: P@PP P$aL^^6G^6G2PDC @P~RCDu@Pi@f2 u ^6Wy]UvUL? Total Nodes:P"@PPP`?/ \P?PP@Pp`PY+}=AFQy? / \P?PF2  PP-`YItFPY+}9AFQ,?/ \Py?PF2PP_YItFPY+}7AFQ>/ \P2?PF2PP_YItF33ҋ^6G^6W^6G]UvU>Deleting the tree...P>d^6GRP33[YBu"^6&2^6G^6W'>Py>d]Ã% >A: PZ>9PP _=Add node to treeP6>P^=B: P#>9P@P^=Delete node from treeP=PQ^=ESCapeP=9PP^9PP.YL[1Fb=P=cF2=At1 =Bt2 u]UUUvU=Pa=yie]UvU~WľXLWľX*P/:ľXW<QUIZ.DTAT~TľXW:=tH_&EvľX&Ev2 u>ľXkU4u,ľXT]T:]WľXLWľX*93G<Pt8P8&Uh8# Sorry, no questions for this topicP8J`]UvU!8 Ready for another? P^8T~WL;Y;N;; O;V_&~&2=YuPn_7NoP8S~&2=YtHFF2 ]UvUP&_^6\^6G24uL>WU4u)^6G=HP^6GP>8PY;|HY# u>W^6GO&5Q6P57S63DATA ERROR: Re-copy QUIZ.DTA from your master diskP6^z ^6G]ÁF2=tEL>W^WFPc[[2PF2=uHY# u\@\L\P^i3~W4uMF2=t:5The correct answer is F2P6.P6P 6P]Pe]L>W^WFP[[2 uL~W]4u[^Jz5! No more questions. Press P5P%]L_8k8 81TF\P]UU UvUU45No Terminal Selected5u=UHoL3LHNL"Run TUTORINS to install  the TUTOR.@L23L/]UvULPS]W^P1Wv4 TUTOR.HLP}4oaWP~WaP]]UvULLP\P[.52P.52P.52P.52HYP.52P.52HYPIlP\.52P.52@PO3TURBO PASCAL TUTORP4O.52HP32.00=5Y+P.52@PSO32.00P3O.52HPy3MS-DOS5Y+P.52POZ3MS-DOSP3LO.52P.52HPN33Copyright (C) 1986 BORLAND Inc.Pf3 OF.4PF2=|HY# ud&F2@F.u LCQF_[P[]UvULPIZP PRN+PP2NPOY+}AFQ-PP2_NYItF+PP2ENP PMPY/2 Turbo Pascal Tutor Pm2-P]PZd%F~WwPH/E]UULLF 2PF2PM+PP2MF2PF2PeM+PP1MF 2@PF2HY+}IAFQFPF2P-M-PP1_MFPF2PM-PP1BMYItFF 2PF2PL+PPs1MF2PF2PL+PPT1LF2@PF2HY+}IAFQF 2PFPL|PP1LF2PFPsL|PP0LYItF]UUUvU^6GPHY^6G H^6GKP^6GY+^6G^6GPP^6GY+^6G]UvUFW2=t F F <F>FFW2PuW^6GHPFUH^6^6oYPPFUH^6YPQKF2#FAPFUHYFF2PF2P2{0`/: r0~:/h0F2P[0P/WPWd=u PYN=t3n   %),26;>DIMQ[ 10 DIV 3 =  c 45% xSV ^[Ӌ|CzR55  Loading 0 =ԋYZr-+ʴ?r$;tuO>4OC&K&g File not found)0 _<tU3 New File S[" eInvalid directory f HFile2oo bigzKz3@3>t2 t/Workfile E  noCCDIV finds the whole quotient when one operand is divided by another 10 MOD 3 =  c 45% xSV ^[Ӌ|CzR35  Loading 0 =ԋYZr-+ʴ?r$;tuO>1 C&K&g File not found)0 _<tU7 New File S[" eInvalid directory f HFile4oo bigzKz3@3>t2 t/Workfile E  noB>MOD finds the remainder when one operand is divided by anotherother1 + 5 * 3 - 4 / 2 =c 45% xSV ^[Ӌ|CzR75  Loading 0 =ԋYZr-+ʴ?r$;tuO>6 C&K&g File not found)0 _<tU16New File S[" eInvalid directory f HFile14 bigzKz3@3>t2 t/Workfile E  noD)* and / are evaluated first, then + and -is divided by anotherother3What expression is the same as (1 + 2 * 3 - 4 / 5)? ^[Ӌ|CzR(1 + (2 * 3) - (4 / 5)) ԋYZr-+ʴ?r$;tuO>((1 + 2) * 3 - (4 / 5))g File not found)0 _<tU((1 + 2) * (3 - 4) / 5)" eInvalid directory f HFile(1 + 2 * (3 - 4) / 5)z3@3>t2 t/Workfile E  noA.Expressions in parentheses are evaluated firstvided by anotherother9How many bytes are used to represent an integer variable?|CzR11 + (2 * 3) - (4 / 5)) ԋYZr-+ʴ?r$;tuO>2 1 + 2) * 3 - (4 / 5))g File not found)0 _<tU3(1 + 2) * (3 - 4) / 5)" eInvalid directory f HFile#Depends on the value of the integert2 t/Workfile E  noBFAn integer can represent 64K - 1 different values; 64K = 2 to the 16th0Which functions return a result of type integer?variable?|CzRPred, Succ, Chr(4 / 5)) ԋYZr-+ʴ?r$;tuO>Pred, Succ, Sqrt4 / 5))g File not found)0 _<tUPred, Succ, Ord 4) / 5)" eInvalid directory f HFileAll of the abovealue of the integert2 t/Work file E  noC-Chr(81) = 'Q'; Sqrt(81) = 9.0; Ord('Q') = 81;lues; 64K = 2 to the 16th UpCase('2') =ns return a result of type integer?variable?|CzR'@'d, Succ, Chr(4 / 5)) ԋYZr-+ʴ?r$;tuO>' 'd, Succ, Sqrt4 / 5))g File not found)0 _<tU'2' , Succ, Ord 4) / 5)" eInvalid directory f HFileChr(2) the abovealue of the integert2 t/Workfile E  noC>UpCase converts a lowercase letter to its uppercase equivalentthe 16th Write(Chr(1)) will print out '1'of type integer?variable?|CzRTrue, Succ, Chr(4 / 5)) ԋYZr-+ʴ?r$;tuO>False Succ, Sqrt4 / 5))g File not found)0 _<tU'2' , Succ, Ord 4) / 5)" eInvalid directory f HFileChr(2) the abovealue of the integert2 t/Workfile E  noB!Write(Chr(48)) will print out '0'r to its uppercase equivalentthe 16th:How many bytes are used to represent a character variable?|CzR1 ue, Succ, Chr(4 / 5)) YZr-+ʴ?r$;tuO>2alse Succ, Sqrt4 / 5))g File not found)0 _<tU32' , Succ, Ord 4) / 5)" eInvalid directory f HFile%Depends on the value of the charactert2 t/Workfile E  noA>A character can have 256 different values; 255 is 2 to the 8ththe 16th-Which functions return a result of type char?ter variable?|CzRPred, Succ, Chr 4 / 5)) ԋYZr-+ʴ?r$;tuO>Pred, Succ, Sqrt4 / 5))g File not found)0 _<tUPred, Succ, Ord 4) / 5)" eInvalid directory f HFileAll of the abovealue of the charactert2 t/Workfile E  noA-Chr(81) = 'Q'; Sqrt(81) = 9.0; Ord('Q') = 81;5 is 2 to the 8ththe 16thChr(Ord('A')) = 'A'urn a result of type char?ter variable?|CzRTrue Succ, Chr 4 / 5)) ԋYZr-+ʴ?r$;tuO>False Succ, Sqrt4 / 5))g File not found)0 _<tUPred, Succ, Ord 4) / 5)" eInvalid directory f HFileAll of the abovealue of the charactert2 t/Workfile E  noADOrd converts from char to integer; Chr converts from integer to charth)Write(LST, #12, #13, #10) is the same as:har?ter variable?|CzRWrite(LST, ^L, ^M, ^J); ԋYZr-+ʴ?r$;tuO>Writeln(LST, ^L); / 5))g File not found)0 _<tUWriteln(LST, #12); / 5)" eInvalid directory f HFileAll of the above lue of the charactert2 t/Workfile E  noD@#12 is a form feed; #13 is a carriage return; #10 is a line feedcharthWhich expressions are true?s the same as:har?ter variable?|CzR 1 and 1 = 1^L, ^M, ^J); ԋYZr-+ʴ?r$;tuO> 1 or 1 = 1T, ^L); / 5))g File not found)0 _<tU 1 XOR 1 = 0, #12); / 5)" eInvalid directory f HFileAll of the above lue of the charactert2 t/Workfile E  noD@true and true = true; true or true = true; true XOR true = falsecharth1001 (binary) =ns are true?s the same as:har?ter variable?|CzR2 and 1 = 1^L, ^M, ^J); ԋYZr-+ʴ?r$;tuO>9 or 1 = 1T, ^L); / 5))g File not found)0 _<tU5 XOR 1 = 0, #12); / 5)" eInvalid directory f HFile11l of the above lue of the charactert2 t/Workfile E   noB@Binary "columns" (from right to left) are increasing powers of 2charthWhich expressions are true?s the same as:har?ter variable?|CzR 1 and 0 = 1^L, ^M, ^J); ԋYZr-+ʴ?r$;tuO> 1 or 0 = 0T, ^L); / 5))g File not found)0 _<tU 1 XOR 0 = 1 #12); / 5)" eInvalid directory f HFileAll of the above lue of the charactert2 t/Workfile E  noCCtrue and false = false; true or false = true; true XOR false = truerth$10 = expressions are true?s the same as:har?ter variable?|CzR10and 0 = 1^L, ^M, ^J); ԋYZr-+ʴ?r$;tuO>20or 0 = 0T, ^L); / 5))g File not found)0 _<tU16 OR 0 = 1 #12); / 5)" eInvalid directory f HFile32l of the above lue of the charactert2 t/Workfile E  noCFHexadecimal "columns" (from right to left) are increasing powers of 1610 == expressions are true?s the same as:har?ter variable?|CzR$10nd 0 = 1^L, ^M, ^J); ԋYZr-+?r$;tuO>$A0r 0 = 0T, ^L); / 5))g File not found)0 _<tU$0A R 0 = 1 #12); / 5)" eInvalid directory f HFile$01 of the above lue of the charactert2 t/Workfile E  noC(Hexadecimal digits range from 0..9, A..Ft) are increasing powers of 16$22 = expressions are true?s the same as:har?ter variable?|CzR220nd 0 = 1^L, ^M, ^J); ԋYZr-+ʴ?r$;tuO>440r 0 = 0T, ^L); / 5))g File not found)0 _<tU34 R 0 = 1 #12); / 5)" eInvalid directory f HFile101 of the above lue of the charactert2 t/Workfile E  noCFHexadecimal "columns" (from right to left) are increasing powers of 16if not false then ClrScr;e?s the same as:har?ter variable?|CzRThe screen will be erased ԋYZr-+ʴ?r$;tuO>The screen will NOT be erasedFile not found)0 _<tUIs not a legal Pascal statementeInvalid directory f HFile101 of the above lue of the charactert2 t/Workfile E  noAD"False" is a pre-defined boolean constant. ClrScr clears the screen16if 0 = true then ClrScr;;e?s the same as:har?ter variable?|CzRThe screen will be erased ԋYZr-+ʴ?r$;tuO>The screen will NOT be erasedFile not found)0 _<tU Is not a legal Pascal statement Invalid directory f HFile101 of the above lue of the charactert2 t/Workfile E  noCC"True" is a pre-defined boolean constant. ClrScr clears the screenn165What variable type cannot be used as a case selector?able?|CzRbooleaneen will be erased ԋYZr-+ʴ?r$;tuO>charscreen will NOT be erasedFile not found)0 _<tUintegera legal Pascal statement Invalid directory f HFilestring the above lue of the charactert2 t/Workfile E  noD9A case selector cannot have more than 256 possible valuesthe screenn160Which of the following is true about FOR loops ?ctor?able?|CzR%A FOR loop must execute at least once+ʴ?r$;tuO>-The index variable is always incremented by 1)0 _<tU-The index variable cannot be safely modified ctory f HFileA FOR loop can be infinitee charactert2 t/Workfile E  noC 2This is a legal FOR loop: for i := 10 downto 1 do valuesthe screenn16EWhat variable type CANNOT be used as an index variable in a FOR loop?Rintegeroop must execute at least once+ʴ?r$;tuO>byteindex variable is always incremented by 1)0 _<tUreal ndex variable cannot be safely modified ctory f HFilecharR loop can be infinitee charactert2 t/Workfile E  noC(The index variable must be a simple typeownto 1 do valuesthe screenn16for i := $01 to $100 do;T be used as an index variable in a FOR loop?RWill execute 100 timese at least once+ʴ?r$;tuO>Will execute 256 times lways incremented by 1)0 _<tUIs not a legal Pascal statementfely modified ctory f HFileNone of the above infinitee charactert2 t/Workfile E  noBFHexadecimal "columns" (from right to left) are increasing powers of 16for i := i to i do;0 do;T be used as an index variable in a FOR loop?R#This statement will execute 0 timesce+ʴ?r$;tuO>#This statement will execute 1 time ented by 1)0 _<tUIs not a legal Pascal statementfely modified ctory f HFileNone of the above infinitee charactert2 t/Workfile E  noB9The bounds of a FOR loop must each be a scalar expression powers of 16)A REPEAT loop will execute at least once by 1)0 _<tU(A WHILE loop must have an index variablefied ctory f HFile2A WHILE loop can be infinite; a REPEAT loop cannotkfile E  noB8A REPEAT loop is checked for exit at the end of the loopn powers of 16while true do;in difference between a WHILE and REPEAT loop?FOR loop?RIs an infinite loop ecute at least once?r$;tuO>Will execute once and then stopeast once by 1)0 _<tUWill never executehave an index variablefied ctory f HFileIs not a legal Pascal statement REPEAT loop cannotkfile E  noA=A WHILE loop is checked for exit at the beginning of the loopers of 160Which of the following loops will never execute?REPEAT loop?FOR loop?Rwhile (2 > 3) or (5 < 10) do least once?r$;tuO>while true and false do en stopeast once by 1)0 _<tUwhile true or false do an index variablefied ctory f HFilewhile (6 <= 6) and (5 >= 5) dot REPEAT loop cannotkfile E  noB,true and false = false; true or false = truenning of the loopers of 16#Which of the following is NOT true?ever execute?REPEAT loop?FOR loop?R(A REPEAT loop must execute at least once?r$;tuO>+A REPEAT loop doesn't need a begin/end pair 1)0 _<tU*A REPEAT loop must have an index variable ed ctory f HFileA REPEAT loop can be infiniteot REPEAT loop cannotkfile E  noC-"repeat until 20 > 10" is a legal REPEAT loopning of the loopers of 16repeat until true;wing is NOT true?ever execute?REPEAT loop?FOR loop?RIs an infinite loopexecute at least once?r$;tuO> Will execute once and then stop in/end pair 1)0 _<tUWill never execute have an index variable ed ctory f HFileIs not a legal Pascal statement REPEAT loop cannotkfile E  noB8A REPEA T loop is checked for exit at the end of the loop loopers of 16,Which of the following loops will never end?ute?REPEAT loop?FOR loop?Runtil true and false; cute at least once?r$;tuO>until true or false;d then stop in/end pair 1)0 _<tUuntil (-2 < 6) and (3 > 2);index variable ed ctory f HFileuntil (-4 < -5) or (10 >= 10);t REPEAT loop cannotkfile E  noAtrue or false = truecked for exit at the end of the loop loopers of 16 6Which of the following is NOT a constant of type real? loop?FOR loop?R2.50l true and false; cute at least once?r$;tuO>30000 true or false;d then stop in/end pair 1)0 _<tU1E20l (-2 < 6) and (3 > 2);index variable ed ctory f HFile0.45e23-4 < -5) or (10 >= 10);t REPEAT loop cannotkfile E  noB?Integer constants are the counting numbers from -32767 to 32767s of 16 @What data type will result if you multiply an integer by a real?loop?Rintegerrue and false; cute at least once?r$;tuO>real true or false;d then stop in/end pair 1)0 _<tU1E20l (-2 < 6) and (3 > 2);index variable ed ctory f HFile0.45e23-4 < -5) or (10 >= 10);t REPEAT loop cannotkfile E  noB100 * 0.5 = 50.0s are the counting numbers from -32767 to 32767s of 16 4eal true or false;d then stop in/end pair 1)0 _<tU"Depends on the value of the numberariable ed ctory f HFile.Depends on which Turbo compiler you are using nnotkfile E  noDATURBO.COM uses 6 bytes (BCD & 87 use 8 and 10 bytes respectively)of 16 Write(15.123:0) will output:epresent a real number variable?eal?loop?R0ntegerrue and false; cute at least once?r$;tuO>15al true or false;d then stop in/end pair 1)0 _<tU15.123s on the value of the numberariable ed ctory f HFile1.5E+01 on which Turbo compiler you are using nnotkfile E  noDDDefinition: Write(RealNumber:TotalFieldWidth:NumberOfDecimalPlaces)16 Write(15.123:0:0) will output:resent a real number variable?eal?loop?R0ntegerrue and false; cute at least once?r$;tuO>15 l true or false;d then stop in/end pair 1)0 _<tU15.123s on the value of the numberariable ed ctory f HFile1.5E+01 on which Turbo compiler you are using nnotkfile E  noBDDefinition: Write(RealNumber:TotalFieldWidth:NumberOfDecimalPlaces)16 9Can objects of enumerated scalar types be added together?le?eal?loop?RYesegerrue and false; cute at least once?r$;tuO>No l true or false;d then stop in/end pair 1)0 _<tU15.123s on the value of the numberariable ed ctory f HFile1.5E+01 on which Turbo compiler you are using nnotkfile E  noBGAn enumerated scalar type may be used to represent the days of the week 2Given: type Days = (Mon,Tue,Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?RSucc(Tue) = Wedfalse; cute at least once?r$;tuO>Pred(Tue) = Monalse;d then stop in/end pair 1)0 _<tUSucc(Wed) = Pred(Fri)of the numberariable ed ctory f HFileAll are true expressions mpiler you are using nnotkfile E  noDSucc(Pred(x)) =  xlar type may be used to represent the days of the week 2Given: type Days = (Mon,Tue,Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?R Ord(Mon) = 0 edfalse; cute at least once?r$;tuO> Ord(Mon) = 1Monalse;d then stop in/end pair 1)0 _<tUOrd(Mon) = Moned(Fri)of the numberariable ed ctory f HFile.None of the above are legal Pascal expressionsnnotkfile E  noA3Each scalar's value is represented by a single bytethe days of the week 2Given: type Days = (Mon,Tue,Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?RDays(0) = Mon dfalse; cute at least once?r$;tuO> Days(1) = Mononalse;d then stop in/end pair 1)0 _<tUDays(Mon) = Mond(Fri)of the numberariable ed ctory f HFile.None of the above are legal Pascal expressionsnnotkfile E  noABThe scalar type identifier can also be used as a transfer function week [1, 2, 3] + [4, 5, 6] =n,Tue,Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?R[]ys(0) = Mon dfalse; cute at least once?r$;tuO> [1, 2, 3] Mononalse;d then stop in/end pair 1)0 _<tU [4, 5, 6] = Mond(Fri)of the numberariable ed ctory f HFile[1, 2, 3, 4, 5, 6] re legal Pascal expressionsnnotkfile E  noD+ is the set union operatorcan also be used as a transfer function week [1, 2, 3] * [4, 5, 6] =n,Tue,Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?R[] s(0) = Mon dfalse; cute at least once?r$;tuO> [1, 2, 3] Mononalse;d then stop in/end pair 1)0 _<tU [4, 5, 6] = Mond(Fri)of the numberariable ed ctory f HFile[1, 2, 3, 4, 5, 6] re legal Pascal expressionsnnotkfile E  noA"* is the set intersection operatoro be used as a transfer function week SetVar := ['AA'..'ZZ'];n,Tue,Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?Rcontains 26 elements; cute at least once?r$;tuO>contains more than 26 elementsp in/end pair 1)0 _<tUcontains 0 elementsi)of the numberariable ed ctory f HFile Is not a legal Pascal statement al expressionsnnotkfile E  noD)An element of a set must be a simple typeed as a transfer function week [1..3, 5..8] - [1..2, 6..9] =Wed,Thu,Fri,Sat,Sun);gether?le?eal?loop?R [1..2, 6..9]elements; cute at least once?r$;tuO> [1..3, 5..8]e than 26 elementsp in/end pair 1)0 _<tU[3, 5] s 0 elementsi)of the numberariable ed ctory f HFile[2, 9] a legal Pascal statement al expressionsnnotkfile E  noC1- subtracts the second set from the the first settransfer function week /Which of the following is NOT a valid set type:n);gether?le?eal?loop?R set of char]elements; cute at least once?r$;tuO> set of byte]e than 26 elementsp in/end pair 1)0 _<tU set of real lementsi)of the numberariable ed ctory f HFile7set of days { where days is a user-defined scalar } E  noC)An element of a set must be a simple typeirst settransfer function week #Write(['A'..'C'] = []) will output:id set type:n);gether?le?eal?loop?RABC of char]elements; cute at least once?r$;tuO>Trueof byte]e than 26 elementsp in/end pair 1)0 _<tUFalse real lementsi)of the numberariable ed ctory f HFileIs not a legal Pascal statement a user-defined scalar } E  noC=Write can only output s calar values and strings to the screenction week Write(['A'..'C']) will output:tput:id set type:n);gether?le?eal?loop?RABC of char]elements; cute at least once?r$;tuO>'A'..'C'yte]e than 26 elementsp in/end pair 1)0 _<tU 'A', 'B', 'C'ementsi)of the numberariable ed ctory f HFile Is not a legal Pascal statement a user-defined scalar } E  noD=Write can only output scalar values and strings to the screenction week 4How many bytes are used to represent a set variable?ther?le?eal?loop?R1BC of char]elements; cute at least once?r$;tuO>16'..'C'yte]e than 26 elementsp in/end pair 1)0 _<tU256, 'B', 'C'ementsi)of the numberariable ed ctory f HFile'It depends on the base type of the set defined scalar } E  noD;A single bit is reserved for each possible element of a setenction week SetVar := [0, 100, 200, 300];present a set variable?ther?le?eal?loop?RSetVar contains 100, 200te at least once?r$;tuO> SetVar contains 0, 44, 100, 200 in/end pair 1)0 _<tUSetVar contains 0, 100, 200 numberariable ed ctory f HFile SetVar contains 0, 100, 200, 300he set defined scalar } E  noB;if element > 255 then SetVar := SetVar + [element MOD 256]]enction week (Can a string be used as a case selector?et variable?ther?le?eal?loop?RYesVar contains 100, 200te at least once?r$;tuO>No Var contains 0, 44, 100, 200 in/end pair 1)0 _<tUSetVar contains 0, 100, 200 numberariable ed ctory f HFileSetVar contains 0, 100, 200, 300he set defined scalar } E  noB%A case selector must be a simple typer + [element MOD 256]]enction week StringVar := CharVar as a case selector?et variable?ther?le?eal?loop?Ris a legal assignment 00te at least once?r$;tuO>is NOT a legal assignment0, 200 in/end pair 1)0 _<tUSetVar contains 0, 100, 200 numberariable ed ctory f HFileSetVar contains 0, 100, 200, 300he set defined scalar } E  noAStrings of length 1 are allowede typer + [element MOD 256]]enction week .Given StringVar = 'ABCD': Length(StringVar) =iable?ther?le?eal?loop?R0s a legal assignment 00te at least once?r$;tuO>4 NOT a legal assignment0, 200 in/end pair 1)0 _<tU'ABCD' contains 0, 100, 200 numberariable ed ctory f HFile Is not a legal Pascal expressionhe set defined scalar } E  noB/Definition: function Length(StringVar) : byte;nt MOD 256]]enction week BGiven StringVar = 'ABCD': Delete(StringVar, 1, Length(StringVar));op?RStringVar = '' gnment 00te at least once?r$;tuO>StringVar = 'A'assignment0, 200 in/end pair 1)0 _<tUStringVar = 'ABCD' 100, 200 numberariable ed ctory f HFileIs not a legal Pascal statementnhe set defined scalar } E  noA>Definition: Delete(StringVar, FirstCharToDel, NumCharsToDel);tion weekCopy('ABCDEFGHIJ', 4, 3) =Delete(StringVar, 1, Length(StringVar));op?R'CDEF'Var = '' gnment 00te at least once?r$;tuO>'ABCD'Var = 'A'assignment0, 200 in/end pair 1)0 _<tU'DEF' Var = 'ABCD' 100, 200 numberariable ed ctory f HFileIs not a legal Pascal statementnhe set defined scalar } E  noC4 BCD'Var = 'A'assignment0, 200 in/end pair 1)0 _<tU5DEF' Var = 'ABCD' 100, 200 numberariable ed ctory f HFile6s not a legal Pascal statementnhe set defined scalar } E  noB*Definition: Pos(FindPattern, InThisString)y, NumCharsToCopy));tion weekStr(25, StringVar);') =) =Delete(StringVar, 1, Length(StringVar));op?RStringVar = '25'; ent 00te at least once?r$;tuO>StringVar = '';assignment0, 200 in/end pair 1)0 _<tU7StringVar = ' '; { 25 spaces } HFileIs not a legal Pascal statementnhe set defined scalar } E  noA2Definition: Str(NumericValue, StringVarToModify);arsToCopy));tion weekStr(25:3, StringVar); =) =Delete(StringVar, 1, Length(StringVar));op?RStringVar = '25'; ent 00te at least once?r$;tuO>StringVar = '25.3';gnment0, 200 in/end pair 1)0 _<tU StringVar = ' 25'; { 1 space } '; { 25 spaces } HFileIs not a legal Pascal statementnhe set defined scalar } E  noC=Definition: Str(NumericValue:FieldWidth, StringVarToModify);;tion week"Val('123', IntegerVar, ErrorCode);tringVar, 1, Length(StringVar));op?R IntegerVar = 123, ErrorCode = 0 ast once?r$;tuO> IntegerVar = 123, ErrorCode <> 0in/end pair 1)0 _<tUIntegerVar = 0, ErrorCode = 123 '; { 25 spaces } HFileIs not a legal Pascal statementnhe set defined scalar } E  noA=Definition: Val(StringValue, IntegerVarToModify, ErrorCode);;tion week1Can an array be composed of elements of any type?ngth(StringVar));op?RYes gerVar = 123, ErrorCode = 0 ast once?r$;tuO>NotegerVar = 123, ErrorCode <> 0in/end pair 1)0 _<tUIntegerVar = 0, ErrorCode = 123 '; { 25 spaces } HFileIs not a legal Pascal statementnhe set defined scalar } E  noA"array[1..10] of file" is legalntegerVarToModify, ErrorCode);;tion week&How many dimensions can an array have?f any type?ngth(StringVar));op?R2es gerVar = 123, ErrorCode = 0 ast once?r$;tuO>3otegerVar = 123, ErrorCode <> 0in/end pair 1)0 _<tU4ntegerVar = 0, ErrorCode = 123 '; { 25 spaces } HFileLimited only by memory tatementnhe set defined scalar } E  noD7"array [1..2, 1..2, 1..2, 1..2, 1..2] of byte" is legalCode);;tion weekAGiven: a : array[1..10] of char; The statement: a[0] := 'C';;op?RIs a legal Pascal statement = 0 ast once?r$;tuO>Will cause a compiler error <> 0in/end pair 1)0 _<tUWill cause a run-time error 123 '; { 25 spaces } HFile9Will cause a run-time error only if range-checking is on E  noD;{$R+} turns on range-checking for scalars and array indexes);;tion weekCIf Players is a user-defined type, which type declaration is legal?p?Ra = array[1..Players] of byte;0 ast once?r$;tuO>b = array[Players] of Players; 0in/end pair 1)0 _<tU$c = array[Players, Players] of byte; '; { 25 spaces } HFile"All 3 are legal type declarations f range-checking is on E  noD2A user-defined type may contain up to 2 56 elementsy indexes);;tion weekNo= array[Players] of Players; 0in/end pair 1)0 _<tUc = array[Players, Players] of byte; '; { 25 spaces } HFileAll 3 are legal type declarations f range-checking is on E  noAEAssignments can be made between 2 non-file variables of the same typeek7How many bytes are used to represent an array variable?type? legal?p?R1es array[1..Players] of byte;0 ast once?r$;tuO>2o= array[Players] of Players; 0in/end pair 1)0 _<tU3 = array[Players, Players] of byte; '; { 25 spaces } HFile!Depends on the type of the array f range-checking is on E  noD@a char uses 1 byte; an integer uses 2 bytes; a real uses 6 bytes typeekCWhat scalar type cannot be used as an index in an array definition?p?Rintegeray[1..Players] of byte;0 ast once?r$;tuO>chararray[Players] of Players; 0in/end pair 1)0 _<tUreal rray[Players, Players] of byte; '; { 25 spaces } HFileuser-defined scalar of the array f range-checking is on E  noC$an array index must be a simple type2 bytes; a real uses 6 bytes typeekWrite(ArrayVar); cannot be used as an index in an array definition?p?RIs a legal procedure callbyte;0 ast once?r$;tuO>Is NOT a legal procedure call 0in/end pair 1)0 _<tUreal rray[Players, Players] of byte; '; { 25 spaces } HFileuser-defined scalar of the array f range-checking is on E  noB8Write can output scalar values and strings to the screen 6 bytes typeek)The safest way to initialize an array is:ex in an array definition?p?RWith a FOR loop dure callbyte;0 ast once?r$;tuO>With a FILLCHAR statementcall 0in/end pair 1)0 _<tUreal rray[Players, Players] of byte; '; { 25 spaces } HFileuser-defined scalar of the array f range-checking is on E  noA'FillChar does not perform type checkingngs to the screen 6 bytes typeek$Is a text file a random access file?y is:ex in an array definition?p?RYesh a FOR loop dure callbyte;0 ast once?r$;tuO>No h a FILLCHAR statementcall 0in/end pair 1)0 _<tUreal rray[Players, Players] of byte; '; { 25 spaces } HFileuser-defined scalar of the array f range-checking is on E  noBWhich of the following CANNOT be used on a random access file?tion?p?RSeek a FOR loop dure callbyte;0 ast once?r$;tuO> BlockWrite CHAR statementcall 0in/end pair 1)0 _<tUWriterray[Players, Players] of byte; '; { 25 spaces } HFileRead-defined scalar of the array f range-checking is on E  noB#BlockWrite is used on untyped files all have the same lengthytes typeek>The fastest way to move to the end of a random access file is:tion?p?RAppend(FileVar);dure callbyte;0 ast once?r$;tuO>"Seek(FileVar, FileSize(FileVar)); /end pair 1)0 _<tU3while not EOF(FileVar) do Read(FileVar, RecordVar);es } HFile>while not EOF(FileVar) do Seek(FileVar, FilePos(FileVar) + 1); noBDFileSize returns the number of records, FilePos  the current record #eek7The fastest way to remove the last record of a file is:ile is:tion?p?R'Delete(FileVar, FileSize(FileVar) - 1);e?r$;tuO>6Seek(FileVar, FileSize(FileVar) - 1); Delete(FileVar);_<tU9Seek(FileVar, FileSize(FileVar) - 1); Truncate(FileVar);  HFile3There is no way to remove the last record of a fileeVar) + 1); noCADelete(StringVar, 1, 1) removes the first character from a stringd #eek8The fastest way to remove the first record of a file is:le is:tion?p?RDelete(FileVar, 1);eSize(FileVar) - 1);e?r$;tuO>7Copy the first record to a new file, erase the new file_<tU9Copy the other records to a new file, erase the old file  HFile4There is no way to remove the first record of a fileVar) + 1); noCADelete(StringVar, 1, 1) removes the first character from a stringd #eek6What is the main difference between Write and Writeln?s:le is:tion?p?R Write can only take one argument) - 1);e?r$;tuO>1Writeln also outputs a carriage return/line feed w file_<tU1Writeln waits for the user to hit carriage returnld file  HFileThere is no way to remove the first record of a fileVar) + 1); noB7Write does not move the output pointer to the next linem a stringd #eekDWhich data type CANNOT be output to the screen in a Write statement??Rreale can only take one argument) - 1);e?r$;tuO>stringn also outputs a carriage return/line feed w file_<tUchareln waits for the user to hit carriage returnld file  HFileset e is no way to remove the first record of a fileVar) + 1); noD7Only scalar or string types can be output to the screenm a stringd #eek5The fastest way to move to the end of a text file is:rite statement??RAppend(FileVar); ke one argument) - 1);e?r$;tuO>!Seek(FileVar, FileSize(FileVar));eturn/line feed w file_<tU3while not EOF(FileVar) do Read(FileVar, StringVar); file  HFile>while not EOF(FileVar) do Seek(FileVar, FilePos(FileVar) + 1); noADFileSize returns the number of records; FilePos the current record #eek;The fastest way to remove the first line of a text file is:tatement??RDelete(FileVar, 1); one argument) - 1);e?r$;tuO>5Copy the first line to a new file, erase the new filele_<tU7Copy the other lines to a new file, erase the old file e  HFile7There is no way to remove the first line of a text file) + 1); noCADelete(StringVar, 1, 1) removes the first character from a stringd #eek0Which of the following is true about text files?xt file is:tatement??R9After you Assign the file name you can read from the fileuO>;If you open a text file with a Rewrite you can read from ittU/Readln and Writeln can be used with text files ld file e  HFileText files are files of recordsirst line of a text file) + 1); noCAa text file cannot be open for reading and writing simultaneouslyd #eek9Which procedure/function CANNOT be used with a text file?s:tatement??REOFer you Assign the file name you can read from the fileuO>EOLNou open a text file with a Rewrite you can read from ittUSeek n and Writeln can be used with text files ld file e  HFileResetfiles are files of recordsirst line of a text file) + 1); noCHSeek moves the file pointer to a specific record in a r andom access file8while not EOF(FileVar) do Read(FileVar, StringVar) WILL:?s:tatement??RRead every line in a text file you can read from the fileuO>#Read the first line of a text file ite you can read from ittUCause a compiler error be used with text files ld file e  HFileCause a run-time errorf recordsirst line of a text file) + 1); noBHRead(StringVar) reads until the next character is a carriage return (CR):while not EOF(FileVar) do Readln(FileVar, StringVar) WILL::tatement??RRead every line in a text file you can read from the fileuO>"Read the first line of a text file ite you can read from ittUCause a compiler error be used with text files ld file e  HFileCause a run-time errorf recordsirst line of a text file) + 1); noAFReadln reads until the next character is a CR, then it skips past EOLNR)>Which data type is used for dynamically allocating a variable?ement??Rintegerery line in a text file you can read from the fileuO> 2 integers declared side-by-sidele ite you can read from ittU pointers ompiler error be used with text files ld file e  HFilean array of pointersorf recordsirst line of a text file) + 1); noC+New and GetMem both return a memory addressCR, then it skips past EOLNR)*What data type can a pointer NOT point to?locating a variable?ement??Rsetegerery line in a text file you can read from the fileuO> user-definedeclared side-by-sidele ite you can read from ittUrecordrs ompiler error be used with text files ld file e  HFileit can point to any data type sirst line of a text file) + 1); noD>Every variable is allocated space at a specific memory addressast EOLNR)$A NIL pointer can be used to access:nt to?locating a variable?ement??RRAM (Random-access memory)file you can read from the fileuO>ROM (Read only memory)de-by-sidele ite you can read from ittURUM (Rarely utilized memory)ed with text files ld file e  HFileNothing oint to any data type sirst line of a text file) + 1); noD1sorry--we're not giving you any hints on this oneemory addressast EOLNR)5Pointer variables are initialized to NIL at run-time:variable?ement??RTrue(Random-access memory)file you can read from the fileuO>False ead only memory)de-by-sidele ite you can read from ittURUM (Rarely utilized memory)ed with text files ld file e  HFileNothing oint to any data type sirst line of a text file) + 1); noB5Turbo Pascal never initializes variables. N-E-V-E-R!y addressast EOLNR) New(P) will:ables are initialized to NIL at run-time:variable?ement??RAllocate 8 bytesss memory)file you can read from the fileuO>Allocate SizeOf(P^) bytesby-sidele ite you can read from ittUAllocate 1 bytelized memory)ed with text files ld file e  HFile;Allocate 8 bytes or SizeOf(P^) bytes--whichever is greater 1); noD>The minimum amount allocated on the heap is one-half paragraphast EOLNR)={$R+} will cause a run-time error on an out-of-bounds pointer?ement??RTruecate 8 bytesss memory)file you can read from the fileuO>False te SizeOf(P^) bytesby-sidele ite you can read from ittUAllocate 1 bytelized memory)ed with text files ld file e  HFileAllocate 8 bytes or SizeOf(P^) bytes--whichever is greater 1); noB;{$R+} turns on range-checking for scalars and array indexesapha st EOLNR)8What is the data type returned by the function MemAvail?inter?ement??Rpointere 8 bytesss memory)file you can read from the fileuO>reale te SizeOf(P^) bytesby-sidele ite you can read from ittUinteger 1 bytelized memory)ed with text files ld file e  HFilebytecate 8 bytes or SizeOf(P^) bytes--whichever is greater 1); noCEMemAvail returns the total number of paragraphs available on the heapNR)CWhich can be used to check for room on the heap before calling New???R MaxAvail 8 bytesss memory)file you can read from the fileuO>MemAvail SizeOf(P^) bytesby-sidele ite you can read from ittU HeapAvail1 bytelized memory)ed with text files ld file e  HFileSizeOfte 8 bytes or SizeOf(P^) bytes--whichever is greater 1); noACMaxAvail gives the # of contiguous paragraphs available on the heapapNR)Mem[Seg(P^):Ofs(P^)] = P^k for room on the heap before calling New???RIs true if SizeOf(P^) = 1 file you can read from the fileuO>Is true if SizeOf(P^) > 1by-sidele ite you can read from ittU Is never truetelized memory)ed with text files ld file e  HFileIs always truees or SizeOf(P^) bytes--whichever is greater 1); noAAMem is the pre-defined memory array of byte: Mem[Segment:Offset]apapNR),Two different ways of managing the heap are:eap before calling New???RNew/Release, New/Mark/Disposee you can read from the fileuO>New/Dispose, New/Mark/Release dele ite you can read from ittUNew/Old, New/Mark/Freeemory)ed with text files ld file e  HFileNew/Dispose, New/Mark/Free(P^) bytes--whichever is greater 1); noB@Dispose(P) frees P's memory; Release(P) frees all heap from P on]apapNR)CHow many times can a procedure or function call itself recursively???RLimited only by stack space ee you can read from the fileuO>256/Dispose, New/Mark/Release dele ite you can read from ittU640KOld, New/Mark/Freeemory)ed with text files ld file e  HFile*A procedure or function cannot call itselfhever is greater 1); noACDuring a call, local parameters & variables are pushed on the stackapNR)"A recursive procedure or function:function call itself recursively???RMust be forward declaredace ee you can read from the fileuO>4Must have an exit branch or your program will crash from ittUCannot declare local variables with text files ld file e  HFile%Must be smaller than 16K or 100 linestselfhever is greater 1); noB6No special checking is performed on recursive routines on the stackapNR)@INVOKING procedure Test; begin Test; end; WILL EVENTUALLY CAUSE:ly???RA compiler errordeclaredace ee you can read from the fileuO> An I/O error exit branch or your program will crash from ittUA heap/stack collision error s with text files ld file e  HFile"Test to execute once and then exitnestselfhever is greater 1); noC;Repetitive, uncontrolled recursion will cause a fatal errorhe stackapNR)  Welcome to Turbo Tutor Version 2.0 ---------------------------------- To use this tutorial, use the control keys to highlight the name of the sample program that you wish to examine or run. Then press RETURN and the  source code of the sample program will appear in the lower window. You may then use the control keys to scroll through the code, press R to run the sample program, or press Control-Q to take a quiz on the topic you selected. { This example performs simple arithmetic operations on two integers. Integers are the counting numbers--positive and negative--including zero. Turbo Pascal integers range from -32768 to 32767. This procedure gets two integer values from the user, X and Y, and performs the following operations on them: Expression Description ---------- ----------- X + Y Addition X - Y Subtraction X DIV Y Integer division (ignore remainder) X MOD Y Modulo (remainder from integer division) This program restricts the numbers entered to two digits to prevent underflow and overflow. If an integer operation attempts to produce a result greater than 32767 or less than -32768, Turbo will not report an error (though the result will not be valid). Turbo does, however, catch division by zero. } procedure Integers; (**)  type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const Minimum = -9; { Minimum number that can be entered } Maximum = 99; { Maximum number that can be entered } var NumX, { the X value input by user } NumY : integer; { the Y value input by user } procedure GetNumbers(var X, Y : integer); { reads in the two integers for calculations } begin PrintXY('Enter 2 integers:', VNorm, 1, FirstRow); PrintXY('X := ', VLow, 1, FirstRow + 2); { Prompt the user } X := GetInteger(WhereX, WhereY, 2, Minimum, Maximum); if Interrupted then Exit; Print('; Y := ', VLow); { Prompt the user } Y := GetInteger(WhereX, WhereY, 2, Minimum, Maximum); if Interrupted then Exit; Print(';', VLow); end; { GetNumbers } procedure ShowCalculations; { Shows how to write out the results of the integer operations : +, -, *, DIV and MOD } procedure Calculate(X, Y : integer; Operator : char); { Given two integers and an operator, displays the "equation" } var Result: integer; begin PrintXY(IntToString(X, 1) + ' ', VLow, 3, Succ(WhereY)); ChangeVideo(VNorm); case Operator of { display operation, do the math } '+': begin Show(' + '); Result := X + Y; end; '-': begin Show(' - '); Result := X - Y; end; '*': begin Show(' * '); Result := X * Y; end; 'D': if Y <> 0 then begin Show('DIV'); Result := X div Y; end else  Show('Cannot DIV by zero!'); 'M': if Y <> 0 then begin Show('MOD'); Resul  t := X mod Y; end else Show('Cannot MOD by zero!'); end; { case } Print(' ' + IntToString(Y, 1) + ' = ', VLow); Print(IntToString(Result, 5), VNorm); { finish displaying "equation" } end; { Calculate of ShowCalculations } begin { ShowCalculations } Showln(''); Calculate(NumX, NumY, '+'); Calculate(NumX, NumY, '-'); Calculate(NumX, NumY, '*'); Calculate(NumX, NumY, 'D'); Calculate(NumX, NumY, 'M'); end; { ShowCalculations } begin { Integers } GetNumbers(NumX, NumY); { Read in the numbers } if not Interrupted then ShowCalculations; { perform integer operators and display results } end; { Integers } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Integers; { execute the procedure } end. { end of the program }  Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal  Tutor. **)  { This example performs simple operations on characters. Characters are used to represent ASCII codes. Turbo Pascal characters range from ASCII code 0 to ASCII code 255. This procedure gets a character from the user, and echoes it on the top line of the output display. The character is then processed as follows: 1. If the character is a lowercase letter, it is converted to uppercase. 2. If the character is an uppercase letter, it is converted to lowercase.  3. If the character is not a letter of the alphabet, the original character is displayed. Once processed, the character is displayed on the next line. } procedure Chars; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) var Ch : char; { the character to be swapped } procedure PrintBackSpace; { Implements a backspace on the TWO output lines } begin if WhereX > 1 then begin Print(BS + ' ', VLow); { erase previous character } Print(BS + LF + ' ', VLow); { erase prev. char on line below } GotoWinXY(Pred(WhereX), Pred(WhereY)); end; end; { PrintBackSpace } function LowerCase(Ch : char) : char; { Converts a character to lower case. Ord returns the ascii value of the character argument. The conversion algorithm is based on the idea that the distance between 'M' ! and 'A' is the same as the distance from 'm' and 'a'. So just find the difference between the ord of 'A' and 'a' and add this to ord of the character argument. Chr then converts the ascii number back to a(lower case) character. } begin if Ch in ['A'..'Z'] then { upper case letter? } LowerCase := Chr(Ord(Ch) + Ord('a') - Ord('A')) else LowerCase := Ch; end; { LowerCase } function SwapCase(Ch : char) : char; { Given an uppercase letter, it converts it to lowercase. Given a lowercase letter, it converts it to uppercase. } begin if Ch in ['A'..'Z'] then { upper case letter? } SwapCase := LowerCase(Ch) { yes: make lower case } else SwapCase := UpCase(Ch) { UpCase is a built-in Turbo function } end; { SwapCase } procedure ShowOn2Lines(Ch : char); { Print the character on line one and print the swapped character on line 2. WhereX returns the current column position of the cursor. WhereY returns the current row position of the cursor. } begin  Print(Ch + LF + BS, VLow); { character, then down one row, same col } Print(SwapCase(Ch), VNorm); { Swap the case of the letter and print it } GotoWinXY(WhereX, Pred(WhereY)); { back up to original row } end; { ShowOn2Lines } function PrintableChar(Ch : char) : boolean; { returns true if the character is printable, i.e., not a control character } begin PrintableChar := Ch in [' '..'~']; end; { PrintableChar } procedure PromptUser; { Tell the user to input a line of text to be swapped }  begin PrintXY('ESC', VNorm, 1, 6); Print(' - Quit', VLow); PrintXY('OPPOSITES -- type some characters:', VNorm, 1, 1); GotoWinXY(1, 3); end; { PromptUser } begin { Chars } PromptUser; repeat Ch := GetKey; { read the character } if (Ch = BS) then PrintBackSpace else if PrintableChar(Ch) and (WhereX < 80) then ShowOn2Lines(Ch) { Echo character on two lines and swap case } until Interrupted; { The user typed ESC } end; { Chars } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Chars; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This procedure demonstrates the use of the boolean operators AND, OR, XOR, and NOT on numbers (as opposed to boolean variables). AND will return a bit on if the bit of both operands is on. 00001100 12 00001010 10 00001000 12 AND 10 = " 8 OR will return a bit on if the bit of either operand is on. 00001100 12 00001010 10 00001110 12 OR 10 = 14  XOR will return a bit on if the bit of one operand is on and the other is off. 00001100 12 00001010 10 00000110 12 XOR 10 = 6 NOT will reverse the bits of an operand. 0101010101010101 21845 1010101010101010 NOT 21845 = -21846 } procedure Binary; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) procedure PrintNumber(Header : AnyString; Number, Row : integer); { Prints a number in binary form on a particular row } var Counter : byte; Place : integer; begin PrintXY(Pad(Header, 18), VNorm, 1, Row); Place := 1 shl 15; { Set highest bit of Place } for Counter := 1 to 16 do begin if (Number and Place) <> 0 then Print('1 ', VLow) else Print('0 ', VLow); Place := Place shr 1; { Move Place to next bit } end; Print(IntToString(Number, 6), VNorm); end; { PrintNumber } procedure RunBinary(var Number1, Number2 : integer); { The main procedure - it takes the two numbers as input and manipulates them, showing the results on the screen. } var NumStr1, NumStr2 : string[6]; Ch : char; begin NumStr1 := IntToString(Number1, 1); NumStr2 := IntToString(Number2, 1); PrintNumber(NumStr1, Number1, FirstRow); PrintNumber(NumStr2, Number2, Succ(FirstRow)); PrintNumber(NumStr1 + ' AND ' + NumStr2, Number1 AND Number2, FirstRow + 3); PrintNumber(NumStr1 + ' OR ' + NumStr2, Number1 OR Number2, FirstRow + 4); PrintNumber(NumStr1 + ' XOR ' + NumStr2, Number1 XOR Number2, FirstRow + 5); PrintNumber('NOT ' + NumStr1, not Number1, FirstRow + 6); PrintNumber('NOT ' + NumStr2, not Number2, FirstRow + 7); PrintXY(' ', VNorm, 70, Succ(FirstRow)); { Erase old second number } PrintXY('Number 1: ', VNorm, 60, FirstRow); Number1 := GetInteger(WhereX, WhereY, 6, $8000, 32767); if Interrupted then Exit; PrintXY('Number 2: ', VNorm, 60, Succ(FirstRow)); Number2 := GetInteger(WhereX, WhereY, 6, $8000, 32767); if Interrupted then Exit; end; { RunBinary } var Num1, Num2 : integer; begin { Binary } Num1 := 1; Num2 := 0; repeat RunBinary(Num1, Num2); until Interrupted; Message(''); end; { Binary } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Binary; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) # { This procedure compares numbers in three different notations that are commonly used on computers - decimal (base 10), hexadecimal (base 16), and binary (base 2). Decimal notation is the way we "normally" represent numbers. Each digit is a power of 10 and legal digits range from 0 to 9. Hexadecimal notation, or hex, is often used in the computer world because  it is relatively easy to convert numbers from binary (the way computers represent numbers) to hexadecimal and back again. Each hex digit is a power of 16 and legal digits range from 0 to 9, and from A to F. Binary notation is the way the computers represent numbers. Each digit is a power of 2 and legal digits range from 0 to 1. Here is how to count from zero to sixteen in decimal, hexadecimal and binary notation: Decimal Hex Binary 0 0  0 1 1 1 2 2 10 3 3 11 4  4 100 5 5 101 6 6 110 7 7 111  8 8 1000 9 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15  F 1111 16 10 10000 Too bad we don't have 16 fingers--we could type a lot faster and it would make it much easier to talk about the way that computers represent and manipulate data! This procedure gets a value from the user in any of the three notations, and then immediately shows the number in the other notations. The routines first convert a string in the input notation to a base 10 number, and then convert the number back into a string that displays the number in the correct notation. } procedure Hex; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) type BaseList = (Decimal, Hexadecimal, Binary, NoBase); BaseRecord = record BaseValue : byte; BaseInputLength : byte; BaseLegalSet : CharSet; end; const DigitString : string[16] = '0123456789ABCDEF'; { Digits used by the conversion routines } PrintCol = 20; { Column that the numbers start to display in } BaseData : array[BaseList] of BaseRecord =  ((BaseValue : 10; BaseInputLength : 12;  BaseLegalSet : ['0'..'9']), (BaseValue : 16; BaseInputLength : 10; BaseLegalSet : ['0'..'9', 'A'..'F']), (BaseValue : 2; BaseInputLength : 40; BaseLegalSet : ['0'..'1']),  (BaseValue : 0; BaseInputLength : 0; $  BaseLegalSet : [])); function ConvertToBaseTen(OldNumber : AnyString; Base : byte) : real; { Converts a number string to a base 10 number } var Number, Counter : integer; Multiplier, Result : real; begin Multiplier := 1; { Last digit of number is always worth 1 } Result := 0.0; for Counter := Length(OldNumber) downto 1 do { Check each digit from last to first } begin Number := Pred(Pos(OldNumber[Counter], DigitString)); { Add value of } Result := Result + (Multiplier * Number); { digit to result } Multiplier := Multiplier * Base; { Increase base value of next digit } end; ConvertToBaseTen := Result; end; { ConvertToBaseTen } function ConvertFromBaseTen(Number : real; Base : byte) : AnyString; { Converts a base 10 number to a number string } var Multiplier : real; Result : integer; S : AnyString; begin Multiplier := 1; { Last digit of number is always worth 1 } while (Multiplier * Base) <= Number do Multiplier := Multiplier * Base; { Find largest digit place in number } S := ''; repeat { Find each digit } Result := Trunc(Number / Multiplier); S := S + DigitString[Succ(Result)]; { Convert a value to a digit } Number := Number - (Multiplier * Result); { Subtract digit from number } Multiplier := Multiplier / Base; { Decrease base value of next digit } until Multiplier < 1; { Stop when all digits have been found } ConvertFromBaseTen := S; end; { ConvertFromBaseTen } procedure PrintAllValues(PrintNumber : real; CurrentBase : BaseList); { Prints the current number in all bases on the screen } var Counter : BaseList; begin for Counter := Decimal to Binary do begin if Counter <> CurrentBase then { Don't print current base } begin  PrintXY(ConvertFromBaseTen(PrintNumber, BaseData[Counter].BaseValue), VLow, PrintCol, FirstRow + 2 + Ord(Counter)); ClrEol; { Erase old output } end; end; end; { PrintAllValues } procedure GetNewNumber(var NewNumber : real; var Base : BaseList); { Allows the user to enter a number, and displays it in the different bases } var Ch : char; KeyWasInput, Stop : boolean; Legal : CharSet; CurrString : AnyString; CurrLength : byte absolute CurrString; { length byte of CurrString } MaxLength : byte; procedure ProcessChar(Ch : char); { Processes a single input character } begin case Ch of '0'..'9', 'A'..'F' : if CurrLength < MaxLength then begin  if not KeyWasInput then { Clear input field when first key is pressed } begin  ClearXY(PrintCol, FirstRow + 2 + Ord(Base)); KeyWasInput := true;  end; Print(Ch, VLow); { Print new character } CurrString := CurrString + Ch; NewNumber := ConvertToBaseTen(CurrString, BaseData[Base].BaseValue); PrintAllValues(NewNumber, Base); GotoWinXY(PrintCol + CurrLength, FirstRow + 2 + Ord(Base)); { Move back to input field } %  end; BS : if CurrLength > 0 then begin Delete(CurrString, CurrLength, 1); Print(BS + ' ' + BS, VLow); NewNumber := ConvertToBaseTen(CurrString, BaseData[Base].BaseValue); PrintAllValues(NewNumber, Base); GotoWinXY(PrintCol + CurrLength, FirstRow + 2 + Ord(Base)); { Move back to input field } end; UpKey : begin if (CurrLength = 0) and KeyWasInput then Print('0', VLow); { Print 0 if field is blank } if Base = Decimal then Base := Binary else  Base := Pred(Base); Stop := true; end; CR, DownKey : begin if (CurrLength = 0) and KeyWasInput then Print('0', VLow); { Print 0 if field is blank } if Base = Binary then Base := Decimal else Base := Succ(Base); Stop := true; end; end; { case } end; { ProcessChar } begin { GetNewNumber }  Stop := false; KeyWasInput := false; CurrString := ''; Legal := BaseData[Base].BaseLegalSet + [BS, CR, Upkey, DownKey]; MaxLength := BaseData[Base].BaseInputLength; GotoWinXY(PrintCol, FirstRow + 2 + Ord(Base)); repeat Ch := GetLegalKey(Legal); ProcessChar(Ch); until Stop or Interrupted; end; { GetNewNumber } var Number : real; CurrBase : BaseList; begin { Hex } PrintXY('Number', VNorm, PrintCol, FirstRow); { Print prompts } PrintXY('------', VNorm, PrintCol, Succ(FirstRow)); PrintXY('Decimal (0..9)', VNorm, 1, FirstRow + 2); PrintXY('Hexadecimal (0..F)', VNorm, 1, FirstRow + 3); PrintXY('Binary (0..1)', VNorm, 1, FirstRow + 4); PrintXY('^E', VNorm, 1, FirstRow + 9); Print('-move up a line', VLow); Print(' ^X', VNorm); Print('/', VLow); Print('Return', VNorm); Print('-move down a line', VLow);  Print(' ESC', VNorm); Print('-exit', VLow); Number := 0; CurrBase := Decimal; PrintAllValues(Number, NoBase);  repeat GetNewNumber(Number, CurrBase); until Interrupted; end; { Hex } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Hex; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program:  {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This procedure uses IF and CASE statements and simulates their decision-making processes on the screen. In each case a character is read in and you are shown both the condition being tested and the evaluation of that condition. Step through an& d evaluate each expression in order to understand how these control statements work. The displays produced by this program illustrate the use of the IF and CASE statements. Most of the source code is devoted to creating these displays (rather than providing examples of IF and CASE statements); so for this reason, we recommend that you run this example and watch it in action rather than (or prior to) examining the source code. } procedure IfCase; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const StartCol = 1; { Left edge column for display } MaxFields = 2; { Maximum fields per statement that can be highlighted } MaxStatements = 5; { Maximum number of statements } type Statement = record { Record that holds statement information } Row : byte; { Row that statement appears on } Col : array[1..MaxFields] of byte; { Column that each field appears on } Data : AnyString; { Data of each statement } end; HighlightType = (Underline, Arrow, None); var Ch : char; { character variable that will be tested } StatementList : array[1..MaxStatements] of Statement; { an array that holds information about fields to be highlighted } CurrStatements : integer; { The number of statements in StatementList } ColCounter, Counter : byte; { Misc. counters }  Mode: (IfMode, CaseMode); { Program is testing either if/then or case } procedure HighLight(Col, Row : byte;  Msg : AnyString; Highlighting : HighlightType); { Highlight a particular string on the screen, wait for input, and then change the string back to normal video } var Ch : char; DisplayStr : AnyString; begin PrintXY(Msg, VNorm, Col, Row); if Highlighting = Underline then begin DisplayStr[0] := Chr(Length(Msg)); FillChar(DisplayStr[1], Length(Msg), '-'); PrintXY(DisplayStr, VNorm, Col, Succ(Row)); end else if Highlighting = Arrow then PrintXY('>', VNorm, Col - 2, Row); Ch := GetKey; PrintXY(Msg, VLow, Col, Row); if Highlighting = Underline then PrintXY(Pad('', Length(Msg)), VNorm, Col, Succ(Row)) else if Highlighting = Arrow then PrintXY(' ', VNorm, Col - 2, Row); end; { HighLight } procedure DisplayTable; { Draw the statements before stepping through them } begin for Counter := 1 to CurrStatements do with StatementList[Counter] do PrintXY(Data, VLow, StartCol, Row); Message('Press any key to step through the program...'); end; { DisplayTable } procedure GetInput(var Ch : char); { Prompts the user and reads in the character(echoing it) } begin PrintXY('Enter character: ', VNorm, 1, FirstRow); repeat Ch := GetKey; { Allow only printable chars or ESC } until (Ch in [ESC, ' '..'~']); PrintXY('Enter character: ', VLow, 1, FirstRow); { Rewrite prompt in VLow } if Ch <> ESC then Print(Ch, VNorm); end; { GetInput } procedure SetupTable; { Put Ch into the statements } var Fillpos : byte; begin for Counter := 1 to CurrStatements do with StatementList[Counter] do begin Co' l[1] := 0; Col[2] := 0; ColCounter := 1; if Mode = IfMode then { Put if/then statements } Row := Succ(FirstRow + ((Pred(Counter)) * 2)) { 2 lines apart } else { Put case statements } Row := FirstRow + Counter; { 1 line apart } FillPos := Pos(NULL, Data); while FillPos <> 0 do begin Col[ColCounter] := FillPos; Data[Col[ColCounter]] := Ch; FillPos := Pos(NULL, Data); ColCounter := Succ(ColCounter); end; end; { with } end; { SetupTable } function Evaluate(Snum, Col, Row : byte) : boolean; { Evaluate the current statement } var Eval : boolean; Msg : AnyString; procedure EvaluateIfMode; { Checks to see which "if" statement the character fits } begin case Snum of 1: Eval := (Ch >= 'A') and (Ch <= 'Z'); 2: Eval := (Ch >= 'a') and (Ch <= 'z'); 3: Eval := (Ch >= '0') and (Ch <= '9'); 4: Eval := True; end { case } end; { EvaluateIfMode } procedure EvaluateCaseMode; { Checks to see which case the character fits } begin case Snum of 1: Eval := (Ch in ['A'..'Z']); 2: Eval := (Ch in ['a'..'z']); 3: Eval := (Ch in ['0'..'9']); 4: Eval := True; end; { case } end; { EvaluateCaseMode } begin { Evaluate } if (Mode = IfMode) then EvaluateIfMode else EvaluateCaseMode; case Snum of 1: Msg := '''' + Ch + ''' is upper case.'; 2: Msg := '''' + Ch + ''' is lower case.'; 3: Msg := '''' + Ch + ''' is numeric.';  4: Msg := '''' + Ch + ''' is not numeric or alphabetic.'; end; { case } HighLight(Col, Row, BoolToString(Eval), None);  if Eval then Print(' ' + Msg, VNorm); Evaluate := Eval; end; { Evaluate } procedure RunIfThen; { Tests the if/then statements } procedure SetupIfTable; { Define statements for if/then test } begin CurrStatements := 4; StatementList[1].Data := 'if (''' + NULL + ''' >= ''A'') and (''' + NULL + ''' <= ''Z'') then'; StatementList[2].Data := 'else if (''' + NULL + ''' >= ''a'') and (''' + NULL + ''' <= ''z'') then'; StatementList[3].Data := 'else if (''' + NULL + ''' >= ''0'') and (''' + NULL + ''' <= ''9'') then'; StatementList[4].Data := 'else'; SetupTable; end; { SetupIfTable }  procedure WriteIfEvaluation; { Step through the if/then test } var S: string[12]; begin for Counter := 1 to CurrStatements do with StatementList[Counter] do begin ColCounter := 1; while (ColCounter <= MaxFields) and (Col[ColCounter] <> 0) do begin S := Copy(Data, Col[ColCounter] - 2, 12); HighLight(StartCol + Col[ColCounter] - 3, Row, S, Underline); if Interrupted then Exit; ColCounter := Succ(ColCounter); end;  if (Evaluate(Counter, StartCol + 2, Succ(StatementList[Counter].Row))) or (Interrupted) then Exit; end; end; { WriteIfEvaluation } begin { RunIfThen } Mode := IfMode; Message('Testing if/then statement...');  GetInput(Ch); if Interrupted then Exit; SetupIfTable; DisplayTable; WriteIfEvaluation; end; { RunIfThen }  procedure RunCase; { Tests the case statement } procedure SetupCaseTable; { Define statements for case test } begin Cu( rrStatements := 5; StatementList[1].Data := 'case ''' + NULL + ''' of'; StatementList[2].Data := ' ''A''..''Z'':'; StatementList[3].Data := ' ''a''..''z'':'; StatementList[4].Data := ' ''0''..''9'':'; StatementList[5].Data := ' else';  SetupTable; end; { SetupCaseTable } procedure WriteCaseEvaluation; { Step through the case test } var S : string[8]; begin with StatementList[1] do begin S := Copy(Data, 6, 3); HighLight(StartCol + Col[1] - 2, Row, s, None); if Interrupted then Exit; end; for Counter := 2 to CurrStatements do with StatementList[Counter] do begin  S := Copy(Data, 3, 8); HighLight(StartCol + 2, Row, S, Arrow); if Interrupted then Exit; if (Evaluate(Pred(Counter), StartCol + 12, StatementList[Counter].Row)) or (Interrupted) then Exit;  end; end; { WriteCaseEvaluation } begin { RunCase } Mode := CaseMode; Message('Testing case statement...'); GetInput(Ch); if Interrupted then Exit; SetupCaseTable; DisplayTable; PrintXY('end; { case }', VLow, 1, FirstRow + 6); WriteCaseEvaluation; end; { RunCase } procedure Wait; { Pauses until the user hits a key } var Ch : char; begin  Message('Press any key to continue...'); { Tell user we are waiting } Ch := GetKey; ChangeVideo(VLow); ClearScreen; end; { Wait } begin { IfCase} RunIfThen; { Run the IF...THEN example } if Interrupted then Exit; Wait; { Let user examine results } if Interrupted then Exit; RunCase; { Run the CASE example } Message(''); end; { IfCase } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } IfCase; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This procedure uses a FOR loop and simulates loop decision making on the screen. Run the example and the following FOR loop will display: for I := A to B do; You are asked to input values for the variables A and B. Then a truth table is constructed that contains an expression from each statement in the example. The procedure highlights the expression being evaluated, shows its value, and waits for you to press a key. Step through and evaluate each expression in order to understand how this important control statement works. The displays produced by this program illustrate the use of  the FOR statement. Most of the source code is devoted to creating these displays (rather than providing examples of FOR  statements); so for this reason, we recommend that you run this example and watch it in action rather than (or prior to)  examining the source code. } procedure ForDo; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This s) tatement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const MaxEvents = 2; { 2 unique events to highlight } MaxStmts = 1; { 1 statement to display } MaxValues = 2; { 2 variables to enter } TableX = 40; { x coordinate of truth table } TableY  = 1; { y coordinate of truth table } EventWidth = 10; { max width of table entry } type StmtRay = array[1..MaxStmts] of AnyString; EventRay = array[1..MaxEvents] of AnyString; ValueRay = array[1..MaxValues] of integer; String2 = string[2]; var Stmt : StmtRay; { actual statement text } Event : EventRay; { text to highlight } Value : ValueRay; { values input by user } procedure LoadArrays; { Load the display data into the 3 global arrays; display loop on screen and input variable values. Variables are marked inside of each statement with a pound sign(#) followed by a single digit. } var I : integer; procedure InputValues(var Stmt : AnyString); { Given a statement, find each "variable" and get the value from the user. } var P, Index : integer; S : String2; function GetValue(var I : integer) : String2; { Get a 2-digit integer from the user } begin I := GetInteger(P, WhereY, 2, -MaxInt, MaxInt); GetValue := IntToString(I, 2); end; { GetValue }  begin { InputValues } P := Pos('#', Stmt); { look for a variable } while P > 0 do { more variables? } begin Index := Ord(Stmt[Succ(P)]) - Ord('0'); { get variable's index } S := GetValue(Value[Index]); { get value } if Interrupted then Exit; Move(S[1], Stmt[P], 2); { update string for display } P := Pos('#', Stmt); { look for a variable... } end; { while } Showln(''); Showln(''); end; { InputValues } procedure ShowStmt(Stmt : AnyString); { Display the loop statement on the screen, replace variable markers (a '#' followed by a digit) with 2 spaces in reverse video. } var I : byte; begin I := 0; while I < Length(Stmt) do begin I := Succ(I); if Stmt[I] = '#' then { replace variables with spaces } begin Print(' ', VNorm); I := Succ(I); end else Print(Stmt[I], VLow); end; { while } Showln(''); Showln(''); end; { ShowStmt } begin { LoadArrays } GotoWinXY(1, FirstRow); Stmt[1] := 'for I := #1 to #2 do;'; { Set up array of statements } for I := 1 to MaxStmts do { display statements } ShowStmt(Stmt[I]); Message('Enter an integer value for each variable '); GotoWinXY(1, FirstRow); { input values } InputValues(Stmt[I]); { Set up array of "events" } if Interrupted then Exit; Event[1] := Copy(Stmt[1], 5, 1); Event[2] := '(I <= ' + Copy(Stmt[1], 16, 2) + ')'; PrintXY('-------------------------------', VLow, TableX - 2, Succ(TableY)); { Display truth table } for I := 1 to MaxEvents do PrintXY(Event[I], VLow, TableX + Pred(I) * EventWidth, TableY); end; { LoadArrays } procedure DisplayEvent(Event, Stmt, Value : AnyString; EventCnt, Row : byte); { Used to simulate loop decision making: show which expression is being evaluated(called an "event"), show the value of the event in the truth table, then wait for*  a keystroke. Clean up highlighting when done. } const Width = 1; var P : byte; Ch : char; DisplayStr : AnyString; begin P := Pos(Event, Stmt); if P > 0 then begin PrintXY(Event, VNorm, P, Row); { Show "event" in normal video } DisplayStr[0] := Chr(Length(Event)); FillChar(DisplayStr[1], Length(Event), '-'); PrintXY(DisplayStr, VNorm, P, Succ(Row)); end; { Show "truth table" value in normal video } PrintXY(Pad(Value, Width), VNorm, TableX + Pred(EventCnt) * EventWidth, TableY + 2); Ch := GetKey; { wait for keystroke } if Interrupted then Exit; if P > 0 then { Re-draw "event" and "truth table" in low video } begin PrintXY(Event, VLow, P, Row); PrintXY(Pad('', Length(Event)), VLow, P, Succ(Row)) end; PrintXY(Pad(Value, Width), VLow, TableX + Pred(EventCnt) * EventWidth, TableY + 2); end; { DisplayEvent } procedure DoLoop; { Execute the loop, use a truth table and highlighting to show which expression is being evaluated at each stage of the loop. } var I : integer; begin Message('Step through the loop by typing any key...'); for I := Value[1] to Value[2] do begin DisplayEvent(Event[1], Stmt[1], IntToString(I, 2), 1, 1); if Interrupted then Exit; DisplayEvent(Event[2], Stmt[1], BoolToString(I <= Value[2]), 2, 0); if Interrupted then Exit; end; DisplayEvent(Event[1], Stmt[1], 'UNDEFINED ', 1, 1); end; { DoLoop } begin { ForDo } LoadArrays; if not Interrupted then DoLoop; Message(''); end; { ForDo } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } ForDo; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This procedure uses a while loop and simulates loop decision making on the screen. The following while loop is displayed on the screen: I := A; while (I > B) and (I <= C) do I := I + D; You are asked to input values for the variables A - D. Then a truth table is constructed that contains an expression from each statement in the example. The procedure highlights the expression being evaluated, shows its value, and waits for you to press a key. Step through and evaluate each expression in order to understand how this important control statement works. The displays produced by this program illustrate the use of the WHILE statement. Most of the source code is devoted to creating these displays (rather than providing examples of WHILE statements). For this reason, we recommend that you run this example and watch it in action rather than (or prior to) examining the source code. } procedure WhileDo; (**) type Dummy = + DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error!  Please see the instructions at the bottom of this file. } (**) const MaxEvents = 4; { 4 unique events to highilght } MaxStmts = 3; { 3 statements to display } MaxValues = 4; { 4 variables to enter } TableX = 40; { x coordinate of truth table } TableY = 1; { y coordinate of truth table } EventWidth = 10; { max width of table entry } type StmtRay = array[1..MaxStmts] of AnyString; EventRay = array[1..MaxEvents] of AnyString; ValueRay = array[1..MaxValues] of integer; String2 = string[2]; var Stmt : StmtRay; { actual statement text } Event : EventRay; { text to highlight } Value : ValueRay; { values input by user } procedure LoadArrays; { Load the display data into the 3 global arrays; display loop on screen and input variable values. Variables are marked inside of each statement with a pound sign(#) followed by a single digit. } var I : integer; procedure InputValues(var Stmt : AnyString); { Given a statement, find each "variable" and get the value from the user. } var P, { position of the variable in the string } Index : integer; { index into the Value array } S : String2; function GetValue(var I : integer) : String2; { Get a 2-digit integer from the user } begin I := GetInteger(P, WhereY, 2, -MaxInt, MaxInt); GetValue := IntToString(I, 2); end; { GetValue } begin { InputValues } if Interrupted then Exit; P := Pos('#', Stmt); { look for a variable } while P > 0 do { more variables? } begin Index := Ord(Stmt[Succ(P)]) - Ord('0'); { get variable's index } S := GetValue(Value[Index]); { get value } if Interrupted then Exit; Move(S[1], Stmt[P], 2); { update string for display } P := Pos('#', Stmt); { look for a variable... } end; { while } Showln(''); Showln(''); end; { InputValues } procedure ShowStmt(Stmt : AnyString); { Display the loop statement on the screen, replace variable markers (a '#' followed by a digit) with 2 spaces } var I : byte; begin I := 0; while I < Length(Stmt) do begin I := Succ(I); if Stmt[I] = '#' then { replace variables with spaces } begin Print(' ', VNorm); I := Succ(I); end else Print(Stmt[I], VLow); end; { while } Showln(''); Showln(''); end; { ShowStmt } begin { LoadArrays } GotoWinXY(1, FirstRow); Stmt[1] := 'I := #1;'; { Set up array of statements } Stmt[2] := 'while (I > #2) and (I <= #3) do'; Stmt[3] := ' I := I + #4;'; for I := 1 to MaxStmts do { display statements } ShowStmt(Stmt[I]); Message('Enter an integer value for each variable '); GotoWinXY(1, FirstRow); { Enter numeric values for each "variable" } InputValues(Stmt[1]); InputValues(Stmt[2]); InputValues(Stmt[3]); if Interrupted then Exit; { define "events" to highlight on screen } Event[1] := Copy(Stmt[1], 1, 1); Event[2] := Copy(Stmt[2], 7, 8); Event[3] := Copy(Stmt[2], 20, 9); Event[4] := Copy(Stmt[3], 1, 3); { Display truth table } PrintXY('-------------------------------', VLow, TableX - 2, Succ(TableY)); for I := 1 to,  Pred(MaxEvents) do PrintXY(Event[I], VLow, TableX + Pred(I) * EventWidth, TableY); end; { LoadArrays } procedure DisplayEvent(Event, Stmt, Value : AnyString; EventCnt, Row : byte); { Used to simulate loop decision making: show which expression is being evaluated(called an "event"), show the value of the event in the truth table, then wait for a keystroke. Clean up highlighting when done. } const Width = 1; var P : byte; Ch : char; DisplayStr : AnyString; begin if Interrupted then Exit; { Show "event" in normal video } P := Pos(Event, Stmt); if P > 0 then begin PrintXY(Event, VNorm, P, Row); DisplayStr[0] := Chr(Length(Event)); FillChar(DisplayStr[1], Length(Event), '-'); PrintXY(DisplayStr, VNorm, P, Succ(Row)); end; { Show truth table } PrintXY(Pad(Value, Width), VNorm, TableX + Pred(EventCnt) * EventWidth, TableY + 2); Ch := GetKey; { wait for keystroke } { Re-draw "event" and "truth table" in low video }  if Interrupted then Exit; if P > 0 then begin PrintXY(Pad(Event, Width), VLow, P, Row); PrintXY(Pad('', Length(Event)), VLow, P, Succ(Row)) end; PrintXY(Pad(Value, Width), VLow, TableX + Pred(EventCnt) * EventWidth, TableY + 2); end; { DisplayEvent } procedure DoLoop; { Execute the loop, use a truth table and highlighting to show which expression is being evaluated at each stage of the loop. } var S : AnyString; { scratch } begin Message('Step through the loop by typing any key... '); Str(Value[1]:2, S); DisplayEvent(Event[1], Stmt[1], S, 1, 1); while (Value[1] > Value[2]) and (Value[1] <= Value[3]) and not Interrupted do begin DisplayEvent(Event[2], Stmt[2], BoolToString(Value[1] > Value[2]), 2, 3); DisplayEvent(Event[3], Stmt[2], BoolToString(Value[1] <= Value[3]), 3, 3); Value[1] := Value[1] + Value[4]; Str(Value[1]:2, S); DisplayEvent(Event[4], Stmt[3], S, 1, 5); end; DisplayEvent(Event[2], Stmt[2], BoolToString(Value[1] > Value[2]), 2, 3); DisplayEvent(Event[3], Stmt[2], BoolToString(Value[1] <= Value[3]), 3, 3); end; { DoLoop } begin { WhileDo } LoadArrays; if not Interrupted then DoLoop; Message(''); end; { WhileDo } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } WhileDo; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library }  For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) - { This procedure uses a repeat loop and simulates loop decision making on the screen. The following repeat loop is displayed on the screen: I := A; repeat I := I + B; until (I <= C) or (I > D); You are asked to input values for the variables A - D. Then a truth table is constructed that contains an expression from each statement in the example. The procedure highlights the expression being evaluated, shows its value, and waits for you to press a key. Step through and evaluate each expression in order to understand how this important control statement works.  The displays produced by this program illustrate the use of the REPEAT statement. Most of the source code is devoted to  creating these displays (rather than providing examples of REPEAT statements). For this reason, we recommend that you run this example and watch it in action rather than (or prior to) examining the source code. } procedure RepUntil; (**)  type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const MaxEvents = 4; { 4 unique events to highilght } MaxStmts = 4; { 3 statements to display } MaxValues = 4; { 4 variables to enter } TableX = 40; { x coordinate of truth table } TableY = 1; { y coordinate of truth table } EventWidth = 10; { max width of table entry } type StmtRay = array[1..MaxStmts] of AnyString; EventRay = array[1..MaxEvents] of AnyString; ValueRay = array[1..MaxValues] of integer; String2 = string[2]; var Stmt : StmtRay; { actual statement text }  Event : EventRay; { text to highlight } Value : ValueRay; { values input by user } procedure LoadArrays; { Load the display data into the 3 global arrays; display loop on screen and input variable values. Variables are marked inside of each statement with a pound sign(#) followed by a single digit. } var Counter : integer; procedure InputValues(var Stmt : AnyString); { Given a statement, find each "variable" and get the value from the user. } var P, Index : integer; S : String2; function GetValue(var I : integer) : String2; { Get a 2-digit integer from the user } begin I := GetInteger(P, WhereY, 2, -MaxInt, MaxInt); GetValue := IntToString(I, 2); end; { GetValue } begin { InputValue } P := Pos('#', Stmt); { look for a variable } while P > 0 do { more variables? } begin Index := Ord(Stmt[Succ(P)]) - Ord('0'); { get variable's index } S := GetValue(Value[Index]); { get value } if Interrupted then Exit; Move(S[1], Stmt[P], 2); { update string for display } P := Pos('#', Stmt); { look for a variable... } end; { while } Showln(''); Showln(''); end; { InputValue } procedure ShowStmt(Stmt : AnyString); { Display the loop statement on the screen, replace variable markers (a '#' followed by a digit) with 2 spaces in reverse video. } var I : byte; begin I := 0; while I < Length(Stmt) do begin I := Succ(I); if Stmt[I] = '#' then { replace variables with spaces } begin Print(' ', VNor. m); I := Succ(I); end else Print(Stmt[I], VLow); end; { while } Showln(''); Showln(''); end; { ShowStmt } begin { LoadArrays } GotoWinXY(1, FirstRow); Stmt[1] := 'I := #1;'; { Set up array of statements } Stmt[2] := 'repeat'; Stmt[3] := ' I := I + #2;'; Stmt[4] := 'until (I <= #3) or (I > #4);'; for Counter := 1 to MaxStmts do { display statements } ShowStmt(Stmt[Counter]); Message('Enter an integer value for each variable '); GotoWinXY(1, FirstRow); { Enter numeric values for each "variable" } InputValues(Stmt[1]); if Interrupted then Exit; Showln(''); Showln(''); InputValues(Stmt[3]); if Interrupted then Exit; InputValues(Stmt[4]); if Interrupted then Exit; { define "events" to highlight on screen } Event[1] := Copy(Stmt[1], 1, 1); Event[2] := Copy(Stmt[3], 1, 3); Event[3] := Copy(Stmt[4], 7, 9); Event[4] := Copy(Stmt[4], 20, 8); PrintXY('------------------------------', VLow, TableX - 2, Succ(TableY)); { Display truth table } for Counter := 1 to MaxEvents do begin if Counter <> 2 then  begin if Counter = 1 then PrintXY(Event[Counter], VLow, TableX + Pred(Counter) * EventWidth,  TableY) else PrintXY(Event[Counter], VLow, TableX +(Counter - 2) * EventWidth, TableY); end; end; end; { LoadArrays } procedure DisplayEvent(Event, Stmt, Value: AnyString; EventCnt, Row: byte); { Used to simulate loop decision making: show which expression is being evaluated (called an "event"), show the value of the event in the truth table, then wait for a keystroke. Clean up highlighting when done. } const Width = 1; var P : byte; Ch : char; DisplayStr : AnyString; begin { DisplayEvent } if Interrupted then Exit; P := Pos(Event, Stmt); if P > 0 then begin PrintXY(Event, VNorm, P, Row); { Show "event" in normal video } DisplayStr[0] := Chr(Length(Event));  FillChar(DisplayStr[1], Length(Event), '-'); PrintXY(DisplayStr, VNorm, P, Succ(Row)); end; { Show "truth table" value in normal video } PrintXY(Pad(Value, Width), VNorm, TableX + Pred(EventCnt) * EventWidth, TableY + 2); Ch := GetKey; { wait for keystroke } if Interrupted then Exit; { Re-draw "event" and "truth table" in low video } if P > 0 then begin PrintXY(Event, VLow, P, Row); PrintXY(Pad('', Length(Event)), VLow, P, Succ(Row)) end; PrintXY(Pad(Value, Width), VLow, TableX + Pred(EventCnt) * EventWidth, TableY + 2); end; { DisplayEvent } procedure DoLoop; { Execute the loop, use a truth table and highlighting to show which expression is being evaluated at each stage of the loop. } begin Message('Step through the loop by typing any key... '); DisplayEvent(Event[1], Stmt[1], IntToString(Value[1], 2), 1, 1); repeat Value[1] := Value[1] + Value[2]; DisplayEvent(Event[2], Stmt[3], IntToString(Value[1], 2), 1, 5); DisplayEvent(Event[3], Stmt[4], BoolToString(Value[1] <= Value[3]), 2, 7); DisplayEvent(Event[4], Stmt[4], BoolToString(Value[1] > Value[4]), 3, 7); until (Value[1] <= Value[3]) or (Value[1] > Value[4]) or (Interrupted); end; { Do/ Loop } begin { RepUntil } LoadArrays; if not Interrupted then DoLoop; Message(''); end; { RepUntil } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } RepUntil; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example performs simple arithmetic operations on real numbers. Real numbers are positive and negative numbers that can range from 1E38 (100000000000000000000000000000000000000.0, or 1 x 10 to the 38th power), to 1E-38 (0.00000000000000000000000000000000000001, or 1 x 10 to the minus 38th power). Unlike integers, real numbers can contain fractional parts (digits below the decimal point). In Turbo Pascal, a real number is a number that includes a decimal point (.), an exponent (the letter E and an integer giving a power of 10), or both. For complete syntax diagrams, see Appendix A in Tutor manual.  This program is a four function (real number) calculator that shows how to 1. Read in real numbers, checking the input for the correct format (Val procedure); 2. Perform calculations on real numbers with the operators +, -, *, /; and 3. Check for errors when doing real number calculations--including overflow, underflow, and division by zero. } procedure Reals; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. }  (**) const ErrorNum : real = 1E20; { Error number that forces display overflow } var Error : boolean; { TRUE if overflow/underflow occurred } procedure Display(var R : real); { Displays a number in the calculator display. If the number  is too large, displays an error message instead. } var S : AnyString; Temp : integer; begin S := RealToString(R, 1, 2); { round to 2 places } Val(S, R, Temp); { convert back to real to strip off any unnecessary digits } S := RealToString(R, 12, 2); { convert back to string } Error := Length(S) > 12; { number too large? } if Error then S := ' ERROR '; PrintXY(S + ' ', VLow, 2, Succ(FirstRow)); { display # or err } GotoWinXY(2, Succ(FirstRow)); end; { Display } procedure DrawCalculator; { Draws the calculator on the screen } begin PrintXY('+-------------+', VNorm, 1, FirstRow); PrintXY('| |', VNorm, 1, Succ(FirstRow)); PrintXY('|-------------|', VNorm, 1, FirstRow + 2); PrintXY('| = 7 8 9 /0  |', VNorm, 1, FirstRow + 3); PrintXY('| BS 4 5 6 * |', VNorm, 1, FirstRow + 4); PrintXY('| 1 2 3 - |', VNorm, 1, FirstRow + 5); PrintXY('| C 0 . + |', VNorm, 1, FirstRow + 6); PrintXY('| |', VNorm, 1, FirstRow + 7); PrintXY('+-------------+', VNorm, 1, FirstRow + 8); PrintXY('Esc', VNorm, 4, FirstRow + 9); Print(' - Quit', VLow); end; { DrawCalculator } procedure RunCalculator; { Lets the user run the calculator } var OldInp, LastOperator, Inp : char; DisplayString : AnyString; Total, Number : real; Negative, DecimalUsed : boolean; procedure ShowTemp(var S : AnyString); { Converts number string to numeric, displays results } var Valid : integer; Temp : real; begin if S = '' then S := '0'; Val(S, Temp, Valid); if Valid = 0 then Display(Temp) else Display(ErrorNum); { force an error display } end; { ShowTemp of RunCalculator } procedure Operand(var S : AnyString); { Given a numeral or decimal pt., adds it to the string and re-displays the current (temp) value. } begin if LastOperator in [CR, '='] then Total := 0.0; if ((not DecimalUsed) and (Length(S) < 8)) or ((DecimalUsed) and (Length(S) - Pos('.', S) < 2)) or ((Inp = '.') and (not DecimalUsed)) then begin if S = '0' then S := ''; if Inp = '.' then DecimalUsed := True; S := S + Inp; ShowTemp(S); end; { if } end; { Operand of RunCalculator } procedure BackSpace(var S : AnyString); { Backspace key was pressed; removes last char & re-displays string } begin if S <> '0' then begin if S[Length(S)] = '.' then DecimalUsed := False; Delete(S, Length(S), 1); ShowTemp(S); end; { if } end; { BackSpace of RunCalculator } procedure Operator(var S : AnyString); { Performs the operation } var Valid : integer; begin DecimalUsed := False; Val(S, Number, Valid); if Valid <> 0 then { error occurred } begin Display(ErrorNum); Exit; { quit calculator } end; if Negative then Number := Number * -1.0; if (OldInp in ['0'..'9', CR, '=']) then begin case LastOperator of  '+', '=', CR : Total := Total + Number; '-' : Total := Total - Number; '/' : if Number = 0.0 then Total := ErrorNum else Total := Total / Number; '*' : Total := Total * Number; end; { case } LastOperator := Inp; Negative := False; end { if } else Negative := (Inp = '-'); Display(Total); S := '0'; end; { Operator of RunCalculator } procedure ClearCalculator; { Clear the calculator, initialize variables } begin DecimalUsed := False;  Total := 0.0; Number := 0.0; DisplayString := '0'; LastOperator := '+'; OldInp := 'C'; Negative := False; Error := False; Display(Total); end; { ClearCalculator of RunCalculator } begin { RunCalculator } ClearCalculator; repeat Inp := UpCase(GetKey); if not ((Error) and not (Inp in ['C', ESC, IntChar])) then { Accept onl1 y C, ESC, or interrupt if error has occurred } case Inp of ESC, IntChar: Exit; { done w/ calculator } 'C'  : ClearCalculator; '.','0'..'9': Operand(DisplayString); BS : BackSpace(DisplayString); CR,'=','+', '-','/','*' : Operator(DisplayString); end; { case } if Inp <> BS then OldInp := Inp; { remember last input } until false; { infinite loop stops when ESC is typed(see above) } end; { RunCalculator } begin { Reals } DrawCalculator; RunCalculator; end; { Reals } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Reals; { execute the procedure } end. { end of the program }  Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This program demonstrates the use of enumerated scalar types. It allows the user to step forward and backward through the days of the week. Values of enumerated scalar types cannot be written out directly. For this reason, we use an array of strings to hold printable text representing the name of each day. To print a value of the enumerated type DayType, we use the value to index into the typed constant array WeekDayName, and display the resulting string. } procedure Scalars; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) type DayType = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday); { The enumerated type decalaration for the days of the week } DayName = string[13]; { Type that holds the name of the day } const WeekDayName: array[DayType] of DayName = { An array that holds day names } (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '); var Current: DayType; { The current day } procedure UpdateScreen; { Updates the information on the screen } var Day : DayType; SaveX, SaveY, Counter : byte; begin { UpdateScreen } ClearLines(FirstRow + 6, FirstRow + 6); { Clear old arrow } GotoWinXY(1, FirstRow + 5); for Day := Sunday to Pred(Current) do { Print out days prior to current } Print(WeekDayName[Day], VLow); SaveX := WhereX; SaveY := WhereY; Print(WeekDayName[Current], VNorm); { Print out Current } GotoWinXY(SaveX, Succ(SaveY)); { Move down a line } for Counter := 1 to Length(WeekDayName[Current]) d2 o Print('-', VLow); { Underline current day } GotoWinXY(WhereX, Pred(WhereY)); { Move up a line } for Day := Succ(Current) to Saturday do { Print out days after current } Print(WeekDayName[Day], VLow); end; { UpdateScreen } procedure PrintMessage(S : AnyString); { Prints a message in the middle of the screen } begin Message (S); Delay(1000); { Wait for 1 second } Message (''); { Erase message } end; { PrintMessage } procedure ReadArrows(var Choice : char); { Reads the input from the keyboard } begin Choice := GetKey; { Read user input } case Choice of RightKey: begin { Right arrow key was pressed } if Current = Saturday then { Move forward through days } begin PrintMessage('Undefined, moving to Sunday'); Current := Sunday; end else Current := Succ(Current); UpdateScreen;  end; LeftKey: begin { Left arrow key was pressed } if Current = Sunday then { Move backward through days } begin PrintMessage('Undefined, moving to Saturday'); Current := Saturday; end else Current := Pred(Current); UpdateScreen; end; end; { case } end; { ReadArrows } procedure StepThroughDays; { Allows the user to step through the days of the week forwards and backwards } var Choice : char; { The user input } begin repeat ReadArrows(Choice); until(Choice in [ESC, IntChar]); { Quit if user presses escape } { or interrupt key } end; { StepThroughDays } procedure PrintPrompt; { prints a prompt for the user } begin PrintXY(' Succ(Day) Pred(Day)  Quit', VLow, 21, Succ(Firstrow)); PrintXY('^D', VNorm, 20, Succ(FirstRow)); PrintXY('^S', VNorm, 36, Succ(FirstRow)); PrintXY('Esc', VNorm, 52, Succ(FirstRow)); end; { PrintPrompt } begin { Scalars } PrintPrompt; { prints a user prompt on the screen } Current := Wednesday; UpdateScreen; StepThroughDays; { allow user to step through names of days }  end; { Scalars } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Scalars; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example demonstrates the set union, intersection, and difference operations. There are four groups of set operations: 1. Those that add elements to a set (assignment, union); 2. Those that remove elements from a set (difference, intersection); 3. Those that test whether an element is in a set (membership); and 4. Those that test whether two sets are exactly alike (equality). The "set constructor" (a pair of square brackets with a list of constants, variables, and3  subranges) allows you to specify the elements of a set within an expression. This program lets you define two sets: Set1 and Set2. It then performs the following operations and displays the results: Operand Operator Operand Description ------- -------- ------- ----------- Set1 := [] Assignment Set1 * Set2 Intersection Set1 + Set2 Union Set1 - Set2 Difference Set2 - Set1 Difference } procedure Sets1; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const Letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; type LetterSet = set of 'A'..'Z'; var Set1, Set2 : LetterSet; procedure PrintSet(SetTitle : AnyString; TempSet : LetterSet; Row : byte; PrintSemicolon : boolean); { Prints out the elements of a set } var Ch, LastCh : char; NeedaComma : boolean; function GetLastChar(C : char; ThisSet : LetterSet) : char; { Checks a particular character and decides whether to print it or not } var Ch : char; begin GetLastChar := #0; for Ch := C to 'Z' do begin if not (Ch in ThisSet) then Exit; GetLastChar := Ch; end; end; { GetLastChar } begin { PrintSet } PrintXY(SetTitle + '= ', VNorm, 1, Row); Print('[', VLow); Ch := 'A'; NeedaComma := false; { first letter: don't lead with a comma } repeat LastCh := GetLastChar(Ch, TempSet);  if LastCh <> #0 then begin if NeedaComma then Print(',', VLow); Print(Ch, VNorm); { always print first letter } if Pred(LastCh) > Ch then { sub-range: A..C } begin Print('..', VLow); NeedaComma := false; { printed subrange dots instead } end else NeedaComma := true; { aleady printed first letter }  if Ch <> LastCh then { i.e. A,B } begin if NeedaComma then Print(',', VLow); Print(LastCh, VNorm); end; Ch := Succ(LastCh); { increment loop var } NeedaComma := true; { aleady printed first letter } end else Ch := Succ(Ch); { increment loop var } until Ch > 'Z'; Print(']', VLow); if PrintSemicolon then Print(';', VLow); end; { PrintSet } procedure GetSet(var TempSet : LetterSet; Col, Row : byte); { Lets the user enter the elements of a set } var Ch, Current : char; begin Current := 'A'; GotoWinXY(Col, Row); repeat Ch := GetKey; case Ch of LeftKey, ^S: if Current = 'A' then Current := 'Z'  else Current := Pred(Current); RightKey, ^D: if Current = 'Z' then Current := 'A' else Current := Succ(Current); ' ': if Current in TempSet then  TempSet := TempSet - [Current] else TempSet := TempSet + [Current]; end; { case } GotoWinXY(Col + Ord(Current) - Ord('A'), Row); if Current in TempSet then Print(Current + BS + LF + '-', VNorm) el4 se Print(Current + BS + LF + ' ', VLow); GotoWinXY(Pred(WhereX), Pred(WhereY)); { Move up a line and back a column } until Interrupted or (Ch = CR); end; { GetSet } procedure PaintScreen; { Displays the sets and user commands } begin  PrintXY('Set1: ', VNorm, 1, FirstRow); Print(Letters, VLow); PrintXY('Set2: ', VNorm, 40, FirstRow); Print(Letters, VLow); Message('Highlight a letter to include it in the set...'); PrintXY('Highlight letter on/off Move left Move right' + ' Finished', VLow, 7, FirstRow + 7); PrintXY('SPACE', VNorm, 1, FirstRow + 7); PrintXY('^S', VNorm, 33, FirstRow + 7); PrintXY('^D', VNorm, 49, FirstRow + 7); PrintXY('Enter', VNorm, 66, FirstRow + 7); end; { PaintScreen } begin { Sets1 } Set1 := []; { init both sets } Set2 := []; PaintScreen; { setup screen } GetSet(Set1, 7, FirstRow); { get first set } if Interrupted then { user typed ESC } Exit; PrintSet('Set1 :', Set1, FirstRow + 2, True); { re-display first set } GetSet(Set2, 46, FirstRow); { get 2nd set } if Interrupted then { user typed ESC } Exit; PrintSet('Set2 :', Set2, FirstRow + 3, True); { re-display 2nd set } ClearLines(FirstRow + 7, FirstRow + 7); Message(''); { clear message line } { Calculate and display results } PrintSet('Set1 * Set2 ', Set1 * Set2, FirstRow + 5, False); PrintSet('Set1 + Set2 ', Set1 + Set2, FirstRow + 6, False); PrintSet('Set1 - Set2 ', Set1 - Set2, FirstRow + 7, False); PrintSet('Set2 - Set1 ', Set2 - Set1, FirstRow + 8, False); end; { Sets1 } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Sets1; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example uses sets to "deal" a deck of cards. It performs the following set operations: Operation Symbol ---------- ------ Assignment := Membership in Union + Difference - Equality = This procedure uses two sets, DECK and DEALT. It places 52 cards in DECK and empties DEALT. It then randomly takes cards from DECK, shows them to the user, and then places the cards in DEALT. } procedure Sets2; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const HighCard = 52; { cards range from 1..52 } type CardSet = set of byte; { will contain cards } var Dealt, { the cards already dealt } Deck : CardSet; { the cards remaining to deal } procedure CountCards(var 5 Deck : CardSet); { Place 52 cards in the deck numbered from 1..52 } var Card : integer; begin Deck := []; { empty the set } Print('Counting card:', VLow); for Card := 1 to HighCard do { place 52 cards in the deck } begin Print(IntToString(Card, 3) + #8 + #8 + #8, VNorm); { display card, then 3 backspaces } if CheckInterrupt then Exit;  Deck := Deck + [Card]; { add card to deck } end; end; { CountCards } procedure ShowCard(Card : integer); { Given a card 1..52, convert to Rank, Suit and then display it. } const RankStr : string[13] = 'A23456789TJQK'; { symbols for each rank } SuitStr : string[4] = 'HDCS'; { symbols for each suit } var Rank, { ranks range from 1..13 } Suit : byte; { suits range from 1..4 } begin Suit := Succ(Pred(Card) div 13); Rank := Succ(Pred(Card) mod 13); PrintXY(RankStr[Rank] + SuitStr[Suit], VNorm, Rank * 4, (Suit * 2) + FirstRow); end; { ShowCard } procedure DealCards(var Deck, Dealt : CardSet); { Take cards from the deck randomly until the deck is empty. A while loop keeps generating "cards" randomly until it finds one that has not been dealt yet } var Number, Card : byte; begin Showln(''); Print('Dealing card:', VLow); Number := 0; repeat Card := 0; { set card to illegal value to begin } { keep looking for an undealt card }  while (Card = 0) or not (Card in Deck) do Card := Random(Succ(HighCard)); Number := Succ(Number); { 1 more card was dealt } PrintXY(IntToString(Number, 3), VNorm, 15, Succ(FirstRow)); ShowCard(Card); { show the card to user } if CheckInterrupt then Exit; Dealt := Dealt + [Card]; { place in DEALT pile } Deck := Deck - [Card]; { remove from DECK } Delay(30); until Deck = []; { stop when DECK is empty } end; { DealCards } begin { Sets2 } CountCards(Deck); { place 52 cards in the deck } if Interrupted then Exit; Dealt := []; { empty the DEALT pile } DealCards(Deck, Dealt); { Deal 'em! } end; { Sets2 } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Sets2; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking }  {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example demonstrates the use of Turbo's built-in string procedures and functions: Insert, Delete, Concat (or +), and Length. Insert(S : Anystring; var D: Anystring; Pos : integer); Inserts string S into string D, starting at position Po6 s. Delete(var S : Anystring; Pos, Len : integer); Deletes Len characters from string S, beginning at position Pos.  Concat(S1,S2 [,S3...,Sn] : AnyString) : AnyString; Concatenates any number of strings into one big string. Can also be represented as S1 + S2 +.... The brackets denote optional parameters. Length(S : AnyString) : integer; Returns the length of a string in bytes. The maximum length is 255, and the minimum length is zero. } procedure Strings1; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) var String1 : AnyString; procedure ClearPrompt; { Clears a prompt from the screen } begin ClearLines(FirstRow + 6, FirstRow + 7); end; { ClearPrompt } procedure SetUpScreen; { Put up the initial header } var I : byte; begin PrintXY('Position :', VLow, 1, FirstRow); for I := 1 to 20 do Show(IntToString(I, 3)); end; { SetUpScreen } procedure MakeString(var NewStr : AnyString; Directive : AnyString); { Gets a string from the user } begin PrintXY('Enter up to 10 characters for' + Directive + 'string, and press return: ', VNorm, 1, FirstRow + 6); { Ask the user to enter the string to work with }  NewStr := GetString(WhereX, WhereY, 10); ClearPrompt; end; { MakeString } procedure DisplayString(LabelOp, DispString : AnyString; Y : integer); var CurrentChar : integer; begin PrintXY(LabelOp, VLow, 1, Y); { Display the Operation type before } { the new string } GotoWinXY(16, Y); for CurrentChar := 1 to Length(DispString) do { Display the current } Print(DispString[CurrentChar] + ' ', VNorm); { string under the } end; { DisplayString } { numbers. } procedure Options1(var String1 : AnyString); var Position : integer; Character : char; begin GotoWinXY(1, FirstRow + 6); Print('Delete character at position (1..' + IntToString(Length(String1), 1) + '): ', VNorm); { Ask for a position to be removed from the string } Position := GetInteger(WhereX, WhereY, 2, 1, Length(String1)); if Interrupted then  Exit; ClearPrompt; Character := String1[Position]; Delete(String1, Position, 1); { Delete the character } DisplayString('Deleted ''' + Character + ''': ', String1, 3); end; { Options1 } procedure Options2(var String1 : AnyString); var Position : integer; Character : char; begin PrintXY('Enter a character to insert: ', VNorm, 1, FirstRow + 6); { Ask for a character to be } Character := GetChar(WhereX, WhereY); { inserted in the string } ClearPrompt; if Interrupted then Exit; if (Length(String1) > 0) then begin PrintXY('Enter position (1..' + IntToString(Succ(Length(String1)), 1) + '): ', VNorm, 1, FirstRow + 6); { Ask for insertion position } Position := GetInteger(WhereX, WhereY, 2, 1, Succ(Length(String1))); ClearPrompt; if Interrupted then Exit; Insert(Character, String1, Position);  end else { If the string has no characters in it then make the string into } String1 := Character; { the inserted cha7 racter } DisplayString('Inserted ''' + Character + ''': ', String1, 4); end; { Options2 } procedure Options3(String1 : AnyString); var String2, ConcatStr : AnyString; begin MakeString(String2, ' another '); { Ask for a new string to } ConcatStr := Concat(String1, String2); { Concatenate it } DisplayString('Concatenated: ', ConcatStr, 5); { Display the new string. } end; { Options3 } begin { Strings1 } SetUpScreen; String1 := ''; MakeString(String1, ' a '); if Interrupted then Exit; DisplayString('Your String : ', String1, 2); Options1(String1); if Interrupted then Exit; Options2(String1); if Interrupted then Exit; Options3(String1); end; { Strings1 } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Strings1; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example demonstrates some useful user-defined string procedures. The procedure HighlightElement prints out a string with a specified character highlighted. The procedure CenterString centers a string within a field of 80 characters (the length of a line on most computer screens). The procedure UpCaseStr changes all of the lowercase letters in a string to their uppercase counterparts. } procedure Strings2; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) var String1, ReturnStr : AnyString; { Global declarations } Counter, Position : integer; procedure ClearPrompt; { Clears a prompt from the screen } begin ClearLines(FirstRow + 6, FirstRow + 7); end; { ClearPrompt } procedure HighlightElement(Instr : AnyString; Position : integer); var StrLength : integer; Counter : integer; StopPos : integer; begin StrLength := Length(InStr); { Store length of string} StopPos := Pred(Position); { Stop before highlighted character} for Counter := 1 to StopPos do Print(InStr[Counter], VLow); Print(InStr[Position] + BS + LF + '-', VNorm); { Write highlighted character } GotoWinXY(WhereX, Pred(WhereY)); { Move up a line } StopPos := Succ(Position); for Counter := StopPos to StrLength do Print(InStr[Counter], VLow); { write the rest of the string} Showln(''); end; { HighlightElement } procedure CallHighlight(InStr : AnyString; var Position : integer); begin PrintXY('Which position would you like to highlight? ', VNorm, 1, FirstRow + 6); Position := GetInteger(WhereX, WhereY, 2,8  1, Length(InStr)); ClearPrompt; if Interrupted then Exit; PrintXY('Highlighted ' + IntToString(Position, 2) + ' : ', VNorm, 1, FirstRow + 2); HighlightElement(InStr, Position); { call highliting procedure } Showln(''); end; { CallHighlight } procedure UpCaseStr(InStr : AnyString; var OutStr : AnyString); var Counter : integer; begin OutStr := ''; { change the string to upper case } for Counter := 1 to Length(InStr) do OutStr := OutStr + UpCase(InStr[Counter]); Print('Upper Case : ', VNorm); HighlightElement(OutStr, Position); { call highlight procedure to } end; { UpCaseStr } { write new upper case string } procedure CenterText(InStr : AnyString); var I : integer; begin  Print('Centered : ', VNorm); Showln(''); for I := 1 to 7 do { print number line: 10's column } Print(IntToString(I, 10), VNorm); { print number line: 1's column } Showln(''); for I := 1 to 79 do Print(IntToString(I MOD 10, 1), VNorm); Showln(''); Print(Pad('', (80 - Length(InStr)) div 2), VLow); { Print blanks in front } { of the string } HighlightElement(InStr, Position); { call highlighting routine} end; { CenterText } begin { Strings2 } Message('This procedure demonstrates some simple string functions...'); PrintXY('Enter String: ', VNorm, 1, FirstRow + 6); { read in first string } { and display it } String1 := GetString(WhereX, WhereY, 30); Message(''); ClearPrompt; if Interrupted then  Exit; GotoWinXY(18, FirstRow); for Counter := 1 to 6 do Print(IntToString(Counter * 5, 5), VLow); PrintXY('Your String : ', VNorm, 1, Succ(FirstRow)); { display string in upper case } Print(String1, VLow); Showln(''); CallHighlight(String1, Position); { highlight character procedure } if Interrupted then Exit; UpCaseStr(String1, ReturnStr); { call upper case procedure } CenterText(ReturnStr); { center the text } end; { Strings2 } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Strings2; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { Arrays are commonly used to store a collection of like-sized objects (lists, tables, grids, etc.). In the Turbo Tutor manual, we show how a two-dimensional array can be used to represent a checkerboard. In this example, we use an array in a similar way: as a "treasure map." This procedure plays a game in which the user tries to guess the location of a pot of gold. The location of the pot is kept in an internal "map" that is a square array of boolean variables. The position of the p9 ot is indicated by a value of TRUE (all the other items in the array have the value FALSE). Determining whether or not the treasure has been found is as simple as checking the "truth" or "falsehood" of the selected location (array element). }  procedure Arrays1; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) const MaxX = 6; { The maximum X and Y coordinates } MaxY = 6; type GameRecord = record XGuess, YGuess : byte; { The X and Y coordinates guessed by the user } XLoc, YLoc : byte; { The X and Y location of the gold } Square : array[1..MaxX, 1..MaxY] of boolean; { The possible treasure locations, one of which will be True } Guessed : array[1..MaxX, 1..MaxY] of boolean; { Which squares have been guessed } Tries : byte; { How many tries it took } Found : boolean; { The treasure has been found } end; function Distance(GameRec : GameRecord) : byte; { Figures out the distance from the guess to the treasure } begin with GameRec do Distance := Abs(XGuess - XLoc) + Abs(YGuess - YLoc); end; { Distance } procedure SetUpTreasure(var GameRec : GameRecord); { Finds a place for the treasure } begin with GameRec do begin FillChar(Square, SizeOf(Square), 0); { Initialize the squares } FillChar(Guessed, SizeOf(Guessed), 0); { No guesses have been made } XLoc := Succ(Random(MaxX)); { Find a random location } YLoc := Succ(Random(MaxY)); { for the treasure } Square[XLoc, YLoc] := True; { Mark the treasure square } Found := False; Tries := 0; end; { with } end; { SetUpTreasure } procedure GetGuess(var GameRec : GameRecord); { Allows the user to guess the location of the treasure } begin with GameRec do begin repeat PrintXY('X and Y Coordinates: [ , ]', VNorm, 40, FirstRow + 3); XGuess := GetInteger(62, FirstRow + 3, 2, 1, MaxX); { Let user guess X } if Interrupted then { treasure location } Exit; YGuess := GetInteger(66, FirstRow + 3, 2, 1, MaxY); { Let user guess Y } if Interrupted then { treasure location } Exit; if Guessed[XGuess, YGuess] then { Don't let user guess } begin { same square twice }  Beep; Message('That square was guessed already. Pick again.'); end; ClearXY(40, FirstRow + 3); until Guessed[XGuess, YGuess] = False; { Pick only unguessed squares } Message(''); Tries := Succ(Tries); end; { with } end; { GetGuess } procedure PrintBoard(GameRec : GameRecord); { Prints out the playing board } var Counter, Count : byte; begin with GameRec do begin PrintXY('X', VNorm, 12, FirstRow); { Print out X coordinates } PrintXY(' ', VNorm, 1, Succ(FirstRow)); for Counter := 1 to MaxX do Print(IntToString(Counter, 3), VNorm); PrintXY('Y', VNorm, 1, FirstRow + 4); for Counter := 1 to MaxY do begin PrintXY(IntToString(Counter, 1) + ' ', VNorm, 3,  Succ (Counter + FirstRow)); { Print out Y coordinates } for Count := 1 to MaxX do { Print out X's on the board } :  Print(' O ', VLow); end; end; { with } end; { PrintBoard } procedure MarkSquare(var GameRec : GameRecord; VType : VideoType); { Marks a square (in a particular video mode) as being "guessed" } begin with GameRec do begin PrintXY('X', VType, (3 * XGuess) + 3, Succ(YGuess + FirstRow)); Guessed[XGuess, YGuess] := True; end; { with } end; { MarkSquare } procedure Play(var GameRec : GameRecord); { The main loop of the procedure - reads in a guess and prints the result } var S : string[8]; begin with GameRec do begin GetGuess(GameRec); if Interrupted then Exit; Found := Square[XGuess, YGuess]; if Found then begin Beep; MarkSquare(GameRec, VNorm); Message('YOU FOUND IT! --- Tries: ' + IntToString(Tries, 1)); end else begin MarkSquare(GameRec, VNorm); if Distance(GameRec) = 1 then { Print out correct message } S := ' square' else S := ' squares'; Message('Square [' + IntToString(XGuess, 1) + ', ' + IntToString(YGuess, 1) + '] is ' + IntToString(Distance(GameRec), 1) + S + ' from the treasure.'); end; end; { with } end; { Play } var GameRec : GameRecord; begin { Arrays1 } with GameRec do begin Message('Try to guess the location of the hidden treasure.'); SetUpTreasure(GameRec); PrintBoard(GameRec); repeat Play(GameRec); until (Found) or (Interrupted); end; { with } end; { Arrays1 } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: { program body } ; { get ready to run example } ; { execute the procedure } . { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: $C-} { turn off Ctrl-C checking } $I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This program fills an array with random integers in the range 1..99, and then sorts the array (from left to right in ascending order) using a sorting technique called a bubble sort. A bubble sort simply makes several passes through an array, comparing elements next to each other and swapping them if they are out of order. The swapping process is repeated until all the values are in order. The basic algorithm for the bubble sort is as follows: for LastElement := ArraySize downto 2 do for CurElement := 1 to Pred(LastElement) do if SortArray[CurElement] > SortArray[Succ(CurElement)] then  Switch(CurElement, Succ(CurElement)); While the bubble sort is not the most efficient way of sorting an array, because of its simplicity it is often used in many situations where time is not critical. } procedure Arrays2; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler ; error! Please see the instructions at the bottom of this file. } (**) const ArraySize = 10; { The amount of elements in SortArray } ColumnStart = 22; { The starting column for text output } DelayTime = 600; type LegalVal = 1..99; { The range of legal array elements } ArrayType = array[1..ArraySize] of LegalVal; { The array type } var SortArray : ArrayType; { The array to be sorted } procedure Initialize; { Initialize SortArray with random values in the range 1..99 } var ArrayIndex: 1..ArraySize; { An index into SortArray } begin for ArrayIndex := 1 to ArraySize do SortArray[ArrayIndex] := Succ(Random(99)); end; { Initialize } procedure ShowArray; { Display the contents of SortArray } begin PrintXY('+--+--+--+--+--+--+--+--+--+--+', VLow, Pred(ColumnStart), FirstRow + 3); PrintXY('|  | | | | | | | | | |', VLow, Pred(ColumnStart), FirstRow + 5); PrintXY('+--+--+--+--+--+--+--+--+--+--+', VLow, Pred(ColumnStart), FirstRow + 6); PrintXY('SortArray', VNorm, ColumnStart - 11, FirstRow + 4); Print(' | | | | | | | | | | |', VLow); end; procedure DrawElements; var ArrayIndex : integer; begin GotoWinXY(Pred(ColumnStart), FirstRow + 4); for ArrayIndex := 1 to ArraySize do begin PrintXY(IntToString(SortArray[ArrayIndex], 2) + BS + BS + LF + ' ', VNorm, Succ(WhereX), WhereY); GotoWinXY(WhereX, Pred(WhereY)); { Move up a line }  end; end; procedure DrawInverse(ElementIndex1, ElementIndex2 : integer); { Draw in reverse video the array element indexed by ElementIndex } begin PrintXY(IntToString(SortArray[ElementIndex1], 2) + BS + BS + LF, VLow, ColumnStart +((Pred(ElementIndex1)) * 3), FirstRow + 4); Print('--', VNorm); { Underline element } PrintXY(IntToString(SortArray[ElementIndex2], 2) + BS + BS + LF, VLow, Succ(WhereX), FirstRow + 4); Print('--', VNorm); { Underline element } end; { DrawInverse } procedure Switch(Index, NextIndex : integer); { Switch two elements of SortArray and draw them in inverse } var TempStore : integer; { A variable for temporary storage } begin DrawInverse(Index, NextIndex); { Draw in inverse values to be swapped } Delay(DelayTime); { A short Delay } TempStore := SortArray[Index]; { Swap the elements } SortArray[Index] := SortArray[NextIndex]; SortArray[NextIndex] := TempStore; Delay(DelayTime); { Another Delay } DrawInverse(Index, NextIndex); { Draw values that have been swapped } Delay(DelayTime); DrawElements; end; { Switch } procedure BubbleSort; { Perform a bubble sort on SortArray } var LastElement : 2..ArraySize; CurElement : 1..ArraySize; begin PrintXY('Sorting the array elements (bubble sort)...', VNorm, 11, Succ(FirstRow)); for LastElement := ArraySize downto 2 do  for CurElement := 1 to Pred(LastElement) do begin if CheckInterrupt then Exit; if SortArray[CurElement] > SortArray[Succ(CurElement)] then begin Switch(CurElement, Succ(CurElement)); end else  begin DrawInverse(CurElement, Succ(CurElement)); Delay(DelayTime * 2); DrawElements; end; <  end; end; { BubbleSort } begin { Arrays2 } Initialize; { Fill the array with randow numbers } ShowArray; { Display the initial array } DrawElements; BubbleSort; { Sort the array } end; { Arrays2 } (** TRYING TO RUN THIS PROGRAM?  This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Arrays2; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example demonstrates the use of random access files. We use the procedure Seek to move quickly to any location in the file; we also use the function FilePos and FileSize to tell us where we are in the file and how big it is, respectively. Please note that these standard procedures and functions work on random access files and on "untyped" files, but CANNOT be used on files of the type text. Random access files consist of any number of elements, each of the same component type. In this program, our component is a record with three fields: a first name, a last name, and an age. Each new records is appended to the end of the file after the data is entered by the user. The file pointer is moved forward and backward within the file by using FilePos to determine the current record number and then using Seek to point to the next or previous record: - FileSize(FileVar) returns the number of records in a file (integer). - FilePos(FileVar) returns the record number of the next record (an integer in the range 0..FileSize). - Seek(FileVar, RecNumber) moves the file pointer so that the next read will retrieve RecNumber (and the next write will overwrite it). } procedure RecFiles; {$I-}  { Turn off I/O error checking } (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) type RecordType = record { Sample record type } FirstName : string[10]; LastName : string[10]; Age : integer; end; const Filename = 'RECFILES.DTA'; { Temporary file name } FieldCol = 40; { Column to start fields in } var FileVar : file of RecordType; { File that holds records } FileError : boolean; { True if a file error has occurred } function CheckForError : boolean; { Checks IOResult for an I/O error } var ErrorNum : integer; begi= n ErrorNum := IOResult; if ErrorNum <> 0 then begin PrintXY('I/O error #' + IntToString(ErrorNum, 1) + ' occurred.', VNorm, 1, FirstRow + 8); FileError := True; end; CheckForError := FileError; end; { CheckForError }  procedure SetupFile; { Opens the data file } begin Assign(FileVar, Filename); Rewrite(FileVar); if CheckForError then; end; { SetupFile } procedure ClearFields; { Clears out the input fields on the screen } begin PrintXY(Pad('', 10), VNorm, FieldCol, FirstRow + 3); PrintXY(Pad('', 10), VNorm, FieldCol, FirstRow + 4); PrintXY(Pad('', 2), VNorm, FieldCol, FirstRow + 5); end; { ClearFields } procedure PrintFileSize; { Prints out the current file size } begin PrintXY(IntToString(FileSize(FileVar), 5), VNorm, 34, FirstRow); end; { PrintFileSize } procedure PrintFilePointer; { Prints out the location of the file pointer } begin PrintXY(IntToString(FilePos(FileVar), 5), VNorm, 41, Succ(FirstRow)); end; { PrintFilePointer } procedure DisplayRec(Rec : RecordType); { Displays a particular record on the screen } begin with Rec do begin  PrintXY(Pad(FirstName, Pred(SizeOf(FirstName))), VLow, FieldCol, FirstRow + 3); PrintXY(Pad(LastName, Pred(SizeOf(LastName))), VLow, FieldCol, FirstRow + 4); PrintXY(IntToString(Age, 2), VLow, FieldCol, FirstRow + 5); end; end; { DisplayRec } procedure AddRec; { Allows a user to input a record from the keyboard } var DataRec : RecordType; begin ClearFields; Seek(FileVar, FileSize(FileVar)); { Move to the end of the file } if CheckForError then  Exit; PrintFilePointer; with DataRec do begin FirstName := GetString(FieldCol, FirstRow + 3, Pred(SizeOf(FirstName))); if Interrupted then Exit; LastName := GetString(FieldCol, FirstRow + 4, Pred(SizeOf(LastName))); if Interrupted then Exit; Age := GetInteger(FieldCol, FirstRow + 5, 2, 1, 99); end; { with } if Interrupted then  Exit; Write(FileVar, DataRec); { Write the record to the file } if CheckForError then Exit; PrintFileSize;  PrintFilePointer; ClearFields; end; { AddRec } procedure FindRec(Direction : integer); { Move in a certain direction in the file by one record } var DataRec : RecordType; Target : integer; begin Target := FilePos(FileVar) + Direction; { Find target record } if (Target >= 0) and (Target < FileSize(FileVar)) then begin { Only seek to existing records } Seek(FileVar, Target); { Seek to target record } if CheckForError then Exit; Read(FileVar, DataRec); { Read in the record } if CheckForError then Exit; DisplayRec(DataRec); Seek(FileVar, Target); { Move back to target record, } PrintFilePointer; { since Read has moved past it } end else Beep; end; { FindRec } procedure SetupScreen; { Print prompts and messages on the screen } var RecordString, PointerString : AnyString; begin RecordString := 'The data file currently contains records.'; PointerString := 'The file pointer is currently at record .'; PrintXY(RecordString, VLow, 1, FirstRow); PrintXY(PointerString, VLow, 1, Succ(FirstRow)); PrintFileSize; PrintFilePointe> r; PrintCommandXY('A: ', 1, FirstRow + 3); Print('Add records', VLow); PrintCommandXY('B: ', 1, FirstRow + 4); Print('Forward one record', VLow); PrintCommandXY('C: ', 1, FirstRow + 5); Print('Backward one record', VLow); PrintCommandXY('ESCape', 1, FirstRow + 6); PrintXY('First Name:', VNorm, FieldCol - 12, FirstRow + 3); PrintXY('Last Name:', VNorm, FieldCol - 11, FirstRow + 4); PrintXY('Age:', VNorm, FieldCol - 5, FirstRow + 5); PrintXY('Choice: ', VNorm, 1, FirstRow + 8); end; { SetupScreen } procedure Menu; { Take commands from the user and execute them } var Command : char; begin SetupScreen; repeat GotoWinXY(9, FirstRow + 8); Command := UpCase(GetKey); case Command of 'A': AddRec;  'B': FindRec(1); 'C': FindRec(-1); end; { case } until FileError or Interrupted; { Take input until user wants to exit or an I/O error occurs } end; { Menu } procedure DeleteFile; { Delete the temporary data file } begin Close(FileVar); if CheckForError then Exit; Erase(FileVar); if CheckForError then; end; { DeleteFile } begin { RecFiles } FileError := False; SetupFile; Menu; DeleteFile; end; { RecFiles } {$I+} (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } RecFiles; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This procedure reads data from a text file that was previously created by the WritText program. As with WritText, the program forces the user to follow a fixed sequence of steps in order to read the file: 1) Assign Associates a name w/ a file variable. 2) Reset Opens a file, prepares to read the 1st byte. 3) Read (or Readln) Reads data from the file. 4) Close The file is now unavailable for reading. Reading and writing files requires a sequence of successfully executed steps; this drill is designed to help the user commit these steps to memory. } procedure ReadText; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) type States = (BeforeAssign, BeforeOpen, FileOpen, Finished); { Scalar representing ? different states } Operations = (AssignOp, ResetOp, ReadOp, ReadlnOp, CloseOp, ExitOp); { Scalar representing different operations } Result = record { The result from a combination of a state } NewState : States; { and an operation } ErrorNum : byte; end; StateDataType = array[BeforeAssign..FileOpen, Operations] of Result; const FileName = 'TEXT.DTA'; { Name of text file to use } { Typed constant holding state information } InitStateData : StateDataType = (((NewState : BeforeOpen; ErrorNum : 0), (NewState : BeforeAssign; ErrorNum : 1), (NewState : BeforeAssign; ErrorNum : 1), (NewState : BeforeAssign; ErrorNum : 1), (NewState : BeforeAssign; ErrorNum : 1), (NewState : Finished; ErrorNum : 4)), ((NewState : BeforeOpen; ErrorNum : 0), (NewState : FileOpen; ErrorNum : 0), (NewState : BeforeOpen; ErrorNum : 2), (NewState : BeforeOpen; ErrorNum : 2), (NewState : BeforeOpen; ErrorNum : 2), (NewState : Finished; ErrorNum : 4)), ((NewState : FileOpen; ErrorNum : 3), (NewState : FileOpen; ErrorNum : 0), (NewState : FileOpen; ErrorNum : 0), (NewState : FileOpen; ErrorNum : 0), (NewState : BeforeOpen; ErrorNum : 0),  (NewState : FileOpen; ErrorNum : 3))); var FileVar : text; { Declare a file variable of type text } State : States; { The current state of the system } Error : byte; { The current error number } StateData : StateDataType; { Keep track of errors } procedure SetupScreen; { Draws prompts on the screen } begin PrintCommandXY('A: ', 9, Succ(FirstRow)); Print('Assign', VLow); PrintCommandXY('B: ', 9, FirstRow + 2); Print('Reset', VLow); PrintCommandXY('C: ', 9, FirstRow + 3); Print('Read', VLow); PrintCommandXY('D: ', 9, FirstRow + 4); Print('Readln', VLow); PrintCommandXY('E: ', 9, FirstRow + 5); Print('Close', VLow); PrintCommandXY('ESCape', 9, FirstRow + 6); PrintXY('Choice:', VNorm, 1, FirstRow + 8);  end; {SetupScreen } function GetOp : Operations; { Reads in an operation from the keyboard } var Ch : char; begin GotoWinXY(9, FirstRow + 8); Ch := GetLegalKey(['A'..'E', ESC, IntChar]); { Accept only } case Ch of { legal chars } 'A': GetOp := AssignOp; { Convert characters to Operations } 'B': GetOp := ResetOp; 'C': GetOp := ReadOp; 'D': GetOp := ReadlnOp; 'E': GetOp := CloseOp; ESC, IntChar: GetOp := ExitOp; end; { case } end; { GetOp } procedure WriteMessage(Num : byte); { Writes a message on the screen } var ErrorString : AnyString; begin case Num of 0: ErrorString := ' The file operation was successful.'; 1: ErrorString := ' The file has not been assigned yet (use Assign).'; 2: ErrorString := ' The file needs to be opened first (use Reset).'; 3: ErrorString := ' The file needs to be closed first (use Close).'; 4: ErrorString := ''; 5: ErrorString := ' At End-of-File. Cannot read any more data.'; 6: ErrorString := ' At End-of-Line. Cannot read any more data.'; 7: ErrorString := 'The data file does not exist. Please run WRITTEXT.'; end; { case } if Num in [1..3, 5..7] then { An error occurred } Beep; ClearXY(30@ , FirstRow + 5); { Clear out old message } Delay(500); PrintXY(ErrorString, VNorm, 30, FirstRow + 5); { Write new message } end; { WriteMessage } procedure ReadFromFile(Op : Operations); { Allows the user to write text to a file } var Instr : string[30]; begin { ReadFromFile } if EOF(FileVar) then Error := 5 else begin if Op = ReadOp then begin  if Eoln(FileVar) then Error := 6 else Read(FileVar, Instr); end else Readln(FileVar, Instr); if Error = 0 then begin PrintXY('Last line read:', VNorm, 30, FirstRow + 3); PrintXY(Pad(Instr, 30), VLow, 46, FirstRow + 3); end; end; end; { ReadFromFile } procedure ExecuteOp(Op : Operations); { Executes a particular operation } begin with StateData[State, Op] do begin Error := Errornum; if Error = 0 then { If no error has occurred ... } begin case Op of AssignOp: Assign(FileVar, FileName); ResetOp: begin {$I-} Reset(FileVar); {$I+} if IOResult <> 0 then begin Error := 7; NewState := BeforeOpen; end; end; ReadOp, ReadlnOp: ReadFromFile(Op); CloseOp: Close(FileVar); end; { case } end; WriteMessage(Error); if (NewState = Finished) and (State = FileOpen) then Close(FileVar); { Close the file if exiting and it is open } State := NewState; end; { with } end; { ExecuteOp } begin { ReadText } State := BeforeAssign; StateData := InitStateData; { init StateData table } SetupScreen; repeat ExecuteOp(GetOp); until (State = Finished); end; { ReadText } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } ReadText; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This procedure creates output data to a Text file. The text file may then be used by the next example on the tutorial menu (READTEXT). This procedure forces the user to follow a fixed sequence of steps in order to write data to the file:  1) Assign Associates a name w/ a file variable. 2) Rewrite Opens a file, prepares to write the 1st byte. 3) Write (or Writeln) Writes data to the file. 4) Close Saves the file; it A is now unavailable for further writing. Reading and writing files requires a sequence of successfully executed steps; this drill is designed to help the user commit these steps to memory. } procedure WritText; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) type  States = (BeforeAssign, BeforeOpen, FileOpen, Finished); { Scalar representing different states } Operations = (AssignOp, ReWriteOp, WriteOp, WritelnOp, CloseOp, ExitOp); { Scalar representing different operations } Result = record { The result from a combination of a state } NewState : States; { and an operation } ErrorNum : byte; end; StateDataType = array[BeforeAssign..FileOpen, Operations] of Result; const FileName = 'TEXT.DTA'; { Name of text file to use } { Typed constant holding state information } InitStateData: StateDataType = (((NewState : BeforeOpen; ErrorNum : 0),  (NewState : BeforeAssign; ErrorNum : 1), (NewState : BeforeAssign; ErrorNum : 1), (NewState : BeforeAssign; ErrorNum : 1), (NewState : BeforeAssign; ErrorNum : 1), (NewState : Finished; ErrorNum : 4)), ((NewState : BeforeOpen; ErrorNum : 0), (NewState : FileOpen; ErrorNum : 0), (NewState : BeforeOpen; ErrorNum : 2), (NewState : BeforeOpen; ErrorNum : 2), (NewState : BeforeOpen; ErrorNum : 2), (NewState : Finished; ErrorNum : 4)), ((NewState : FileOpen; ErrorNum : 3), (NewState : FileOpen; ErrorNum : 0), (NewState : FileOpen; ErrorNum : 0),  (NewState : FileOpen; ErrorNum : 0), (NewState : BeforeOpen; ErrorNum : 0), (NewState : FileOpen; ErrorNum : 3))); var FileVar : text; { Declare a file variable of type text } State : States; { The current state of the system } StateData : StateDataType; { Keep track of operations } FileWasOpen : boolean; { True if the file was ever open } procedure SetupScreen; { Draws prompts on the screen } begin PrintCommandXY('A: ', 9, Succ(FirstRow)); Print('Assign', VLow); PrintCommandXY('B: ', 9, FirstRow + 2); Print('Rewrite', VLow); PrintCommandXY('C: ', 9, FirstRow + 3); Print('Write', VLow); PrintCommandXY('D: ', 9, FirstRow + 4); Print('Writeln', VLow); PrintCommandXY('E: ', 9, FirstRow + 5); Print('Close', VLow); PrintCommandXY('ESCape', 9, FirstRow + 6); PrintXY('Choice:', VNorm, 1, FirstRow + 8); end; {SetupScreen } function GetOp : Operations; { Reads in an operation from the keyboard } var Ch : char; begin GotoWinXY(9, FirstRow + 8); Ch := GetLegalKey(['A'..'E', ESC, IntChar]); { Accept only } case Ch of { legal chars } 'A': GetOp := AssignOp; { Convert characters to Operations } 'B': GetOp := RewriteOp; 'C': GetOp := WriteOp; 'D': GetOp := WritelnOp;  'E': GetOp := CloseOp; ESC, IntChar: GetOp := ExitOp; end; { case } end; { GetOp } procedure WriteMessage(Num : byte); { Writes a message on the screen } var ErrorString : AnyString; begin case Num of 0: ErrorString := ' B  The file operation was successful.'; 1: ErrorString := ' The file has not been assigned yet (use Assign).'; 2: ErrorString := ' The file needs to be opened first (use Rewrite).'; 3: ErrorString := ' The file needs to be closed first (use Close). '; 4: ErrorString := ''; end; { case } if Num in [1..3] then { An error occurred } Beep; ClearXY(30, FirstRow + 5); { Clear out old message } Delay(500); PrintXY(ErrorString, VNorm, 30, FirstRow + 5); { Print new message } end; { WriteMessage } procedure WriteToFile(Op : Operations); { Allows the user to write text to a file } var Outstr : AnyString; begin PrintXY('Text to write:', VNorm, 30, FirstRow + 3); { Write user prompt } Outstr := GetString(45, FirstRow + 3, 30); { Read in text to write } if Op = WriteOp then Write(FileVar, Outstr) else Writeln(FileVar, Outstr); ClearXY(30, FirstRow + 3); { Erase prompt } end; { WriteToFile } procedure ExecuteOp(Op : Operations); { Executes a particular operation } begin with StateData[State, Op] do begin WriteMessage(ErrorNum); if ErrorNum = 0 then { If no error has occurred ... } begin case Op of AssignOp: Assign(FileVar, FileName); RewriteOp: begin Rewrite(FileVar); FileWasOpen := true; end; WriteOp, WritelnOp: WriteToFile(Op); CloseOp: Close(FileVar); end; { case } end; if (NewState = Finished) and (State = FileOpen) then Close(FileVar); { Close the file if exiting and it is open } State := NewState; end; { with } end; { ExecuteOp } begin { WritText } FileWasOpen := false; State := BeforeAssign; StateData := InitStateData; { init StateData table } SetupScreen; repeat ExecuteOp(GetOp); until(State = Finished); if FileWasOpen then Message('Now run READTEXT to see what you have written.'); end; { WritText } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } WritText; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) { This example demonstrates the use of pointers by building a stack of simple records. Each record contains an integer and a backward link (a pointer to a previously "pushed" record). A stack is a LIFO (Last-In-First-Out) structure; the last element added must be the first to be removed. This example follows closely the model described in Chapter 20 of the Turbo Tutor manual. Study the behavior of this procedure in order to understand how a stack works; study the source code to leaC rn how to implement a stack using pointers. } procedure Stack; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is SUPPOSED to generate a compiler error! Please see  the instructions at the bottom of this file. } (**) type NodePtr = ^Node; Node = record Data : integer;  Last : NodePtr; { Pointer to the previous node on the stack } end; const MaxElements = 9; { The maximum number of elements in the stack } var StackTop : NodePtr; { Pointer to the top of the stack } Elements : byte; { The number of elements in the stack } Ch : char; { Character read in as a command } procedure PrintStack; { Prints the stack on the screen } var Temp : NodePtr; Line : byte; begin Temp := StackTop; Line := FirstRow + MaxElements - Elements; while Temp <> nil do { Temp moves through the stack from top to bottom } begin PrintXY(Pad(IntToString(Temp^.Data, 2), 14), VNorm, 1, Line); Line := Succ(Line); Temp := Temp^.Last; end; if Elements > 0 then { Print location of StackTop } begin PrintXY('<', VLow, 4, FirstRow + MaxElements - Elements); Print(' StackTop', VNorm); end; end; procedure Push; { Pushes a new node onto the stack } var NewNode : NodePtr; Number : integer; begin if Elements = MaxElements then begin Beep; Message('The stack is full. You cannot push any more numbers onto it.'); end else begin  PrintXY('Number to push onto stack: ', VNorm, 20, FirstRow + 7); Number := GetInteger(WhereX, WhereY, 2, -9, 99); ClearXY(20, FirstRow + 7); { erase old message } if Interrupted then Exit; New(NewNode); { Allocate space on heap for new node } NewNode^.Data := Number; { Put data into new node } NewNode^.Last := StackTop; { Connect new node to top of stack } StackTop := NewNode; { Set StackTop to new node } Elements := Succ(Elements); PrintStack; Message(IntToString(Number, 1) + ' was pushed onto the stack.'); end; end; { Push } procedure Pop; { Pops the top element off of the stack } var Temp : NodePtr; Number : integer; begin if Elements = 0 then begin Beep; Message('The stack is empty. You cannot pop any more numbers off of it.'); end else begin Number := StackTop^.Data; { Save value of number popped } Temp := StackTop; { Temp saves the location of StackTop } StackTop := StackTop^.Last; { Move StackTop down one node } Dispose(Temp); { Dispose of node } Elements := Pred(Elements); PrintXY(Pad('', 14), VLow, 1, Pred(FirstRow + MaxElements - Elements)); PrintStack; Message(IntToString(Number, 1) + ' was popped off of the stack.'); end; end; { Pop } procedure ClearStack; { Pops all of the elements from the stack } var Counter : byte; begin for Counter := 1 to Elements do Pop; end; { ClearStack } begin { Stack } StackTop := nil; Elements := 0; PrintCommandXY('A: ', 20, FirstRow + 3); Print('Push a number onto the stack', VLow); PrintCommandXY('B: ', 20, FirstRow + 4); Print('Pop a number off of the stack', VLow); PrintCommandXY('ESCape', 20, FirstRow + 5); repeat GotoWinXY(20D , FirstRow + 6); Ch := UpCase(GetKey); Message(''); case Ch of 'A': Push; 'B': Pop; end; { case } until Interrupted; ClearStack; end; { Stack } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment:  begin { program body } InitExample; { get ready to run example } Stack; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **)  { This example adds and deletes nodes in a binary tree, a tree in which each node has at most two descendants. Because the steps to be taken when traversing the tree are identical at every node, this is an ideal application for recursive procedures. The two main procedures that manipulate the tree, DeleteFromTree and AddToTree, call THEMSELVES as they "explore" the tree, searching for the proper place to add or delete a node. Refer to Chapter 21 of the Turbo Tutor manual for more information on binary trees. Note that nodes with a depth greater than MaxLevel are added to the tree but are not displayed.  } procedure Recur; (**) type Dummy = DummyType; { TRYING TO COMPILE THIS PROGRAM? This statement is  SUPPOSED to generate a compiler error! Please see the instructions at the bottom of this file. } (**) type NodePtr = ^NodeType; NodeType = record Value : char; { Character value assigned to a node }  Parent : NodePtr; { The parent of the node } Left, Right : NodePtr; { The children of the node } end; const MaxLevel = 5; { Maximum level of the tree } var Root : NodePtr; { Pointer to the root of the tree } Ch : char; { Character read in as a command } NodeChr : char; { Character being added or deleted } TotalNodes : integer; { The total number of nodes in the tree } procedure PrintTree; { Prints the nodes of the tree on the screen } procedure PrintNode(Node : NodePtr; Lvl, Col, Spc : byte; NilNodes : boolean); { Prints an individual node } begin if Lvl > MaxLevel then Exit;  if (Node = nil) or (NilNodes) then begin PrintXY(' ', VNorm, Col, FirstRow + (Pred(Lvl) * 2)); NilNodes := True; { All of the nodes below this one will be nil } end else PrintXY(Node^.Value, VNorm, Col, FirstRow + (Pred(Lvl) * 2)); { Print out the value of the current node } PrintNode(Node^.Left, Succ(Lvl), Col - Spc, Spc div 2, NilNodE es); { Print the values of the children to the left of the current node } PrintNode(Node^.Right, Succ(Lvl), Col + Spc, Spc div 2, NilNodes); { Print the values of the children to the right of the current node } end; { PrintNode of PrintTree }  begin { PrintTree } PrintNode(Root, 1, 32, 16, False); PrintXY(IntToString(TotalNodes, 5), VNorm, 14, FirstRow); end; { PrintTree } procedure AddNode; { Adds a new node to the tree } procedure AddToTree(var Node : NodePtr; PNode : NodePtr; Level : byte); { This is the procedure which will recursively add a node to the tree } begin if Node = nil then { The new node is empty } begin New(Node); Node^.Value := NodeChr; Node^.Left := nil; Node^.Right := nil; Node^.Parent := PNode; TotalNodes := Succ(TotalNodes); PrintTree; end else if NodeChr <= Node^.Value then { The new node is occupied - } AddToTree(Node^.Left, Node, Succ(Level)) { search left child } else { The new node is occupied - } AddToTree(Node^.Right, Node, Succ(Level)); { search right child } end; { AddToTree of AddNode } begin { AddNode } Message('Type in the characters to add. Press the space bar to stop adding characters.'); repeat repeat NodeChr := GetKey; if Interrupted then Exit; until NodeChr in [' '..'~']; if NodeChr <> ' ' then AddToTree(Root, nil, 1); { Start tree traverse at root } until NodeChr = ' '; Message(''); end; { AddNode } function LeftNode(Node : NodePtr) : boolean; { Determines if a node is the left or right child of its parent }  begin LeftNode := (Node^.Parent^.Left = Node) or (Node = nil); end; { LeftNode } procedure RemoveNode(Node : NodePtr); { Deletes the node and fixes the tree } var Temp : NodePtr; { Temporary pointer } procedure LeftAndRightNil; { The left and right children are both nil } begin if Node <> Root then begin if LeftNode(Node) then Node^.Parent^.Left := Nil else Node^.Parent^.Right := Nil end; end; { LeftAndRightNil of RemoveNode } procedure LeftNil; { Only the left child is nil } begin Node^.Right^.Parent := Node^.Parent; if Node <> Root then begin if LeftNode(Node) then Node^.Parent^.Left := Node^.Right else Node^.Parent^.Right := Node^.Right; end; end; { LeftNil of RemoveNode } procedure RightNil; { Only the right child is nil } begin Node^.Left^.Parent := Node^.Parent; if Node <> Root then begin if LeftNode(Node) then Node^.Parent^.Left := Node^.Left else Node^.Parent^.Right := Node^.Left; end; end; { RightNil of RemoveNode } procedure NoneNil; { Neither the left nor the right child is nil } begin  Temp := Node^.Left; while Temp^.Right <> nil do Temp := Temp^.Right; Node^.Right^.Parent := Temp; Temp^.Right := Node^.Right; Node^.Left^.Parent := Node^.Parent; if Node^.Parent <> nil then if LeftNode(Node) then Node^.Parent^.Left := Node^.Left else Node^.Parent^.Right := Node^.Left; end; { NoneNil of RemoveNode } begin if Node^.Left = nil then if Node^.Right = nil then LeftAndRightNil else LeftNil else if Node^.Right = nil thenF  RightNil else NoneNil; if (Node = Root) then { Handle special case where Root has been deleted } begin if Node^.Left <> nil then Root := Node^.Left else if Node^.Right <> nil then Root := Node^.Right else  Root := nil; end; Dispose(Node); TotalNodes := Pred(TotalNodes); PrintTree; end; { RemoveNode } procedure DeleteFromTree(var Node : NodePtr); { Recursively deletes a node from the tree } begin if Node = nil then Message('The character ' + #39 + NodeChr + #39 + ' is not in the tree.') else if NodeChr = Node^.Value then RemoveNode(Node) else if NodeChr < Node^.Value then { Search left child } DeleteFromTree(Node^.Left) else { Search right child } DeleteFromTree(Node^.Right); end; { DeleteFromTree } procedure DeleteNode; { Disposes of a node of the tree } begin PrintXY('Enter the character to delete: ', VNorm, 1, FirstRow + 9); repeat NodeChr := GetKey; { Don't allow a space as input } until NodeChr in [Succ(' ')..'~']; Message(''); if Interrupted then Exit; DeleteFromTree(Root); { Start tree traverse at root } end; { DeleteNode } procedure InitTree; { Prints out the blank tree } var Counter : byte; begin PrintXY('Total Nodes:', VLow, 1, FirstRow); PrintXY('/ \', VLow, 24, Succ(FirstRow)); for Counter := 0 to 1 do PrintXY('/ \', VLow, Counter * 32 + 12, FirstRow + 3); for Counter := 0 to 3 do PrintXY('/ \', VLow, Counter * 16 + 6, FirstRow + 5); for Counter := 0 to 7 do PrintXY('/ \', VLow, Counter * 8 + 3, FirstRow + 7); Root := nil; { Initialize root } TotalNodes := 0; end; { InitTree } procedure DeleteTree; { Deletes all of the nodes of the tree, which frees up the memory that the tree used } begin Message('Deleting the tree...'); while Root <> nil do { Continue to delete Root until the tree is empty } begin NodeChr := Root^.Value; DeleteFromTree(Root); end; Message(''); end; { DeleteTree } begin { Recur } InitTree; PrintTree; PrintCommandXY('A: ', 57, FirstRow); Print('Add node to tree', VLow); PrintCommandXY('B: ', 57, Succ(FirstRow)); Print('Delete node from tree', VLow); PrintCommandXY('ESCape', 57, FirstRow + 2); repeat GotoWinXY(57, FirstRow + 3); Ch := UpCase(GetKey); Message(''); case Ch of 'A': AddNode; 'B': DeleteNode; end; { case } until Interrupted; DeleteTree; end; { Recur } (** TRYING TO RUN THIS PROGRAM? This program is an INCLUDE file that is used by the MAIN program, TUTOR.PAS. To run this program, copy the following 4 lines to the line above this comment: begin { program body } InitExample; { get ready to run example } Recur; { execute the procedure } end. { end of the program } Next, copy the following 2 lines to the beginning of this file, then re-compile this program: {$C-} { turn off Ctrl-C checking } {$I TUTOR.LIB} { include TUTOR's source library } For more information, please refer to Chapter 1 of the Turbo Pascal Tutor. **) G H I J K L