MIC 110 Quiz 4 Name: ____________________________

advertisement

MIC 110

Quiz 4

Name: ____________________________

Write down your name in block letters in the upper-right corner of this page.

1.

Assume there is no syntax error, e.g. intRuner1 instead of intRun1. Circle around the error, and correct the error or insert a missing code in the following codes (1 point). Focus on the user-defined procedure.

Then explain why ( 19 points ).

Private Sub btnActivate_Click ( . . . )

Dim intRun1, intRun2, intTotalRuns As Integer

intRun1 = 5

intRun2 = 7

AddRuns (intRun1, intRun2, intTotalRuns)

MsgBox (intTotalRuns.ToString)

End Sub

Private Sub AddRuns ( ByVal intNum1 As Integer , ByVal intNum2 As Integer , ByVal intTotalNums As Integer )

intTotalNums = intNum1 + intNum2

End Sub

Explanation:

2.

Assume there is no syntax error, e.g. intRuner1 instead of intRun1. Circle around the error, and correct the error or insert a missing code in the following codes (1 point). Focus on the user-defined procedure.

Then explain why ( 19 points ).

Private Sub btnActivate_Click ( . . . )

Dim intRun1, intRun2 As Integer

Dim sngTotalRuns As Single

intRun1 = 10

intRun2 = 2

sngTotalRuns = DivideRuns (intRun1, intRun2)

MsgBox (sngTotalRuns.ToString )

End Sub

Private Function DivideRuns ( ByVal intNum1 As Integer , ByVal intNum2 As Integer ) As Single

Dim sngTotalRuns As Single

sngTotalRuns = ( intNum1 / intNum2 )

End Function

Explanation:

3.

Determine the value of intTotal displayed in the message box once the following codes are executed ( 10 points ). What will be the number iterations of the loop (the number of times the loop will execute the codes inside of the loop)? Explain ( 10 points ).

Dim intCounter As Integer

Dim intTotal As Integer = 0

For intCounter = 1 To 5 Step 2

intTotal = intTotal + 10

Next intCounter

MsgBox(intTotal.ToString)

4.

Determine the value of intTotal displayed in the message box once the following codes are executed ( 10 points ). What will be the number iterations of the loop (the number of times the loop will execute the codes inside of the loop)? Explain ( 10 points ).

Dim intCounter As Integer = 0

Dim intTotal As Integer = 0

Do While intCounter < 5

intCounter = intCounter + 2

intTotal = intTotal + 10

Loop

MsgBox(intTotal.ToString)

5.

Write a user-defined (sub) procedure or function that returns an average temperature of five cities (each city reports one temperature). Your codes should read in the temperatures by using the InputBox function within a loop ( 20 points ).

Download