Top Banner
Μάθετε την Pascal Μάθετε την Pascal on-line Αυτές οι σημειώσεις παρουσιάζουν σχεδόν όλες τις δυνατότητες της γλώσσας προγραμματισμού Pascal. Οργανώνονται σε 16 κεφάλαια τα οποία θα πρέπει να μελετηθούν με τη σειρά που παρουσιάζονται. Τα δυο τελευταία κεφάλαια αναφέρονται σε θέματα αντικειμενοστραφούς προγραμματισμού. Οι φοιτητές θα βοηθηθούν ιδιαίτερα αν “κατεβάσουν” (download) στον δικό τους ΗΥ τον πηγαίο κώδικα των παραδειγμάτων αυτών των σημειώσεων και στη συνέχεια να τα μεταγλωττίσουν και α τα εκτελέσουν. Πως να ξεκινήσετε ; “Κατεβάστε” στο δικό σας ΗΥ τον πηγαίο κώδικα των παραδειγμάτων. Διαβάστε κάθε κεφάλαιο με τη σειρά που δίνεται. Ταυτόχρονα με τη μελέτη των παραδειγμάτων προγραμμάτων μεταφράστε τα προγράμματα και στη συνέχεια εκτελέστε τα με τη βοήθεια του compiler Turbo Pascal 5.5 ή 6.0. Download τις σημειώσεις σε HTML μορφή (pashtm.zip). Το pashtm.zip περιλαμβάνει σε συμπυκνωμένη μορφή όλα τα κείμενα. Το αρχείο αυτό (128k) περιέχει όλα τα κεφάλαια των σημειώσεων τα οποία μπορούν να αποσυμπιεστούν και να μελετηθούν τοπικά. Download τον πηγαίο κώδικα (passrc.zip). Το αρχείο αυτό περιέχει 97 αρχεία πηγαίου κώδικα (περίπου 110k) τα οποία εξηγούνται στα 16 κεφάλαια των σημειώσεων αυτών. Download τις απαντήσεις των ασκήσεων (pasans.zip) Το αρχείο αυτό περιέχει τις απαντήσεις όλων των προτεινόμενων ασκήσεων, είναι περίπου 16k και περιλαμβάνει 23 αρχεία πηγαίου κώδικα. file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/periexomena.htm (1 of 3) [28/03/2012 17:51:30]
233
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Pascal

Pascal

on-line Pascal. 16 . . (download) . ; .

. compiler Turbo Pascal 5.5 6.0.

Download HTML (pashtm.zip). pashtm.zip . (128k) .

Download (passrc.zip). 97 ( 110k) 16 .

Download (pasans.zip) , 16k 23 .file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/periexomena.htm (1 of 3) [28/03/2012 17:51:30]

Pascal

1 ---- ; 2 ---- PASCAL 3 ---- 4 ---

5 ---- 6 ---- , , 7 ---- 8 ---- , 9 ---- 10 -- / 11 - 12 - 13 - Turbo Pascal

14 -- 15 - 16 -

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/periexomena.htm (2 of 3) [28/03/2012 17:51:30]

Pascal

UpCopyright [. ] : 11, 1999

Next

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/periexomena.htm (3 of 3) [28/03/2012 17:51:30]

PASCAL Pascal, Pascal. Pascal, . . . Pascal. , Pascal. 12 . ' . ' , . Pascal, . PASCAL 16 , . Pascal , , . Pascal, , project . - . , SORT, SORT Sort1,Sort2 ... , , . ' , , . , Puppy_Dog. , Compiler Pascal . Pascal, "" file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/eisagogi.htm (1 of 4) [28/03/2012 17:51:31]

. Pascal. , standard . , . , . , . COMPILER ;

. (interpreter). "" , . . (compiler) , ( ). , , . Borland's International TURBO Pascal compilers 5.0 6.0. compilers , . Pascal Compilers. Borland . , , compilers "" . Borland. , Pascal. Pascal, . . TURBO Pascal ; . 5.5 6.0. . Pascal file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/eisagogi.htm (2 of 4) [28/03/2012 17:51:31]

, compiler . , . 5.5 6.0 14 15 Turbo Pascal 5.5 6.0, Borland. , ' . 13 . Turbo Pascal , editor Pascal . Pascal . Editor . Turbo Pascal Pascal. , Turbo Pascal, . standard compilers. , (data) . 13, (units), Turbo Pascal compilers Pascal. ; . . , Pascal. , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/eisagogi.htm (3 of 4) [28/03/2012 17:51:31]

. Pascal. . , , . Pascal, Pascal. Pascal .

[Up] [1]

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/eisagogi.htm (4 of 4) [28/03/2012 17:51:31]

1

1 ;

, . , , Pascal. ; (computer) , , . , . , . . . . , . , , , . , . , () . . ; . . , , . =3.141592 file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter1.htm (1 of 3) [28/03/2012 17:51:32]

1

, . ; , , . , . . 2 , 3 6 . . ; . , "eggs", 2 6 . , . Pascal ; . , , , , , . . Pascal , . Pascal . , , " " Pascal . "" . , . , . Pascal , . , .

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter1.htm (2 of 3) [28/03/2012 17:51:32]

1

[][Up][2]

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter1.htm (3 of 3) [28/03/2012 17:51:32]

2

2 PASCAL

Pascal , Pascal. Turbo Pascal, 01_2.PAS , . .

AG00050_. ..... EX01_2.PAS gif (1615 bytes) Pascal, . Standard Pascal , , (indentifier) . , compiler. Program compiler Pascal . . Pascal (statements) , . . Turbo Pascal program, Standard Pascal, . , Standard Pascal, . ; , , , . ( , , ). Pascal (.. compiler ) file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (1 of 9) [28/03/2012 17:51:34]

2

8 , 8. 8 . Turbo Pascal 63 . Standard Pascal Pascal . Turbo Pascal Compilers , . "Puppy_Dog" . , 2 compilers Pascal. . 3 4 Pascal, . Pascal. begin end . Pascal begin end. , . begin end, loop, (subroutines- procedures Pascal), . , begin end Pascal ' . begin end. , : end. compiler . Pascal . Pascal . 6 10 . . . +R +F5 . . . 02_2.PAS .

AG00050_. ..... EX02_2.PAS giffile:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (2 of 9) [28/03/2012 17:51:34]

2

Kitty_cat. begin end bytes) . , begin end. Writeln . (modifier), , , PC . , , . . Writeln , . , Turbo Pascal . , , , . , . . . . 4. o compiler Pascal , . , 5, 4. . . . . 02_2.PAS . 03_2.PAS.

(1615

AG00050_. ..... EX03_2.PAS gif (1615 bytes) , write. write file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (3 of 9) [28/03/2012 17:51:34]

2

writeln, . writeln , write . . , . . editor 03_2.PAS write writeln. . 04_2.PAS .

AG00050_. ..... EX04_2.PAS gif (1615 Pascal (* *) bytes)

{ }. * . . , 11 12 "send money", Pascal . , "send money". . compilers (* } { *), . ANSI Pascal Turbo Pascal . Turbo Pascal , . . (* *) , { } Turbo Pascal , . . , format Pascal . 04_2.PAS . . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (4 of 9) [28/03/2012 17:51:34]

2

, . 17 23 . - . , browser, . , . , , . 05_2.PAS .

AG00050_. ..... EX05_2.PAS gif (1615 Pascal bytes) carriage return (Enter)

, .. Pascal . , . . 06_2.PAS .

AG00050_. ..... EX06_2.PAS gif (1615 bytes) . Pascal ' . , .

06_2.PAS Pascal . , , . Enter . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (5 of 9) [28/03/2012 17:51:34]

2

. . Pascal. . , , . 06_2.PAS. 1. . 2. , , , write writeln .

[1][Up][3]

2 (* 1 - 1 EX01_2*) 1 program Puppy_Dog; 2 3 begin 4 end. 5 6 { Result of execution 7 8 (There is no output from this program ) 9 10 } (* 2 - 2 EX02_2.pas *) 1 program Kitty_Cat; 2 3 begin 4 Writeln('This program'); 5 Writeln('actually does something.'); 6 end. 7 8 { Result of executionfile:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (6 of 9) [28/03/2012 17:51:34]

2

9 10 This program 11 actually does something. 12 13 14 } (* 2 - 3 EX03_2.pas *) 1 program Guppy_The_Fish; 2 3 begin 4 Write('This will '); 5 Write('all be '); 6 Writeln('on one line.'); 7 end. 8 9 10 { Result of execution 11 12 This will all be on one line. 13 14 } (* 2 - 4 EX04_2.pas *) 1 program Lots_Of_Comments; 2 3 begin { This is the start of the main program } 4 5 (* This is a comment that is ignored by the Pascal compiler *) 6 { This is also ignored } 7 8 Writeln('I am in Pascal school, Dad'); (* Comment *) 9 Writeln('All students are always broke'); {Comment} 10 (* 11 Writeln('Send money'); 12 Writeln('Send money'); 13 *) 14 Writeln('I am really getting hungry'); 15 end. (* This is the end of the main program *) 16 17 { Result of execution 18 19 I am in Pascal school, Dad 20 All students are always broke 21 I am really getting hungry 22 23 }file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (7 of 9) [28/03/2012 17:51:34]

2

(* 2 - 5 EX05_2.pas *) 1 program Good_Programming_Style; 2 3 begin 4 5 Write('Programming style '); 6 Write ('is a matter of '); 7 Writeln ('personal choice'); 8 9 Write('Each person '); 10 Write ('can choose '); 11 Writeln ('his own style'); 12 13 Write('He can be '); 14 Write ('very clear, or '); 15 Writeln ('extremely messy'); 16 end. 17 18 19 { Result of execution 20 21 Programming style is a matter of personal choice 22 Each person can choose his own style 23 He can be very clear, or extremely messy 24 25 } { Result of execution I am in Pascal school, Dad All students are always broke I am really getting hungry } (* 2 - 6 EX06_2.pas *) program Ugly_Programming_Style;begin Write('Programming style '); Write ('is a matter of '); Writeln('personal choice');Write('Each person '); Write('can choose ');Writeln ('his own style');Write('He can be ');Write ('very clear, or '); Writeln('extremely messy');end.

1 2 3 4 5 6 7 8 9 10 { Result of execution

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (8 of 9) [28/03/2012 17:51:34]

2

11 12 13 14 15 16

Programming style is a matter of personal choice Each person can choose his own style He can be very clear, or extremely messy }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter2.htm (9 of 9) [28/03/2012 17:51:34]

3

3

; Pascal, , ' , . Turbo Pascal 8 , . 8 , . 8 . integer byte real boolean char shortint word longint -32768 32767 0 255 1-38 1+38 TRUE FALSE ASCII -128 127 0 65535 2147483648 2147483647

4 ' (char, shortint, word longint) Standard Pascal compiler Turbo Pascal. Turbo Pascal 5.0 :

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter3.htm (1 of 15) [28/03/2012 17:51:37]

3

single double extended comp

7 15 19 -1018 1018

Turbo Pascal 5.0 4 80x87 . Turbo Pascal , . , , . compiler (Reference Manual). . . integer , integer . EX01_3.PAS Turbo Pascal .

AG00050_. ..... EX01_3.PAS gif (1615 , bytes) var.

. Pascal " ". compiler , , . , . (.. ) . var, Count, X Y. Var , compiler file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter3.htm (2 of 15) [28/03/2012 17:51:37]

3

. var . . - (:) , integer (standard identifier), . , , . , . 3 integer, , . , compiler , . . 3 X, Count. Count + , = . :=, " ...", . , , "". , :=+1 , " + 1". Pascal. 12, 13 Count 12+13 25. . , . writeln (,). . . , , . , . EX01_3.PAS. , EX02_3.PAS . writeln write writeln. writeln , write . 2 .

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter3.htm (3 of 15) [28/03/2012 17:51:37]

3

AG00050_. ..... EX02_3.PAS gif (1615 bytes) EX03_3.PAS 5 .

AG00050_. ..... EX03_3.PAS gif (1615 . bytes) write

Turbo Pascal. , write. . . Pascal . . . , integer . integer real . real var real . EX08_3.PAS ' .

AG00050_. ..... EX04_3.PAS gif (1615 , bytes) , ,

. Pascal . EX04_3. PAS real EX05_3.PAS integer . , . . Turbo Pascal.

AG00050_. ..... EX05_3.PAS gif (1615 EX05_3.PAS Pascal bytes) Integer. byte integer . byte file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter3.htm (4 of 15) [28/03/2012 17:51:37]

3

byte, integer 2 byte . Boolean boolean, TRUE FALSE. loop, EndOFFile TRUE FALSE . boolean . : = > < >=

0 then Print_And_Decrement(Index); end; begin (* main program *) Count := 7; Print_And_Decrement(Count); end. (* main program *) { Result of execution

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter5.htm (16 of 20) [28/03/2012 17:51:45]

5

21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

The The The The The The The }

value value value value value value value

of of of of of of of

the the the the the the the

index index index index index index index

is is is is is is is

7 6 5 4 3 2 1

(* 5 - 8 EX08_5.pas*) program Forward_Reference_Example; var Number_Of_Times : integer; procedure Write_A_Line(var Count : integer); forward; procedure Decrement(var Index : integer); begin Index := Index - 1; if Index > 0 then Write_A_Line(Index); end; procedure Write_A_Line; begin Writeln('The value of the count is now ',Count:4); Decrement(Count); end; begin (* main program *) Number_Of_Times := 7; Decrement(Number_Of_Times); Writeln; Number_Of_Times := 7; Write_A_Line(Number_Of_Times); end. (* of main program *) { Result of execution The The The The The The value value value value value value of of of of of of the the the the the the count count count count count count is is is is is is now now now now now now 6 5 4 3 2 1

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter5.htm (17 of 20) [28/03/2012 17:51:45]

5

37 38 39 40 41 42 43 44 45 46 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

The The The The The The The }

value value value value value value value

of of of of of of of

the the the the the the the

count count count count count count count

is is is is is is is

now now now now now now now

7 6 5 4 3 2 1

(* 5 - 9 EX09_5.pas*) program Procedure_Type_Example; {$F+} (* This forces far calls and is required by TURBO *) (* Pascal to use a procedure type. *) type Procedure_Type = procedure(In1, In2, In3 : integer; var Result : integer); var Number1, Number2, Number3 : integer; Final_Result : integer; Do_Math : Procedure_Type; procedure Add(In1, In2, In3 : integer; var Result : integer); begin Result := In1 + In2 + In3; Writeln('The sum of the numbers is ',Result:6); end; procedure Mult(In1, In2, In3 : integer; var Result : integer); begin Result := In1 * In2 * In3; Writeln('The product of the numbers is',Result:6); end; procedure Average(In1, In2, In3 : integer; var Result : integer); begin Result := (In1 * In2 * In3) div 3; Writeln('The Average of the numbers is',Result:6); end; begin

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter5.htm (18 of 20) [28/03/2012 17:51:45]

5

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Number1 := 10; Number2 := 15; Number3 := 20; Do_Math := Add; Do_Math(Number1, Number2, Number3, Final_Result); Do_Math := Mult; Do_Math(Number1, Number2, Number3, Final_Result); Do_Math := Average; Do_Math(Number1, Number2, Number3, Final_Result); end. { Result of execution The sum of the numbers is 45 The product of the numbers is 3000 The average of the numbers is 1000 } (* 5 - 10 EX10_5.pas*) program Function_Type_Example; {$F+} (* This forces far calls and is required by TURBO *) (* Pascal to use a function type. *) type Function_Type = function(In1, In2, In3 : integer) : integer; var Number1, Number2, Number3 : integer; Final_Result : integer; Do_Math : Function_Type; function Add(In1, In2, In3 : integer) : integer; var Temp : integer; begin Temp := In1 + In2 + In3; Writeln('The sum of the numbers is ',Temp:6); Add := Temp; end; function Mult(In1, In2, In3 : integer) : integer; var Temp : integer; begin

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter5.htm (19 of 20) [28/03/2012 17:51:45]

5

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

Temp := In1 * In2 * In3; Writeln('The product of the numbers is',Temp:6); Mult := Temp; end; function Average(In1, In2, In3 : integer) : integer; var Temp : integer; begin Temp := (In1 * In2 * In3) div 3; Writeln('The Average of the numbers is',Temp:6); Average := Temp; end; begin Number1 := 10; Number2 := 15; Number3 := 20; Do_Math := Add; Final_Result := Do_Math(Number1, Number2, Number3); Do_Math := Mult; Final_Result := Do_Math(Number1, Number2, Number3); Do_Math := Average; Final_Result := Do_Math(Number1, Number2, Number3); end. { Result of execution The sum of the numbers is 45 The product of the numbers is 3000 The average of the numbers is 1000 }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter5.htm (20 of 20) [28/03/2012 17:51:45]

6

6 , ,

, . , . Pascal , 2 , . . EX01_6.PAS 5 Automobiles. integer, 12 Automobiles [1], Automobiles[2], Automobiles[3],..., Automobiles[12].

AG00050_. .....EX01_6.PAS gif (1615 Pascal bytes) . 5

, : array, of . , . , . , , ( ) . . Index 1 12, Automobiles, 12 11 22. , . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (1 of 11) [28/03/2012 17:51:47]

6

1 12, 12 -32768 32767. , , . Automobiles 12 integer . . , EX02_6.PAS .

AG00050_. .....EX02_6.PAS gif (1615 Checkerboard 8 , bytes) ,

8 , integer. , Checkerboard 64 , integer. 8 x 8 . , Value 64 . , 64 . , , 1 8. . Checkerboard . , . Checkerboard Value 12 . , 128 , 64 Checkerboard 64 Value, . , , Write. 64 Checkerboard Index Count . . Checkerboard Value (file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (2 of 11) [28/03/2012 17:51:47]

6

Checkerboard ). Value, . 24 26 3 , . 26, Value[3,6] ( 3), . Integer 1 8, . 64 Value . , 3 . . , 8 x 8, . 1 8 101 108 . , . ! , EX03_6.PAS.

AG00050_. .....EX03_6.PAS. gif (1615 , type. bytes)

" " (user-defined types). (predifined) , , . 6 ( Array_Def Boat) type , integer, byte, real ... Pascal , . compiler Pascal , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (3 of 11) [28/03/2012 17:51:47]

6

. . Airplane Dog_Food Dog_Food boolean, Airplane , boolean. var boolean . Puppies, 72 (6 x 12) boolean. Stuff 14 , integer . , Stuff[12], Stuff[13], ..., Stuff[25]. Stuff2 14 . Kitties Puppies. . , . . ; , ' compiler Pascal . Modula2 Ada, . , , . . EX04_6.PAS .

AG00050_. .....EX04_6.PAS gif (1615 const bytes)

. , Max_size 12. . . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (4 of 11) [28/03/2012 17:51:47]

6

, , 1 12 Max_Size 12. , 5 , 1 12 ( integer char). 12 , Max_Size . , , , 12 18. , , . 12 18. , 2000 , 12 18. . , , . . . Turbo Pascal , , " " (typed constant). , Index_Start integer 49. . Index_Start 49. Check_It_Out TRUE, . , , . . ' , , . EX05_6.PAS .

AG00050_. .....EX05_6.PAS gif (1615 Pascal, 0 9999 bytes) file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (5 of 11) [28/03/2012 17:51:47]

6

. . goto . . Turbo Pascal . , , 0 9999. EX05_6. PAS. . Pascal 1971, , ..60 bits . . Pascal . "" . . , , 16 bits, . compilers . Turbo Pascal . Turbo Pascal Standard Pascal, Niclaus Wirth, . label, const, type, var . , . Pascal . Turbo Pascal Standard Pascal. , Pascal. type , . Turbo Pascal . 1. 201 212 file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (6 of 11) [28/03/2012 17:51:47]

6

, . 2. ' 10 x 10, , . . 3. 2 , , .

[5][Up][7]

6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 (* 6 - 1 EX01_6.pas*) program Simple_Arrays; var Count,Index : integer; Automobiles : array[1..12] of integer; begin for Index := 1 to 12 do Automobiles[Index] := Index + 10; Writeln('This is the first program with an array'); Writeln; for Index := 1 to 12 do Writeln('automobile number',Index:3,' has the value', Automobiles[Index]:4); Writeln; Writeln('End of program'); end. { Result of execution This is the first program with an array automobile automobile automobile automobile automobile automobile automobile automobile automobile number number number number number number number number number 1 2 3 4 5 6 7 8 9 has has has has has has has has has the the the the the the the the the value value value value value value value value value 11 12 13 14 15 16 17 18 19

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (7 of 11) [28/03/2012 17:51:47]

6

33 34 35 36 37 38 39 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

automobile number 10 has the value 20 automobile number 11 has the value 21 automobile number 12 has the value 22 End of program } (* 6 - 2 EX02_6.pas*) program Multiple_Arrays; var Index,Count : integer; Checkerboard : array[1..8] of array[1..8] of integer; Value : array[1..8,1..8] of integer; begin (* Main program *) for Index := 1 to 8 do begin (* index loop *) for Count := 1 to 8 do begin Checkerboard[Index,Count] := Index + 3*Count; Value[Index,Count] := Index + 2*Checkerboard[Index,Count]; end; end; (* of index loop *) Writeln(' Output of checkerboard'); Writeln; for Index := 1 to 8 do begin for Count := 1 to 8 do Write(Checkerboard[Index,Count]:7); Writeln; end; Value[3,5] := -1; (* change some of the value matrix *) Value[3,6] := 3; Value[Value[3,6],7] := 2; (* This is the same as writing Value[3,7] := 2; *) for Count := 1 to 3 do Writeln; (* Three blank lines *) Writeln('Output of value'); Writeln; for Count := 1 to 8 do begin for Index := 1 to 8 do Write(Value[Count,Index]:7); Writeln; end; end. (* of main program *)

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (8 of 11) [28/03/2012 17:51:47]

6

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

{ Result of execution Output of checkerboard 4 7 10 13 16 19 22 25 5 8 11 14 17 20 23 26 6 9 12 15 18 21 24 27 7 10 13 16 19 22 25 28 8 11 14 17 20 23 26 29 9 12 15 18 21 24 27 30 10 13 16 19 22 25 28 31 11 14 17 20 23 26 29 32 Output of value 9 15 21 27 33 39 45 51 12 18 24 30 36 42 48 54 15 21 27 33 -1 3 2 57 18 24 30 36 42 48 54 60 21 27 33 39 45 51 57 63 24 30 36 42 48 54 60 66 27 33 39 45 51 57 63 69 30 36 42 48 54 60 66 72 } (* 6 - 3 EX03_6.pas*) program Example_Of_Types; type Array_Def = array[12..25] of integer; Char_Def = array[0..27] of char; Real_Array = array[-17..42] of real; Dog_Food = array[1..6] of boolean; Airplane = array[1..12] of Dog_Food; Boat = array[1..12,1..6] of boolean; var Index,Counter : integer; Stuff : Array_Def; Stuff2 : Array_Def; Puppies : Airplane; Kitties : Boat; begin (* main program *) for Index := 1 to 12 do for Counter := 1 to 6 do begin Puppies[Index,Counter] := TRUE;

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (9 of 11) [28/03/2012 17:51:47]

6

21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

Kitties[Index,Counter] := Puppies[Index,Counter]; end; Writeln(Puppies[2,3]:7,Kitties[12,5]:7,Puppies[1,1]:7); end. (* of main program *) { Result of execution TRUE TRUE TRUE } (* 6 - 4 EX04_6.pas*) program Example_Of_Constants; const Max_Size = 12; (* Pascal assumes this is a byte type, but it can be used as an integer also *) Index_Start : integer = 49; (* This is a typed constant *) Check_It_Out : boolean = TRUE; (* Another typed constant *) type var Bigarray = array[1..Max_Size] of integer; Chararray = array[1..Max_Size] of char; Airplane : Bigarray; Seaplane : Bigarray; Helicopter : Bigarray; Cows : Chararray; Horses : Chararray; Index : integer;

begin (* main program *) for Index := 1 to Max_Size do begin Airplane[Index] := Index*2; Seaplane[Index] := Index*3 + 7; Helicopter[Max_Size - Index + 1] := Index + Airplane[Index]; Horses[Index] := 'X'; Cows[Index] := 'R'; end; end. (* of main program *) { Result of execution (There is no output from this program) }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (10 of 11) [28/03/2012 17:51:47]

6

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

(* 6 - 5 EX05_6.pas*) program Label_Illustration; label var 274,Repeat_Loop,Help,Dog; Counter : byte; (* This limits us to a maximum of 255 *)

begin Writeln('Start here and go to "help"'); goto Help; Dog: Writeln('Now go and end this silly program'); goto 274; Repeat_Loop: for Counter := 1 to 4 do Writeln('In the repeat loop'); goto Dog; Help: Writeln('This is the help section that does nothing'); goto Repeat_Loop; 274: Writeln('This is the end of this spaghetti code'); end. { Result of execution Start here and go to "help" This is the help section that does nothing In the repeat loop In the repeat loop In the repeat loop In the repeat loop Now go and end this silly program This is the end of this spaghetti code }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter6.htm (11 of 11) [28/03/2012 17:51:47]

7

7

Pascal Pascal, (string) 2 char, . 01_7.PAS .

AG00050_. ..... 01_7.PAS gif (1615 type bytes) var. type. , , char. char . First_Name , 10 . , (invalid error). H Pascal . , (concatention), . . , . , Pascal . Turbo Pascal . 01_7.PAS . string Turbo Pascal 02_7PAS.

AG00050_. ..... 02_7.PAS giffile:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter7.htm (1 of 5) [28/03/2012 17:51:49]

7

(1615 . Turbo Pascal , Standard Pascal, bytes) string. , string. , . First_Name , 11 . First_Name[0] First_Name[1] First_Name[10]. byte , , 255 .

' . First_Name 10, 4 , First_Name[0] 4 6 . 3 var. string Full_Name. 14. , , , . 02_7.PAS . string - 03_7.PAS string.

AG00050_. ..... 03_7.PAS gif (1615 bytes) . Total. Length Turbo Pascal string. byte [0] . string , string .file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter7.htm (2 of 5) [28/03/2012 17:51:49]

7

Turbo Pascal strings . , . . 1. 3 , . . .

[6][Up][8]

7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 (* 7- 1 01_7.pas*) program Pure_Pascal_Strings; type Long_String = array[1..25] of char; String10 = array[1..10] of char; String12 = array[1..12] of char; First_Name : String10; Initial : char; Last_Name : String12; Full_Name : Long_String; Index : integer;

var

begin (* main program *) First_Name := 'John '; Initial := 'Q'; Last_Name := 'Doe '; Writeln(First_Name,Initial,Last_Name); for Index := 1 to 10 do Full_Name[Index] := First_Name[Index]; Full_Name[11] := Initial; for Index := 1 to 12 do Full_Name[Index + 11] := Last_Name[Index]; for Index := 24 to 25 doFull_Name[Index] := ' '; Writeln(Full_Name);

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter7.htm (3 of 5) [28/03/2012 17:51:49]

7

27 28 29 30 31 32 33 34 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1 2 3 4 5 6 7 8 9 10 11 12 13

end. (* main program *) { Result of execution John QDoe John QDoe } (* 7- 2 02_7.pas*) program TURBO_Pascal_Strings; var First_Name : string[10]; Initial : char; Last_Name : string[12]; Full_Name : string[25];

begin (* main program *) First_Name := 'John'; Initial := 'Q'; Last_Name := 'Doe'; Writeln(First_Name,Initial,Last_Name); Full_Name := First_Name + ' ' + Initial + ' ' + Last_Name; Writeln(Full_Name); end. (* main program *) { Result of execution JohnQDoe John Q Doe } (* 7- 3 03_7.pas*) program What_Is_In_A_String; var First_Name : string[10]; Initial : char; Last_Name : string[12]; Full_Name : string[25]; Index,Total : integer;

begin (* main program *) First_Name := 'John'; Initial := 'Q'; Last_Name := 'Doe';

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter7.htm (4 of 5) [28/03/2012 17:51:49]

7

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

Writeln(First_Name,Initial,Last_Name); Full_Name := First_Name + ' ' + Initial + ' ' + Last_Name; Writeln(Full_Name); Total := Length(Full_Name); Writeln('The string contains ',Total:4,' characters'); for Index := 1 to Length(Full_Name)do Writeln(Full_Name[Index]); Writeln('End of program'); end. (* main program *) { Result of execution JohnQDoe John Q Doe The string contains 10 characters J o h n Q D o e End of program }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter7.htm (5 of 5) [28/03/2012 17:51:49]

8

8 ,

Pascal (scalar), (enumerated) , . EX01_8.PAS .

AG00050_. ..... 01_8.PAS gif (1615 Days bytes) 7 . Day Mon,Tue ... 0 , 1 ... .

, Pascal Mon Day, integer . Mon, Tue,... . type Time_Of_Day 4 , . Time Time_Of_Day. Morning, Morning_Time Morning, compiler. , real . 16 20 . loop Day , . Tue Sat Day. Day Case , . Time, 4 , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (1 of 10) [28/03/2012 17:51:51]

8

. case loop . Time Day. , . . Mon 0, Tue 1 ... , Pascal . . 02_8.PAS (subrange) .

AG00050_. ..... 02_8.PAS gif (1615 bytes) . Days

, Work . var, Day Days . Workday, Work, Mon Fri. Sat . , , . Pascal . Index 1 12. , . 12. 27 -8 Index . Pascal . , , 16 27 . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (2 of 10) [28/03/2012 17:51:51]

8

. . 7 29 35. Day WorkDay Weekend, Day . 37 42 . Succ . , . Pred . Ord . 0 1 . , Ord(Day) 5 Day Sat, Ord(Weekend) 0 Weekend Sat. , . . , . . . . . integer, char, byte . . . , (sets). 03_8.PAS .

AG00050_. ..... E03_8.PAS gif (1615 ' Goodies . bytes) set of . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (3 of 10) [28/03/2012 17:51:51]

8

Treat, . Ice_Cream_Cone Treat. Goodies. , Ice_Cream Cone. Ice_Cream_Cone . 21 26, 4 . banana_split , . 5 Mixed, () . , . in . . , , Remaining 32. Mixed , . , , . Pascal 04_8.PAS .

AG00050_. ..... 04_8.PAS gif (1615 ' bytes) .

chars, . 'a'...'z'. Data_Set , Print_Group, . Storage . - "non-lower case character" ( ) . , .file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (4 of 10) [28/03/2012 17:51:51]

8

. 1. 04_8.PAS .

[7][Up][9]

8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 (* 8 - 1 01_8.pas*) program Enumerated_Types; type var Days = (Mon,Tue,Wed,Thu,Fri,Sat,Sun); Time_Of_Day = (Morning,Afternoon,Evening,Night); Day : Days; Time : Time_Of_Day; Regular_Rate : real; Evening_Premium : real; Night_Premium : real; Weekend_Premium : real; Total_Pay : real;

begin (* main program *) Writeln('Pay rate table':33); Writeln; Write(' DAY Morning Afternoon'); Writeln(' Evening Night'); Writeln; Regular_Rate := 12.00; (* This is the normal pay rate *) Evening_Premium := 1.10; (* 10 percent extra for working late *) Night_Premium := 1.33; (* 33 percent extra for graveyard *) Weekend_Premium := 1.25; (* 25 percent extra for weekends *) for Day := Mon to Sun do begin case Day of Mon : Write('Monday '); Tue : Write('Tuesday '); Wed : Write('Wednesday '); Thu : Write('Thursday ');

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (5 of 10) [28/03/2012 17:51:51]

8

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 1 2 3 4 5 6 7

Fri : Write('Friday '); Sat : Write('Saturday '); Sun : Write('Sunday '); end; (* of case statement *) for Time := Morning toNight do begin case Timeof Morning : Total_Pay := Regular_Rate; Afternoon : Total_Pay := Regular_Rate; Evening : Total_Pay := Regular_Rate * Evening_Premium; Night : Total_Pay := Regular_Rate * Night_Premium; end; (* of case statement *) caseDay of Sat : Total_Pay := Total_Pay * Weekend_Premium; Sun : Total_Pay := Total_Pay * Weekend_Premium; end; (* of case statement *) Write(Total_Pay:10:2); end; (*of "for Time" loop *) Writeln; end; (* of "for Day"loop *) end. (* of main program *) { Result of execution Pay rate table DAY Morning Afternoon Evening Night Monday 12.00 12.00 13.20 15.96 Tuesday 12.00 12.00 13.20 15.96 Wednesday 12.00 12.00 13.20 15.96 Thursday 12.00 12.00 13.20 15.96 Friday 12.00 12.00 13.20 15.96 Saturday 15.00 15.00 16.50 19.95 Sunday 15.00 15.00 16.50 19.95 } (* 8 - 2 02_8.pas*) program Scaler_Operations; type Days = (Mon,Tue,Wed,Thu,Fri,Sat,Sun); Work = Mon..Fri; Rest = Sat..Sun;

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (6 of 10) [28/03/2012 17:51:51]

8

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 1 2 3 4

var

Day : Days; (* This is any day of the week *) Workday : Work; (* These are the the working days *) Weekend : Rest; (* The two weekend days only *) Index : 1..12; Alphabet : 'a'..'z'; Start : 'a'..'e';

begin (* main program *) (* The following statements are commented out because they contain various errors that will halt compilation. Workday := Sat; Sat is not part of Workday's subrange. Rest := Fri; Fri is not part of Weekend's subrange. Index := 13; Index is only allowed to go up to 12, Index := -1; and down to 1. Alphabet := 'A' Alphabet, as defined, includes only the lower case alphabet. Start := 'h' h is not in the first five letters. End of commented out section. *) Workday := Tue; Weekend := Sat; Day := Workday; Day := Weekend; Index := 3+2*2; Start := 'd'; Alphabet := Start; (* since Alphabet is "d" *) Start := Succ(Alphabet); (* Start will be 'e' *) Start := Pred(Alphabet); (* Start will be 'c' *) Day := Wed; Day := Succ(Day); (* Day will now be 'Thu' *) Day := Succ(Day); (* Day will now be 'Fri' *) Index := Ord(Day); (* Index will be 4 (Fri = 4) *) end. (* of main program *) { Result of execution (There is no output from this porgram.) } (* 8 - 3 03_8.pas*) program Define_Some_Sets; type Goodies = (Ice_Cream,Whipped_Cream,Banana,Nuts,Cherry,

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (7 of 10) [28/03/2012 17:51:51]

8

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

Choc_Syrup,Strawberries,Caramel,Soda_Water, Salt,Pepper,Cone,Straw,Spoon,Stick); Treat = set ofGoodies; var Sundae : Treat; Banana_Split : Treat; Soda : Treat; Ice_Cream_Cone : Treat; Nutty_Buddy : Treat; Mixed : Treat; Index : byte;

begin (* define all ingredients used in each treat *) Ice_Cream_Cone := [Ice_Cream,Cone]; Soda := [Straw,Soda_Water,Ice_Cream,Cherry]; Banana_Split := [Ice_Cream..Caramel]; Banana_Split := Banana_Split + [Spoon]; Nutty_Buddy := [Cone,Ice_Cream,Choc_Syrup,Nuts]; Sundae := [Ice_Cream,Whipped_Cream,Nuts,Cherry,Choc_Syrup, Spoon]; (* combine for a list of all ingredients used *) Mixed := Ice_Cream_Cone + Soda + Banana_Split + Nutty_Buddy + Sundae; Mixed := [Ice_Cream..Stick] - Mixed; (* all ingredients not used *) if Ice_Cream in Mixed then Writeln('Ice cream not used'); if Whipped_Cream in Mixed then Writeln('Whipped cream not used'); if Banana in Mixed then Writeln('Bananas not used'); if Nuts in Mixed then Writeln('Nuts are not used'); if Cherry in Mixed then Writeln('Cherrys not used'); if Choc_Syrup in Mixed then Writeln('Chocolate syrup not used'); if Strawberries in Mixed then Writeln('Strawberries not used'); if Caramel in Mixed then Writeln('Caramel is not used'); if Soda_Water in Mixed then Writeln('Soda water is not used'); if Salt in Mixed then Writeln('Salt not used'); if Pepper in Mixed then Writeln('Pepper not used'); if Cone in Mixed then Writeln('Cone not used'); if Straw in Mixed then Writeln('Straw not used'); if Spoon in Mixed then Writeln('Spoon not used'); if Stick in Mixed then Writeln('Stick not used'); end. { Result of execution

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (8 of 10) [28/03/2012 17:51:51]

8

52 53 54 55 56 57 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

Salt not used Pepper not used Stick not used } (* 8 - 4 04_8.pas*) program Find_All_Lower_Case_Characters; const type var String_Size = 30; Low_Set = set of 'a'..'z'; Data_Set : Low_Set; Storage : string[String_Size]; Index : 1..String_Size; Print_Group : string[26];

begin (* main program *) Data_Set := []; Print_Group := ''; Storage := 'This is a set test.'; for Index := 1 to Length(Storage) do begin if Storage[Index] in['a'..'z'] then begin if Storage[Index] in Data_Set then Writeln(Index:4,' ',Storage[Index], ' is already in the set') else begin Data_Set := Data_Set + [Storage[Index]]; Print_Group := Print_Group + Storage[Index]; Writeln(Index:4,' ',Storage[Index], ' added to group, complete group = ', Print_Group); end; end else Writeln(Index:4,' ',Storage[Index], ' is not a lower case letter'); end; end. (* of main program *) { Result of execution 1 T is not a lower case letter 2 h added to group, complete group = h

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (9 of 10) [28/03/2012 17:51:51]

8

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

3 i added to group, complete group = hi 4 s added to group, complete group = his 5 is not a lower case letter 6 i is already in the set 7 s is already in the set 8 is not a lower case letter 9 a added to group, complete group = hisa 10 is not a lower case letter 11 s is already in the set 12 e added to group, complete group = hisae 13 t added to group, complete group = hiseat 14 is not a lower case letter 15 t is already in the set 16 e is already in the set 17 s is already in the set 18 t is already in the set 19 . is not a lower case letter }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter8.htm (10 of 10) [28/03/2012 17:51:51]

9

9

Pascal, (record). , . , , EX01_9.PAS.

AG00050_. .....EX01_9.PAS gif (1615 . bytes) (Type section) Description . 3 , Year, Model Engine. , . . Description, =, record, , end. Pascal end begin. . Truck Description Cars 10 . Truck 3 , Year, Model Engine . Truck, 3 , 3 , . -, - . ".-" . Truck 3 -. 16 18 , 3 . Year integer , Model Pickup Engine Diesel.file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (1 of 11) [28/03/2012 17:51:53]

9

10 Cars. , 30 . 26 30, . , 10 , 30 , ". -" . , . Pascal, . 01_9.PAS . - Pascal 02_9.PAS .

AG00050_. .....EX02_9.PAS gif (1615 . bytes) . 3

, , . Person, 9 , 3 Full_Name, 3 , 3 Date. , , . var Friend 50 ( const) , Person. 9 , 9x50=450 , . Pascal . 450 , compiler . Person , , 3 , Self, Mother Father. 3 9 , 27 . Index byte. file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (2 of 11) [28/03/2012 17:51:53]

9

Self 31 43. 3 , , . Self, , Name Person. 3 . Self.Name.First_Name - Self 31 "Charley". . with ; , , city, 2 . , Self.City. "with Self do". . begin 34 end 43, "Self." . with. City, State Zipcode Self . Day "Self.Birthday.Day" "Self." with Self . , with 39 42. , Month Self. Birthday.Month with. with ; (nested records) . Pascal, ' . Turbo Pascal, 9 , with . 9 , , . Year, Self , 9 . Self 9 , Self .

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (3 of 11) [28/03/2012 17:51:53]

9

- 45, "Mother:=Self", . , 9 Pascal , Self Mother. , Mother . 46 Mother Father, 50 Friend, . 450+27=477 . , , . 49 52 3 . . , , 4 . 50 47. , 1000 64 , 64. Turbo Pascal 64 ( 64) . . , " ", , RAM . , . . 03_9.PAS .

AG00050_. .... EX03_9.PAS gif (1615 , , bytes) Kind_Of_Vehicle, record. Vehicle, , . , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (4 of 11) [28/03/2012 17:51:53]

9

, . . ; 3 . case. , 4 . What_Kind (tagfield) . , . (:) of. ' . . . , , . , . . 3 Wheels, Tires Tyres, , compiler. . compiler . , . , , . Pascal . 22 4 Vehicle. Vehicle Ford. 7 Ford 28. Truck, file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (5 of 11) [28/03/2012 17:51:53]

9

. Motor, Tires Payload Ford, Wheels, Engine, tyres, ... Ford. , Sunfish , ' 33 41. Sunfish ' . with . Ford. Mac Sunfish 48. Sunfish Mac , Mac . Ford , Sunfish Mac . Schwinn , . Ford car, if, 51 . Sunfish bicycle, . Mac boat, . , , . . , . 03_9.PAS . 1. 5 .

[8][Up][10]

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (6 of 11) [28/03/2012 17:51:53]

9

9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 (* 9 - 1 EX01_9.pas*) program A_Small_Record; type Description = record Year : integer; Model : string[20]; Engine : string[8]; end; Truck : Description; Cars : array[1..10] of Description; Index : integer;

var

begin (* main program *) Truck.Year := 1988; Truck.Model := 'Pickup'; Truck.Engine := 'Diesel'; for Index := 1 to 10 do begin Cars[Index].Year := 1930 + Index; Cars[Index].Model := 'Duesenburg'; Cars[Index].Engine := 'V8'; end; Cars[2].Model := 'Stanley Steamer'; Cars[2].Engine := 'Coal'; Cars[7].Engine := 'V12'; Cars[9].Model := 'Ford'; Cars[9].Engine := 'rusted'; Write('My ',Truck.Year:4,' '); Write(Truck.Model,' has a '); Writeln(Truck.Engine,' engine.'); for Index := 1 to 10 do begin Write('My ',Cars[Index].Year:4,' '); Write(Cars[Index].Model,' has a '); Writeln(Cars[Index].Engine,' engine.'); end; end. (* of main program *) { Result of execution

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (7 of 11) [28/03/2012 17:51:54]

9

45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

My My My My My My My My My My My }

1988 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940

Pickup has a Diesel engine. Duesenburg has a V8 engine. Stanley Steamer has a Coal engine. Duesenburg has a V8 engine. Duesenburg has a V8 engine. Duesenburg has a V8 engine. Duesenburg has a V8 engine. Duesenburg has a V12 engine. Duesenburg has a V8 engine. Ford has a rusted engine. Duesenburg has a V8 engine.

(* 9 - 2 EX02_9.pas*) program A_Larger_Record; const Number_Of_Friends = 50; type Full_Name = record First_Name : string[12]; Initial : char; Last_Name : string[15]; end; Date = record Day : byte; Month : byte; Year : integer; end; Person = record Name : Full_Name; City : string[15]; State : string[2]; Zipcode : string[5]; Birthday : Date; end; var Friend : array[1..Number_Of_Friends] of Person; Self, Mother, Father : Person; Index : byte;

begin (* main program *) Self.Name.First_Name := 'Charley'; Self.Name.Initial := 'Z';

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (8 of 11) [28/03/2012 17:51:54]

9

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

Self.Name.Last_Name := 'Brown'; with Self do begin City := 'Anywhere'; State := 'CA'; Zipcode := '97342'; Birthday.Day := 17; with Birthday do begin Month := 7; Year := 1938; end; end; (* all data for self now defined *) Mother := Self; Father := Mother; for Index := 1 to Number_Of_Friends do Friend[Index] := Mother; Write(Friend[27].Name.First_Name,' '); Write(Friend[33].Name.Initial,' '); Write(Father.Name.Last_Name); Writeln; end. (* of main program *) { Result of execution Charley Z Brown }

1 (* 9 - 3 EX03_9.pas *) 2 program Variant_Record_Example; 3 4 type Kind_Of_Vehicle = (Car,Truck,Bicycle,Boat); 5 6 Vehicle = record 7 Owner_Name : string[25]; 8 Gross_Weight : integer; 9 Value : real; 10 case What_Kind : Kind_Of_Vehicle of 11 Car : (Wheels : integer; 12 Engine : string[8]); 13 Truck : (Motor : string[8]; 14 Tires : integer; 15 Payload : integer); 16 Bicycle : (Tyres : integer); 17 Boat : (Prop_Blades : byte; 18 Sail : boolean; 19 Power : string[8]);file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (9 of 11) [28/03/2012 17:51:54]

9

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

end; (* of record *) var Sunfish,Ford,Schwinn,Mac : Vehicle;

begin (* main program *) Ford.Owner_Name := 'Walter'; (* fields defined in order *) Ford.Gross_Weight := 5750; Ford.Value := 2595.00; Ford.What_Kind := Truck; Ford.Motor := 'V8'; Ford.Tires := 18; Ford.Payload := 12000; with Sunfish do begin What_Kind := Boat; (* fields defined in random order *) Sail := TRUE; Prop_Blades := 3; Power := 'wind'; Gross_Weight := 375; Value := 1300.00; Owner_Name := 'Herman and George'; end; Ford.Engine := 'flathead'; (* tag-field not defined yet but it *) Ford.What_Kind := Car; (* must be before it can be used *) Ford.Wheels := 4; (* notice that the non variant part is not redefined here *) Mac := Sunfish; (* entire record copied, including the tag-field *) if Ford.What_Kind = Car then (* this should print *) Writeln(Ford.Owner_Name,' owns the car with a ',Ford.Engine, ' engine.'); if Sunfish.What_Kind = Bicycle then (* this should not print *) Writeln('The sunfish is a bicycle which it shouldn''t be'); if Mac.What_Kind = Boat then (* this should print *) Writeln('The mac is now a boat with',Mac.Prop_Blades:2, ' propeller blades.'); end. (* of main program *) { Result of execution Walter owns the car with the flathead engine. The mac is now a boat with three propeller blades.

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (10 of 11) [28/03/2012 17:51:54]

9

67 }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter9.htm (11 of 11) [28/03/2012 17:51:54]

10

10 /

Write Writeln , . ' , . , Write Writeln . , . , EX01_10.PAS .

AG00050_. ..... EX01_10.PAS gif (1615 bytes)

Pascal . Writeln . Write , . Write . ' , EX01_10.PAS, . . 13 14. Index , . Index , 15 . . . real 19 20 integer , 15 file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (1 of 10) [28/03/2012 17:51:56]

10

(scientific format). 21 23, . boolean, char string . string , 10 , 8 . . Turbo Pascal 3 EX01_10.PAS. EX02_10.PAS . 8 .

AG00050_. ..... EX02_10.PAS gif (1615 Pascal , bytes) . ,

string, . . "Read" string . Index ' 5 Read . 3 Integer . 3 , , . , 19 25 5 , Read Readln. . EX02_10.PAS 3 integer. 3 , Enter. , 3. , 3 Enter. . 3 , . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (2 of 10) [28/03/2012 17:51:56]

10

Readln . , . Enter , "Thank you". , Read Readln . . . integer , , . / (/O error) turbo Pascal ( ). , "" . real EX03_10.PAS real .

AG00050_. ..... EX03_10.PAS gif (1615 integer 3 real . bytes) real . real . , Integer . real ' . , EX04_10.PAS, .

AG00050_. ..... EX04_10.PAS gif (1615 bytes) . .

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (3 of 10) [28/03/2012 17:51:56]

10

EX05_10.PAS 10 string , 10 string. .

/ error . integer real , . , , . ' . , . . ; Pascal , . EX06_10.PAS . Write Writeln , . , , . 9 10 , Output. Write. , .

AG00050_. ..... EX05_10.PAS gif (1615 bytes)

AG00050_. ..... EX06_10.PAS gif (1615 bytes) Pascal Lst,

. write writeln . . , Read Readln file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (4 of 10) [28/03/2012 17:51:56]

10

. , standard .

1. 60 , . , . .

[9][Up][11]

10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 (* 10 - 1 01_10.pas*) program Examples_Of_Write_Statements; var Index : byte; Count : real; What : boolean; Letter : char; Name : string[10];

begin Writeln('Integer'); Index := 17; Writeln(Index,Index); Writeln(Index:15,Index:15); Writeln; Writeln('Real'); Count := 27.5678; Writeln(Count,Count); Writeln(Count:15,Count:15); Writeln(Count:15:2,Count:15:2); Writeln(Count:15:3,Count:15:3); Writeln(Count:15:4,Count:15:4); Writeln; Writeln('Boolean');

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (5 of 10) [28/03/2012 17:51:56]

10

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

What := FALSE; Writeln(What,What); Writeln(What:15,What:15); Writeln('Char'); Letter := 'Z'; Writeln(Letter,Letter); Writeln(Letter:15,Letter:15); Writeln('String'); Name := 'John Doe'; Writeln(Name,Name); Writeln(Name:15,Name:15); Writeln; Writeln('Text output','Text output'); Writeln('Text output':15,'Text output':15); end. { Result of execution Integer 1717 17 17 Real 2.7567800000E+01 2.7567800000E+01 2.75678000E+01 2.75678000E+01 27.57 27.57 27.568 27.568 27.5678 27.5678 Boolean FALSEFALSE FALSE FALSE Char ZZ ZZ String John DoeJohn Doe John Doe John Doe Text OutputText Output Text Output Text Output }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (6 of 10) [28/03/2012 17:51:56]

10

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 11 12

(* 10 - 2 02_10.pas*) program Read_Some_Variables; var Index : byte; Number1,Number2,Number3 : integer;

begin (* main program *) Writeln('This is the ''Read'' portion of the program'); for Index := 1 to 5 do begin Write('Enter up to three integers '); Read(Number1,Number2,Number3); Writeln('Thank you'); Writeln('The numbers entered were',Number1:6,Number2:6, Number3:6); end; Writeln; Writeln('This is the ''Readln'' portion of the program'); for Index := 1 to 5 do begin Write('Enter up to three integers '); Readln(Number1,Number2,Number3); Writeln('Thank you'); Writeln('The numbers entered were',Number1:6,Number2:6, Number3:6); end; end. (* of main program *) { Result of execution (The results are dependent on the data entered at the keyboard) } (* 10 - 3 03_10.pas*) program Read_Some_Real_Variables; var Index : byte; Number : integer; Real1,Real2,Real3 : real;

begin Writeln('Read some Real variables'); for Index := 1 to 5 do begin Write('Enter an integer and 3 reals '); Readln(Number,Real1,Real2,Real3);

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (7 of 10) [28/03/2012 17:51:56]

10

13 14 15 16 17 18 19 20 21 22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Writeln(Number:20,Real1:12:3,Real2:12:3,Real3:12:3); end; end. { Result of execution (The results depend on the data entered at the keyboard) } (* 10 - 4 04_10.pas*) program Read_Some_Char_Data; var Letter : char; Index : byte;

begin for Index := 1 to 5 do begin Write('Input a character '); Readln(Letter); Writeln('The character input was an ',Letter); end; end. { Result of execution ( The results depend on the data entered at the keyboard) } (* 10 - 5 05_10.pas*) program Read_A_String; var Index : byte; Field : string[10];

begin for Index := 1 to 5 do begin Write('Enter up to 10 characters '); Readln(Field); Writeln('The data you entered was(',Field,')'); end; end. { Result of execution

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (8 of 10) [28/03/2012 17:51:56]

10

17 (The output depends on the data entered at the keyboard) 18 19 } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 (* 10 - 6 06_10.pas*) program Printout_Example; uses Printer; var Index : byte; begin Writeln(Output,'Printer program example'); Writeln(Output,'Turn on your printer and install paper in it.'); Writeln(Lst,'This is to demonstrate printing in Pascal'); Writeln(Lst); for Index := 1 to 15 do begin Write(Lst,'The index value is '); Write(Lst,Index:3); Writeln(Lst,' at this point'); end; end. { Result of execution Printer example program Turn on your printer and install paper in it (The following is output to the printer) This is to demonstrate printing in Pascal The The The The The The The The The The The The The The index index index index index index index index index index index index index index value value value value value value value value value value value value value value is is is is is is is is is is is is is is 1 at this point 2 at this point 3 at this point 4 at this point 5 at this point 6 at this point 7 at this point 8 at this point 9 at this point 10 at this point 11 at this point 12 at this point 13 at this point 14 at this point

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (9 of 10) [28/03/2012 17:51:56]

10

44 The index value is 15 at this point 45 46 }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter10.htm (10 of 10) [28/03/2012 17:51:56]

11

11

. , , , . . , . , . , ... , . (floppy disks), (hard disks) , . , . Pascal 1971, floppy disks. Pascal . compiler Standard Pascal. , , . , Assign, Open. . , , Pascal . . compilers, Turbo Pascal compilers. , urbo Pascal, Pascal.file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (1 of 17) [28/03/2012 17:51:59]

11

, , - mainframe . , / Pascal. EX01_11.PAS text . . Assign. Turbo Pascal . . Lst . Hellas , . var text 4. . string, , string.

AG00050_. .....EX01_11.PAS gif (1615 text bytes) . " " (file of char), . , .

, Pascal . , Pascal. , Assign. , Reset 9. , . , . , while . "F" "EOLN" ;

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (2 of 17) [28/03/2012 17:51:59]

11

Eof . , , . "end of file" ( ) Eof. H Pascal standard Pascal FALSE . , TRUE. , . . Eoln . , FALSE, TRUE. . , Readln, Hellas . , 80 , . , . . , . . , Hellas. , . , . . . EX02_11.PAS .

, . , string 12 , Name_Of_File_To_Input file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (3 of 17) [28/03/2012 17:51:59]

AG00050_. .....EX02_11.PAS gif (1615 bytes)

11

. Assign , , Chicken. reset . 15 18 , , . writeln, string 23 . , . . . , ( .PAS). , / error . . EX03_11.PAS .

, Assign Reset. Reset . Turbo Pascal compilers Pascal. , , . , Turbo Pascal , . , . 16 20 . ( ) compiler / Turbo Pascal ( ) compiler 16. compiler / , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (4 of 17) [28/03/2012 17:51:59]

AG00050_. .....EX03_11.PAS gif (1615 bytes)

11

Reset 17. compiler 18 / . Reset, . , Turbo Pascal , IOResult /. 0, / , , . , 0 boolean, , . . , 21 24 , . . Rewrite 24 . REset WRITEing . . , . , Rewrite , . , . , . , . . . . ! , , . , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (5 of 17) [28/03/2012 17:51:59]

11

. , ; . , . , . EX04_11.PAS .

AG00050_. .....EX04_11.PAS gif (1615 ASCII bytes) , , ,

. string, (linefields), carriage returns (Enter), . . , . , reset , 4 read write . read readln. 4 Reset . INTDATA.TXT . READDISP.PAS . integer 101 148 4 . 4 a . READ READLN , . , , ... , Read , Readln . Read , Readln . .file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (6 of 17) [28/03/2012 17:51:59]

11

INTDATA.TXT 4 EX04_11.PAS 3 . , 101, 102, 103, , 104, Read. , 105 106, 107. 5 . 19 22 Readln 101, 102, 103, , , 105. Readln, 105, 106, 107, . . loop Read, Readln. , , 5 integer , 4 . . 4 , ... Read Readln . 4 . real EX05_11.PAS.

AG00050_. .....EX05_11.PAS gif (1615 8 , Pascal. bytes) 4 , 6 . EX05_11.PAS real. , . Readln integer, real, , . , , . , . , . .file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (7 of 17) [28/03/2012 17:51:59]

11

Read Readln 14 , 6 . 0.0006 integer , . , Read Readln 14, . EX03_11.PAS . Turbo Pascal real . 0, , . . , / . Assign, Reset , Rewrite , Close. , , . ' , , , . , . EX06_11.PAS (binary file).

record . var, Output_File "file of Dat_Rec", record . Dog_Food records, . , "file of char", . . , compilerfile:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (8 of 17) [28/03/2012 17:51:59]

AG00050_. .....EX06_11.PAS gif (1615 bytes)

11

Pascal compiler . . , 15, Rewrite , , . 18 22 20 records . Write - . . , integer, byte, real record, . record , records , record. Writeln . Write . Close . ; Pascal , , Pascal compiler, - Pascal. compiler . , . . real , , . , ASCII , . , KIBBLES.BIT, 20 records . DOS . TYPE, , , .file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (9 of 17) [28/03/2012 17:51:59]

11

EX07_11.PAS .

AG00050_. ..... EX07_11.PAS gif (1615 , bytes) .

, if. Pascal . , 3 . , . Readln , Read. , GET PUT GET PUT Standard Pascal, Turbo Pascal . Read Write , . GET PUT . , Pascal . . 1. EX01_11.PAS , ( reset), . 2. , . , . DIR DOS.

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (10 of 17) [28/03/2012 17:51:59]

11

[10][Up][12]

11 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 (* 11 - 1 EX01_11.pas*) program Read_A_File; var Hellas : text; Big_String : string[80];

begin (* main program *) Assign(Hellas,'READFILE.PAS'); Reset(Hellas); while not Eof(Hellas) do begin Readln(Hellas,Big_String); Writeln(Big_String); end; (* of while loop *) Close(Hellas); end. (* of program *) { Result of execution (This file is displayed on the monitor) } (* 11 - 2 EX02_11.pas*) program Read_And_Display; var Chicken : text; Name_Of_File_To_Input : string[12]; Line_Count : integer; Big_String : string[80]; begin (* main program *) Write('Enter input file name '); Readln(Name_Of_File_To_Input); Assign(Chicken,Name_Of_File_To_Input); Reset(Chicken); Writeln; Writeln('Program listing with character count per'); Writeln('line and total line count');

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (11 of 17) [28/03/2012 17:51:59]

11

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Writeln; Line_Count := 0; while not Eof(Chicken) do begin Readln(Chicken,Big_String); Writeln(Length(Big_String):5,' ',Big_String); Line_Count := Line_Count + 1; end; Close(Chicken); Writeln; Writeln('The line count is ',Line_Count:3); end. (* of program *) { Result of execution (The selected file is displayed on the monitor) } (* 11 - 3 EX03_11.pas*) program Read_And_Store_A_File; var Read_File : text; Input_File_Name : string[12]; Write_File : text; Output_File_Name : string[12]; Line_Number : integer; Big_String : string[80]; Read_File_OK : boolean; begin Write('Enter input file name '); Readln(Input_File_Name); Assign(Read_File,Input_File_Name); {$I-} Reset(Read_File); {$I+} Read_File_OK := (IOResult = 0); if Read_File_OK then begin Write('Enter output file name '); Readln(Output_File_Name); Assign(Write_File,Output_File_Name); Rewrite(Write_File); Line_Number := 1; while not Eof(Read_File)do begin

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (12 of 17) [28/03/2012 17:51:59]

11

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

Readln(Read_File,Big_String); Write(Write_File,Line_Number:5,' '); Writeln(Write_File,Big_String); Line_Number := Line_Number + 1; end; Close(Read_File); Close(Write_File); end else Writeln('Input file doesn''t exist, execution aborted'); end. (* of program *) { Result of execution (The selected file is copied to the selected output file) } (* 11 - 4 EX04_11.pas*) program Read_Integers_From_File; var Cupcake : text; Index : byte; Var1,Var2,Var3,Var4,Var5 : integer;

begin Assign(Cupcake,'INTDATA.TXT'); Reset(Cupcake); for Index := 1 to 5 do begin Read(Cupcake,Var1,Var2,Var3); Writeln(Var1:6,Var2:6,Var3:6); end; Reset(Cupcake); Writeln; for Index := 1 to 5 do begin Readln(Cupcake,Var1,Var2,Var3); Writeln(Var1:6,Var2:6,Var3:6); end; Reset(Cupcake); Writeln; for Index := 1 to 5 do begin Read(Cupcake,Var1,Var2,Var3,Var4,Var5); Writeln(Var1:6,Var2:6,Var3:6,Var4:6,Var5:6);

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (13 of 17) [28/03/2012 17:51:59]

11

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 1 2 3 4 5 6 7

end; Reset(Cupcake); Writeln; for Index := 1 to 5 do begin Readln(Cupcake,Var1,Var2,Var3,Var4,Var5); Writeln(Var1:6,Var2:6,Var3:6,Var4:6,Var5:6); end; Close(Cupcake); end. (* of main program *) { Result of execution (This data is read from INTDATA.TXT) 101 104 107 110 113 101 105 109 113 117 101 106 111 116 121 101 109 117 125 133 } (* 11 - 5 EX05_11.pas*) program Read_Real_Data_From_A_File; var Hot_Dog : text; Index : byte; Line_Number : integer; Real1,Real2,Real3 : real; 102 105 108 111 114 102 106 110 114 118 102 107 112 117 122 102 110 118 126 134 103 106 109 112 115 103 107 111 115 119 103 108 113 118 123 103 111 119 127 135 104 109 114 119 124 104 112 120 128 136 105 110 115 120 125 105 113 121 129 137

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (14 of 17) [28/03/2012 17:51:59]

11

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

begin (* main program *) Assign(Hot_Dog,'REALDATA.TXT'); Reset(Hot_Dog); for Index := 1 to 7 do begin Readln(Hot_Dog,Line_Number,Real1,Real2,Real3); Writeln(Line_Number:7,Real1:12:3,Real2:12:3,Real3:12:3); end; Close(Hot_Dog); end. (* of main program *) { Result of execution 1 2 3 4 6 7 8 } (* 11 - 6 EX06_11.pas*) program Binary_Output_Example; type Dat_Rec = record Count : integer; Size : real; Name : string[30]; end; Output_File : file of Dat_Rec; Dog_Food : array[1..20] of Dat_Rec; Index : byte; 23.600 145.450 234.800 -0.400 -0.050 0.345 4.000 3456.000 123.000 77.000 5.000 -0.003 1.000 2.000 3.000 12.120 13.110 14.140 2.000 3.000 4.000

var

begin (* main program *) Assign(Output_File,'KIBBLES.BIT'); Rewrite(Output_File); for Index := 1 to 20 do begin Dog_Food[Index].Count := Index; Dog_Food[Index].Size := 12345.6789; Dog_Food[Index].Name := 'Large size Kibbles & Bits'; end;

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (15 of 17) [28/03/2012 17:51:59]

11

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

Writeln('Begin outputting data'); for Index := 1 to 20 do Write(Output_File,Dog_Food[Index]); Close(Output_File); Writeln('End of output'); end. (* of main program *) { Result of execution Begin outputting data End of output (In addition to the above output to the monitor, the file named KIBBLES.BIT is created and filled with binary data.) } (* 11 - 7 EX07_11.pas*) program Binary_Input; type Input_Record = record Number : integer; Amount : real; Name : string[30]; end; Input_File : file of Input_Record; Bird_Food : array[1..20] of Input_Record; Index : byte;

var

begin (* main program *) Assign(Input_File,'KIBBLES.BIT'); Reset(Input_File); for Index := 1 to 20 do if not Eof(Input_File) then Read(Input_File,Bird_Food[Index]); Close(Input_File); Writeln(Bird_Food[6].Number:6,Bird_Food[20].Amount:13:5, ' ',Bird_Food[1].Name); end. (* of main program *) { Result of execution

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (16 of 17) [28/03/2012 17:51:59]

11

29 6 12345.67890 Large size Kibbles & Bits 30 31 }

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter11.htm (17 of 17) [28/03/2012 17:51:59]

12

12

, (pointers) (dynamic allocation) , . ' , Pascal. , . . , , . , ; EX01_12.PAS .

AG00050_. .....EX01_12.PAS gif (1615 var Where Who bytes) " ^ " . , ,

integer , ' . 3 9. 4. .

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (1 of 20) [28/03/2012 17:52:03]

12

wpe3.jpg (9801 bytes)

12-1 12-1 . , . 12 , Index 17. Where Index 17, Index . , Index Who. Addr Turbo Pascal . ; Index 12-2.

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (2 of 20) [28/03/2012 17:52:03]

12

wpe4.jpg (11458 bytes)

12- 2 , 15. "Where^", , . 15. Index, Where, Who. Index . . 17, 23 Where 12-3 .

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (3 of 20) [28/03/2012 17:52:03]

12

wpeC.jpg (11285 bytes)

12- 3 , Index 23 Where. 18, Index 3 15. 3 17 3 23 3 . , , . EX01_12 . 4, Int_Point integer. 9 3 20, Index. , Pt2 Pt1, 21. ' Index. , Pt3 Pt2, 3 Index. Turbo Pascal , 3 . , Where Who , Pascal 14 : " Who := Where; ", . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (4 of 20) [28/03/2012 17:52:03]

12

.

wpeD.jpg (14648 bytes)

12 - 4 , Index, 15 23 15 3 . 3 15. , 6 2 Index 3 . Turbo Pascal EX02_12.PAS Borland Pascal.

AG00050_. .....EX02_12.PAS gif (1615 13, 14 20, bytes)

@ Index Addr. Turbo Pascal. ANSI Standard Pascal @ ^ Borland . compiler Turbo Pascal.

file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (5 of 20) [28/03/2012 17:52:03]

12

EX03_12.PAS, .

AG00050_. .....EX03_12.PAS gif (1615 var, bytes) ^ , . . My_name string 20 . , . , . , . . DOS 60 , Turbo Pascal 4 8 , . Turbo Pascal 64. 3 128 132. 132 stack () heap (). DOS . ' . ; Pascal . stack . , . , . Turbo Pascal compiler Pascal. Turbo Pascal 64 , . , . compilers 64 . , EX03_12.PAS. , . 10 . , , My_ame . , 20 , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (6 of 20) [28/03/2012 17:52:03]

12

, 20 . ; var, New. , , . My_Name . ^, , , " ". 11 integer My_Age. 12-5.

wpeE.jpg (11497 bytes)

12 - 5 . New , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (7 of 20) [28/03/2012 17:52:03]

12

EX01_12. 13 14, 12-6.

wpe6.jpg (12838 bytes)

12 - 6 16 17 . 19 20 . , Dispose , . , , . , , , ... New.file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (8 of 20) [28/03/2012 17:52:03]

12

, . . , . . , . . . , . EX04_12.PAS .

AG00050_. .....EX04_12.PAS gif (1615 , E02_9.PAS bytes) . EX04_12.PAS, , . Person_Id, , var section, 4 ' , . . , ' . , Pascal , Person 18 19, Pascal. , Pascal . , , , . . Friend 50 , 53 file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (9 of 20) [28/03/2012 17:52:03]

12

, Index Temp. New Self , . E02_9.PAS New "^" . , 48 Mother . Self Mother, . Mother Self . Mother , , , , . . 50 51 Father Mother Self. Mother Self , , , , . , . , DOS Turbo Pascal. "Dispose(Mother)" , , , . ' . 12-1 12-5 . ; EX09_2.PAS. Number_Of_Friends . 1000 . EX04_12.PAS , , . , . 640, 8000 file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (10 of 20) [28/03/2012 17:52:03]

12

Friend. . , . . ; Pascal. . . EX05_12.PAS .

AG00050_. .....EX05_12.PAS gif (1615 bytes) . , 4 6, ' . , , Next, . , , , . , . , , Next, . , Pascal . . ' , , , Pascal, , . , . ; , , , Index. , , 3 . 54 , . , . . 20, file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (11 of 20) [28/03/2012 17:52:03]

12

Place_In_List. 3 , . Start_Of_List , . Start_Of_List . 12-7.

wpeF.jpg (17088 bytes)

12 -7 "nil" ; 3 () , nil. nil . nil , nil. ' , . record file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (12 of 20) [28/03/2012 17:52:03]

12

. . . . . 27 33 . . , , Temp_Place. Place_In_List . Temp_List , 29. 3 , nil. 12-8.

wpe2.jpg (23685 bytes)

12 -8 . , file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (13 of 20) [28/03/2012 17:52:03]

12

nil. 3 , , , . , , , . 10 10 . , ( ). , 10 . . , . 4 bytes . , 12 . , . ' , 3 , integer, . , , . ( , , ). , . , . ; , , ; . . , , . , . . , . , Place_In_List, . . , nil . . file:///C|/Users/litzel/Desktop/My%20Projects/IEK/Sxediash%20programmatos/Shmeiwseis%20HTML/chapter12.htm (14 of 20) [28/03/2012 17:52:03]

12

, , Pascal, . 1. , . , .

[11][Up][13]

12 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 (* 12 - 1 01_12.pas*) program First_Pointer_Example; type var Int_Point = ^Integer; Index : Integer; Where : ^Integer; Who : ^Integer; Pt1, Pt2, Pt3 : Int