Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Exam 2 Review
I Multiple Choice Questions
Q1. Which if the following is a correct statement
a. private
b. private
c. private
d. private
e. None of
sub SomeTask (byVal num() as integer) as decimal
function SomeTask (byVal num() as integer)
sub SomeTask () as decimal
sub SomeTask ()
the above.
Q2. Identify the syntax and logic ERROS in the following statements
i. for i=-1 to 10
ii. for j=1 to –5 step -3
iii. for k=10 to 1
iv. for i =2 to 6 step 2
a. iii only
b. i and ii
c. iii and iv
d. iv only
e. i, ii, iv
Q3. With the following function stub, which of the following is a correct statement to call
the function calcTotal from another procedure?
private function calcTotal (byVal num as integer) as decimal
a. calcTotal(10)
b. msgbox (calcTotal(30))
c. lblDisplay.text=calcTotal
d. function calcTotal(50)
e. goto calcTotal()
Q4. Which of the following controls will not physically appear as a visual component
while running the application?
a. picturebox
b. numeric up down scroll bar
c. frame
d. menu
e. timer
Q5. Int(13*rnd()) +2 will produce random numbers in the rang of
a. 1 and 13
b. 2 and 13
c. 2 and 14
d. 2 and 15
e. 1 and 14
Q6 Which statement will generate random integers between 5 and 11
a. RND() * 5 + 6
b. Int(RND() * 5) + 6
c. Int(RND() * 5) + 11
d. Int(RND() * 6) + 5
e. Int(RND() * 7) + 5
Q7. Which of the following is CORRECT
dim arr(4) as integer
a. the size of the array is 4
b. ubound(arr) = 5
c. the last element of the array is represented as arr(ubound(arr))
d. lbound(arr) = 1
e. the last index of the array is 3
II Design Questions
Q1. Follow the execution of the following program and write down the output from the
statements. (show the memory chart and explain how it works)
Private Sub first()
Dim i, j As Integer
i = 3
j = 4
second(i, j)
txtAns.Text = txtAns.Text & vbNewLine & "j=" & j
End Sub
Private Sub second(ByVal u As Integer, ByRef v As Integer)
u = u - 1
v = u * 3
third(u, v)
txtAns.Text = txtAns.Text & vbNewLine & "u=" & u
End Sub
Private Sub third(ByRef a As Integer, ByVal b As Integer)
a = a + b
b = a * 2
txtAns.Text = txtAns.Text & vbNewLine & "b=" & b
Answer:
b:_______ u:____ j:_____
Q2. What will be the output in txtDisplay after the following statement block? Use the
following table to track the value of variables
Dim i, j, k As Integer
txtDisplay.text=””
For i = 1 To 5 step 3
For j = 3 To 4
For k=5 to 2 step -2
txtDisplay.text=txtDisplay.text & “x”
Next k
txtDisplay.text=txtDisplay.text & “y”
Next j
txtDisplay.text=txtDisplay.text & “z”
Next i
i
j
k
x
y
z
Answer: __________________
Write down the result in txtDisplay at the end? What’s is end value of i after quitting the
while loop? Write an equivalent FOR…NEXT loop that produces the same display result.
Q3.
Dim i As Integer
i = 2
Do While i <= 10
txtDisplay.text=txtdisplay.text & vbtab & i
i = i + 2
Loop
Q4 For calculating an exponential operation, two inputs are needed- the base and the
power. For instance, an exponential expression with a base of 2 and a power of 3 is
written as 2^3 and yields a result to 8. Complete the following program to produce the
exponential result using a general purpose user defined function. (hint: using byRef)
Private Sub btnMathGuru_click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim b,p as integer
b=input(“enter the base of the exponential expression)
p=input(“enter the power of the exponential expression)
lbldisplay.text = “The result of “ & b & “^” & p & “ is “ &
findExponential(___, ____)
‘the exponential expression for a base b with a power p is written as b^p
End Sub
Private function findExponential
Q5. In HW3 slot machine homework. How do you modify the following part of code to
make all three slot spin at the beginning (when totaltime=0) for 3 seconds. But slot 1
stops at the end of second 3, slot 2 stops at the end of second 4 and slot 3 at the end of
second 5, respectively, then the timer stops?
Original:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
totalTime = totalTime + Timer1.Interval
If totalTime < 3000 Then
d1 = Int(Rnd() * 5 + 1)
d2 = Int(Rnd() * 5 + 1)
d3 = Int(Rnd() * 5 + 1)
pic1.Image = System.Drawing.Bitmap.FromFile("g" & d1 & ".wmf")
pic2.Image = …
pic3.Image = …
Else
Timer1.Enabled = False
totalTime = 0
countMatch()
End If
Modified:
Q6. Create a lottery ticket program. The possible number range is from 1 to 44. A ticket
should consist of any 5 out of 44 numbers. The program will prompt the player for the
number of tickets and generate the numbers on a label with a ticket (containing 5
numbers) per line.
Private sub Generate_Lottery_ticket()
Remarks: Study thoroughly the exam review, Notes 4-6, Assignments HW3 and lottery
exercise.