Ïðîãðàììèðîâàíèå 9 êëàññ 2017-2018 ó÷åáíûé ãîä

Äîïîëíèòåëüíûå ìàòåðèàëû è ññûëêè

Óðîê 23    21.04.2018

 

 

Òåìà óðîêà: Òèïèçèðîâàííûå ôàéëû

1.    Ïðîãðàììà 1  ÷èòàåò äâîè÷íûé ôàéë (èñïîëíÿåìûé ôàéë ïðîãðàììû)  ïî áàéòàì è âûâîäèò ïðî÷èòàííûå áàéòû è, ñèìâîëû, ASCII-êîäû êîòîðûõ ñîîòâåòñòâóþò ýòèì áàéòàì,  íà ýêðàí

 

 

Ðèñóíîê 1 Èñõîäíûé òåêñò ïðîãðàììû 1

 

Ðèñóíîê 2 Ðåçóëüòàò ðàáîòû ïðîãðàììû 1

 

 

1.    Ïðîãðàììà 2,÷èòàåò èç äâîè÷íîãî ôàéëà áàéò ïîä íîìåðîì 2 (ñ÷åò èäåò ñ íóëÿ) è âûâîäèò íà ýêðàí ïðî÷èòàííûé áàéò, ñèìâîë, ASCII-êîä êîòîðîãî ðàâåí ýòîìó áàéòó è ïîëîæåíèå óêàçàòåëÿ ÷òåíèÿ.

Èñïîëüçóåò ïðîöåäóðó

Seek(<ôàéëîâàÿ ïåðåìåííàÿ>,<ïîçèöèÿ>)

È ôóíêöèþ

FilePos(<ôàéëîâàÿ ïåðåìåííàÿ>)

 

 

File  Edit  Search  Run  Compile  Debug  Tools  Options  Window  Help

┌──────── F:\projects\1436\..\Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042102.pas ──1─────┐

│╔═[■]════ F:\projects\1436..Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042103.pas ═══2═[↑]═╗

│║program p18042101;                                                          

│║var                                                                          

│║        b:byte;                                                             

│║        f:file of byte;                                                     

│║        i:integer;                                                           

│║        fn:string;                                                          

│║begin                                                                       

│║        Readln(fn);                                                          

│║        Assign(f,fn);                                                       

│║        Reset(f);                                                           

│║        Seek(f,2);                                                          

│║        Read(f,b);                                                          

│║        Writeln(i,' ',b,' ',chr(b),' ',FilePos(f));                         

│║end.                                                                        

│║                                                                             

│║                                                                            

┌║                                                                            

│║                                                                             

│║                                                                            

│║                                                                            

│╚══════ 11:17 ◄■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒►┘

 

 

Ðèñóíîê 3 Èñõîäíûé òåêñò ïðîãðàììû 2

 

 

 

Ðèñóíîê 4 Ðåçóëüòàò ðàáîòû ïðîãðàììû 2

 

 

3. Ïðîãðàììà 3, çàïèñûâàåò â ôàéë öåëûå ÷èñëà îò 1 äî 10

 

File  Edit  Search  Run  Compile  Debug  Tools  Options  Window  Help

┌──────── F:\projects\1436\..\Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042102.pas ──1─────┐

│┌─[■]──── F:\projects\1436..Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042104.pas ───2─[]─┐

││program p18042101;                                                          

││var                                                                          

││        b:byte;                                                             

││        f:file of integer;                                                  

││        i:integer;                                                           

││        fn:string;                                                          

││begin                                                                       

││        Readln(fn);                                                          

││        Assign(f,fn);                                                       

││        Rewrite(f);                                                         

││        for i:=1 to 10 do                                                    

││                Write(f,i);                                                 

││        Close(f);                                                           

││end.                                                                         

││                                                                            

││                                                                            

┌│                                                                            

││                                                                            

││                                                                            

││                                                                             ­

│└────── 14:1 ─■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒┘

 F1 Help  Cursor Move  Shift+Cursor Size  ─┘ Done  Esc Cancel

 

Ðèñóíîê 5 Èñõîäíûé òåêñò ïðîãðàììû 3

 

 

 

Ðèñóíîê 6 Ñîäåðæàíèå ñîçäàííîãî ôàéëà

 

 

4. Ïðîãðàììà 4, ÷èòàåò èç ôàéëà öåëûå ÷èñëà îò 1 äî 10 è âûâîäèò èõ íà ýêðàí

 

 

 

File  Edit  Search  Run  Compile  Debug  Tools  Options  Window  Help

┌──────── F:\projects\1436\..\Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042102.pas ──1─────┐

│╔═[■]════ F:\projects\1436..Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042104.pas ═══2═[]═╗

│║program p18042104;                                                          

│║var                                                                         

│║        b:integer;                                                          

│║        f:file of integer;                                                  

│║        i:integer;                                                          

│║        fn:string;                                                          

│║begin                                                                        

│║        Readln(fn);                                                         

│║        Assign(f,fn);                                                       

│║        Reset(f);                                                            

│║        for i:=1 to 10 do                                                   

│║                begin                                                       

│║                        Read(f,b);                                           

│║                        Writeln(b);                                         

│║                end;                                                        

│║        Close(f);                                                            

║end.                                                                        

│║                                                                            

│║                                                                             

│║                                                                             ­

│╚══════ 15:21 ■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒┘

 F1 Help  F2 Save  F3 Open  Alt+F9 Compile  F9 Make  Alt+F10 Local

Menu

 

Ðèñóíîê 7 Èñõîäíûé òåêñò ïðîãðàììû 4

 

 

Ðèñóíîê 8 Ðåçóëüòàò ðàáîòû ïðîãðàììû 4

 

 

Running "f:\projects\1436\2017-2018\Ïðîãðàììèðîâàíèå9\ÏÐîãðàììû\18042101.exe "

18042101.txt

1 1

2 0

3 2 ☻

4 0

5 3 ♥

6 0

7 4 ♦

8 0

9 5 ♣

10 0

11 6 ♠

12 0

13 7

14 0

15 8

 

Ðèñóíîê 9 Ðåçóëüòàò ðåçóëüòàò ÷òåíèÿ ôàéëà öåëûõ ÷èñåë ïîáàéòîâî ïðîãðàììîé 1