

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


1. Understanding an Array Program
a. In Monday’s temperatures program, suppose that the input file had the following temperatures. 5 10 20 10
After the user clicks the button, “Read Temperatures from File”, here are the values of these variables. Note that with 4 numbers, the array subscripts from 0 to 3 are being used for numbers. The rest of the array is not used. Variable Value temperatures(0) 5 temperatures(1) 10 temperatures(2) 20 temperatures(3) 10 temperatures(4) ---
... --- numtemps 4
b. Without running the program, think about the values of the variables during the execution of the button procedure for the “Highest Temperature” button. Here is that part of the program: Dim high As Single Dim index As Integer ' initialize the high so far to be the first element high = temperatures(0) ' loop over the remaining array and find the highest For index = 1 To numtemps - 1 ' if the temp is higher than the high so far, make it the new high If (temperatures(index) > high) Then high = temperatures(index) End If Next Write here the values of the variables index and high before and during the loop. What is the last index number that is used? Are there too many spaces here?
Variable Before loop
Loop iteration 1
Loop iteration 2
Loop iteration 3
Loop iteration 4
Loop iteration 5 .. index ------ high
2. Understanding How to Write a Procedure Call
Suppose that we have a form with a general procedure defined at the top of the form:
Public Class Form ‘ This procedure takes the number of units, ‘ computes the total price using a fixed price of $2.50, ‘ and displays the result in a textbox Private Sub DisplayPrice ( ByVal units as Integer, ByRef tb as TextBox) Dim price as Single = 2. Dim total as Single
total = units * price tb.Text = “Total = “ & Format(total, “currency”) End Sub …. End Class
Suppose that the form has a textbox named TextBox1 and in a button click procedure, we have a variable declared and given a value: Dim number as Integer number = 10
a. Write a valid procedure call to DisplayPrice that could occur in the procedure using the variable “number” as one of the parameters:
b. With the procedure call that you wrote in part a, write what output will be given in TextBox1: