Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

in, else, àáñòðàêöèÿ, ñàìîîáðàçîâàíèå, answers, do, ïðîòîêîë, computer, ñåòè Ïåòðè, stack, interruption, var, vector, alphabet, ôóíêöèîíàëüíûé, word, answers
 

for valuable work you must have JavaScript (allow active content)

Pascal. Pc.1. Nest of tasks. Files

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.1     Answer

Determine the content of the file xxx.zzz after executing the following program


Program AA;
var
    f : file of boolean;
    k, m, n : integer;
    pr : boolean;
begin
    assign(f,’xxx.zzz’);    rewrite(f);
    k:=0; m:=3; n:=7;
    repeat
        k:=k+1;
        m:=m+k;
        n:=n+k;
        pr:=(m mod 2=0) or (n mod 5=0);
        write(f,pr);
    until k=10;
    close(f);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.2     Answer      Visual Basic-analogue

Find the value of variable Sun at the end of program.


Program AA;
var
    i, j, k, nnn, Sun : integer;
    f : file of integer;
begin
    assign(f,’xxx.int’);    rewrite(f);
    for i:=1 to 3 do begin
        j:=i*2-1;
        write(f,j);
    end;
    close(f);
    Sun:=0;    nnn:=100;
    assign(f,’xxx.int’);    reset(f);
    while not eof(f) do begin
        read(f,i);
        k:=nnn mod i;
        Sun:=Sun+k;
    end;
    close(f);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.3     Answer      Visual Basic-analogue

Find the value of variable Sun at the end of program.


Program AA;
var
    i, Sun : integer;
    f : file of integer;
begin
    assign(f,’xxx.int’);    rewrite(f);
    for i:=2 to 5 do write(f,i);
    close(f);
    Sun:=3;
    assign(f,’xxx.int’); reset(f);
    while not eof(f) do begin
        read(f,i);
        Sun:=Sun+i;
    end;
    close(f);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.4     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    while not eof(f1) do begin
        read(f1,xx);    write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.5     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx, n : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    while not eof(f1) do begin
        for n:=1 to 4 do read(f1,xx);
        write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.6     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx, n : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    while not eof(f1) do begin
        read(f1,xx);
        for n:=1 to 4 do write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.7     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    while not eof(f1) do begin
        read(f1,xx);
        if xx mod 2 = 1 then write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.8     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    xx:=0;
    while xx<17 do begin
        read(f1,xx);
        write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.9     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx, n : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    while not eof(f1) do begin
        read(f1,xx);
        for n:=1 to xx do write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.10     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx, Sum, n : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    Sum:=0;
    while not eof(f1) do begin
        read(f1,xx);
        Sum:=Sum+xx;
        for n:=1 to Sum do write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.11     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx, n : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    while not eof(f1) do begin
        read(f1,xx);
        for n:=1 to xx div 2 do write(f2,xx);
    end;
    close(f1);    close(f2);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pc.1.12     Answer      Visual Basic-analogue

Source file ‘aaa.dat’ contains numbers from 1 to 100. Determine the quantity of numbers in file ‘bbb.dat’ after executing the following procedure.


Program AA;
var
    f1, f2 : file of integer;
    xx, old, n : integer;
begin
    assign(f1,’aaa.dat’);    reset(f1);
    assign(f2,’bbb.dat’);    rewrite(f2);
    old:=1;
    while not eof(f1) do begin
        read(f1,xx);
        for n:=1 to (xx * xx) div old do write(f2,xx);
        old:=xx;
    end;
    close(f1);    close(f2);
end.

 

©   Aliaksandr Prykhodzka    1993 - 2007