Expert Answers

List and describe three advantages of creating modular code.

Assume the file MONTHS.TXT contains 12 records, the names of each month in a calendar year. What is stored in RESULTS.TXT after the following code is executed?

Dim monthName As String
Dim sr As IO.StreamReader = IO.File.OpenText(“MONTHS.TXT”)
Do While sr.Peek -1
Dim sw As IO.StreamWriter = IO.File.CreateText(“RESULTS.TXT”)
monthName = sr.ReadLine

The names of all 12 months
None of the above

Given var1 = 7 and var2 = 5, what value will be assigned to the Double variable final Answer when the following statement is executed?

final Answer = (3 * var1 + 3 * var2) / (var1 – var2) * 3



Consider the following statement:
A computer program must figure out if a student has passed a course based on the percentage of points earned. Which of the following is the appropriate structure to use to program the statement?

What numbers will be displayed by the following code?
Dim q As Integer = 9
q += 1
Loop Until (q > 12)

10, 11, and 12
10, 11, 12, and 13
10, 11, 12, 13, and 13

What is displayed when the following code is executed?

Sub Main()

Dim val1, val2 As String
Dim z As Integer = 1

val1 = “Run dog run”
val2 = “dog”

z = Locate(val1, val2)

End Sub

Function Locate(ByVal a As String, ByVal b As String) As Integer
Dim z As Integer
z = a.IndexOf(b)
End Function

An error
None of the above


Consider the following Visual Basic code segments:

Segment 1:

Dim i As Integer = 0
While i <= 85
Console.WriteLine ( i.ToString(“N0”) )
i += 1
End While

Segment 2:

For i As Integer = 0 To 85 Step 2
Console.WriteLine ( i.ToString(“N0”) )

Which of the following statements is true?

The output from these segments is the same.
Declaring the counter inside a for loop is illegal.
The output from these segments is not the same.
None of the above

What is wrong with the following call statement and its corresponding sub statement?

Call Statement:
DayOfTheWeek(31, “July”, 1982)
Sub Statement:
Sub DayOfTheWeek(ByVal var1 As Integer, ByVal var2 As String, ByVal var3 As String)

Constant values like 1982 cannot be passed, only variables.
It is not valid to pass a value like “July.”
var3 is not of the same data type as 1982.
Nothing is wrong with them.


Provide a small piece of code that contains a syntax error. Explain how a programmer might find/correct it.

(TCO 5) Assume that var1 and var2 are Integer variables. Describe precisely the output produced by the following segment for the test inputs -4 and 2.

Dim var1 As Integer
Dim var2 As Integer = 0

var1 = CInt(System.Console.ReadLine())
Do While (var1 > var2)
var1 = var1 – 1

(TCO 5) Write a pretest Do Loop that will implement the following logic:

1. Obtain 10 numbers from the user.
2. Compute the average of those numbers.
3. Display the calculated average.

(TCO 4) Assume a user will input the number of hours an employee worked during a week and the employee’s hourly pay. The employee will be paid 1.5 times that rate for any hours worked over 40 hours. Write the VB code to calculate the employee’s gross pay for that week.

Give a description of the method OpenText(). Make sure to include the following:

1. The purpose of the method (in other words, what it does)
2. An appropriate situation when you would use it in code
3. Sample code showing the syntax of how it is used in Visual Basic programs

(TCO 11) Use the following code to complete parts (a) and (b).

Dim a(10) As Double
For i As Integer = 0 To 10
a(i) = i * i
For i As Integer = 0 To 5
a(i) = a(i + 5)

(a) What is the value of a(8) after this code executes? Please explain.
(b) What is the value of a(4) after this code executes? Please explain.