Download Question 1: Mark the following statements True or False

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Large numbers wikipedia , lookup

Addition wikipedia , lookup

Line (geometry) wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Question A:
40 points
Write short and to the point answers to the following questions in
the provided space.
1. Re-write the following program by using the Do-While-Loop (instead of the
For-Next loop)
(5 points)
Sub Command1_Click
Dim num As Integer
For num= 1 To 99
Picture1.Print num
Next num
End Sub
For parts 2 to 4 write down what will be printed in the picture box
Picture1 when the command button Command1 is clicked. All Dim
statements outside the event procedures are in the Declarations
section of General
2.
(5 points)
Dim x(1 To 4) As Integer
Dim y(1 To 4) As Integer
Dim z(1 To 4) As Integer
Sub Command1_Click( )
Dim i As Integer, k As Integer
Open “DATA.TXT” For Input As #1
For i= 4 To 1 Step -1
Input #1, x(i), y(i)
Next i
Close #1
For k= 1 To 4
Picture1.Print x(k); y(k); x(k)*y(k)
Next k
End Sub
Assume that the file DATA.TXT contains the following entries
0,1
2,3
4,5
6,7
2
3.
Sub Command1_Click( )
Dim Ocean(1 To 2) As String
Ocean(1)= “Pacific”
Ocean(2)= “Atlantic”
Picture1.Cls
For index = 1 To 2
Picture1.Print Size(ocean(index)); Ocean(index)
Next index
End Sub
(5 points)
Function Size (sea As String) As String
Size = “2nd Largest ocean is ”
If sea = “Pacific” Then
Size = “Largest ocean is ”
End If
End Function
4.
(5 points)
Sub Command1_Click( )
Dim NUMBERS(1 To 3, 1 To 3) As Single
Dim j As Integer, k As Integer
Open “DATA.TXT” For Input As #1
For j=1 To 3
For k=1 To 3
Input #1, NUMBERS(j , k)
Next k
Next j
Close #1
For j=1 To3
Picture1.Print NUMBERS(j , j)
Next j
End Sub
Assume that the file DATA.TXT contains the following entries
0
1
2
3
4
5
6
7
8
3
For parts 5 to 7 circle the appropriate answer in the box. List all
errors if there are any. Specify whether an error is a syntax error or a
logical error. Assume that all objects (Text1 etc.) referred to in a
program exist. Note that all Dim statements outside the given event
procedure are in the Declarations section of General
Note: Do not write the correct code. Only identify/describe the error or
errors (if any) concisely.
5.
(5 points)
The code has following error(s).
Sub Command1_Click( )
Dim flag As Boolean, num As Single
flag = True
Do While flag
Val(Text1.Text)=num
If num *num = 0 Then
flag = False
End If
Loop
End Sub
The code is correct
6.
(5 points)
The code has following error(s).
Dim b(2 To 8 Step 2) As Integer
Sub Command1_Click( )
Dim t As Integer
Open “DATA.TXT” For Input As #1
For t=2 To 8 Step 2
Input #1, b(t)
Next t
Close #1
End Sub
The code is correct
Assume that the file DATA.TXT contains the following entries
0
1
2
3
4
5
6
7
8
4
7.
Sub Command1_Click( )
Dim inarray( 1 To 3, 1 To 4) As Integer
Dim j As Integer, k As Integer
For j=1 To 4
For k=1 To 3
(5 points)
The code has following error(s).
inarray(j,k)=Val(Inputbox(“enter a number”))
Next k
Next j
End Sub
The code is correct
8. What is the main advantage of using arrays instead of simple variables for
a list of values of the same type?
(5 points)
Question B:
30 points
a) Write a subprogram procedure (subroutine) that can be utilized
to generate two random numbers as follows.
(5 + 10 points)
I. A random number X such that 0 ≤ X < 1.
II. An integer random number Y such that -10 ≤ Y ≤ 10.
b) Write a function called Large that finds the largest number in
an array B that is passed to it as an argument. The main
program calls this function as
Large (B(), N)
where N is the number of elements of array B.
Question C:
(15 points)
30 points
A program reads 100 numbers from a file “DATA.TXT” in an array and
then sorts this array using bubble sort. The sorted numbers are then
displayed in a picture box. Sorting is done by magnitude and in the
ascending order. Thus 1,5,-7,8,10 will be regarded as a sorted array
a) Plan this program using a flow chart
(15 points)
b) Write the code of the program. The program is executed on
clicking a command button Command1 and the output is displayed in
the picture box Picture1.
(15 points)
5