Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

goto, object, while, type, set, type, system, open, scolaire, ÷àéíèê, ïàðàìåòð, ëàáîðàòîðíûé, unit, ñáîðíèê çàäà÷ ïî ïðîãðàììèðîâàíèþ, äèíàìè÷åñêèé, book
 

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

Visual Basic. B.12. Nest of tasks. Files

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.1     Answer

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


Sub AA()
    Open "c:\xxx.zzz" For Output As #1
    k = 0
    m = 3
    N = 7
    Do
        k = k + 1
        m = m + k
        N = N + k
        pr = (m Mod 2 = 0) Or (N Mod 5 = 0)
        Print #1, pr
    Loop Until k = 10
    Close #1
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.2     Answer      Pascal-analogue

Determine a value produced by function AA .


Function AA() As Integer
    Open "c:\xxx.int" For Output As #1
    For I = 1 To 3
        J = I * 2 - 1
        Print #1, J
    Next I
    Close #1
    Sun = 0
    nnn = 100
    Open "c:\xxx.int" For Input As #1
    While Not EOF(1)
        Input #1, I
        k = nnn Mod I
        Sun = Sun + k
    Wend
    Close #1
    AA = Sun
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.3     Answer      Pascal-analogue

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


Function AA() As Integer
    Open "c:\xxx.int" For Output As #1
    For I = 2 To 5
        Print #1, I
    Next I
    Close #1
    Sun = 3
    Open "c:\xxx.int" For Input As #1
    While Not EOF(1)
        Input #1, I
        Sun = Sun + I
    Wend
    Close #1
    AA = Sun
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.4     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    While Not EOF(1)
        Input #1, xx
        Print #2, xx
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.5     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    While Not EOF(1)
        For n = 1 To 4
            Input #1, xx
        Next n
        Print #2, xx
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.6     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    While Not EOF(1)
        Input #1, xx
        For n = 1 To 4
            Print #2, xx
        Next n
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.7     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    While Not EOF(1)
        Input #1, xx
        If xx Mod 2 = 1 Then
            Print #2, xx
        End If
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.8     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    xx = 0
    While xx < 17
        Input #1, xx
        Print #2, xx
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.9     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    While Not EOF(1)
        Input #1, xx
        For n = 1 To xx
            Print #2, xx
        Next n
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.10     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    Sum = 0
    While Not EOF(1)
        Input #1, xx
        Sum = Sum + xx
        For n = 1 To Sum
            Print #2, xx
        Next n
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.11     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    While Not EOF(1)
        Input #1, xx
        For n = 1 To xx \ 2
            Print #2, xx
        Next n
    Wend
    Close #1
    Close #2
End Sub


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.12.12     Answer      Pascal-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.


Sub AA()
Dim xx As Integer
    Open "c:\aaa.dat" For Input As #1
    Open "c:\bbb.dat" For Output As #2
    old = 1
    While Not EOF(1)
        Input #1, xx
        For n = 1 To (xx * xx) \ old
            Print #2, xx
        Next n
        old = xx
    Wend
    Close #1
    Close #2
End Sub



 

©   Aliaksandr Prykhodzka    1993 - 2007