1. (2 Points) Using a with Block Structure, Complete the Statements to Read The

1. (2 Points) Using a with Block Structure, Complete the Statements to Read The

CSC 110 TEST 2CODING PROBLEMS10/27/2018

Name______

1. (2 points) Using a With Block structure, complete the statements to read the

arguments strName, and dblWage from the data file Employee.txt opened with the following statement: Dim sr as IO.StreamReader = IO.File.OpenText(“Employee.Txt”). (Remember to use a conversion function if needed)

Dim sr as IO.StreamReader = IO.File.OpenText(“Employee.Txt”)
Private sub btnGetData.Click(…)Handles btnGetData.click
Dim strName as String, dblWage as Double
With sr
End With
End Sub

2. (2 points)When executing the btnDisplay click event the programmer wants the program to print sngAnswer to txtDisplay.text if sngAnswer is less than or equal to 100. Write code that will ensure the desired outcome.

Private Sub btnDisplay_Click(…) Handles btnDisplay.Click
Dim sngAnswer as Single = 0
sngAnswer = Cdbl(InputBox(“Enter your answer”))
End Sub

3. (6 Points) A program request that the user enter a value for the TotalCosts and TotalRevenue for a company (txtTotalCost, txtTotalRevenue) and displays a Message to the screen in the following situations

If totalcosts equal to totalrevenue the message is “Break Even”
If totalcosts is greater the totalrevenue the message is “Loss”
If totalcosts is less than totalrevenue the message is “Profit”

Complete the following btnDisplay event. Dimension all needed arguments and use an IF Then ElseIF structure.

Private Sub btnDisplay_Click(…) Handles btnDisplay.Click
Dim sngTotalCosts as Single = CSng(txtTotalCost.text)
Dim sngTotalRevenue as Single = CSng(txtTotalRevenue.text)
IF sngTotalCosts = sngTotalRevenue then
MsgBox “Break Even”
ElseIf sngTotalCosts > sngTotalRevenue then
Msgbox “Profit”
Else
Msgbox “Loss”
End if
End Sub

4. (3 points) The three rules for passing arguments state that

1. you must pass the same ______

  1. they must be in the same ______
  2. and they must be the same ______
  1. Complete this phrase: (2 points) A counter is an argument used to

______

  1. Complete this phrase: (2 points) An accumulator is an argument used to ______
  2. (10 Points)At the Movie House the tickets are sold by age

Age / Ticket Price
Age 6 and under / $0.00
Age 7 to 12 / $5.00
Age 13 to 17 and over 60 / $5.50
Age 18 to 60 / $6.00

Use a Select Case structure and write a btnGetPrice procedure that finds the price for tickets based on the table above. Show the price of the tickets in the textbox txtPrice after you find the right price. Complete the following code…..

Private Sub btnGetPrice_Click(…) Handles btnGetPrice.Click

Dim Age, Price as Double

Age = Cdbl(InputBox(“Input Age”)

Select Case Age

Case is < 6

Price = 0

Case 6 to 12

Price = 5.00

Case 13 to 17 and > 60

Price = 5.50

Case Else

Price = 6.00

End Select

txtPrice.Text = “The Price is “ & FormatCurrency(Price)

End sub

(3 points) For each of the argument Age values (8,12,21,4) Indicate in the box below the value of Price.

Age / 8 / 12 / 21 / 4

Identify the error in the following Code: (2 points Each)

  1. Private sub btnDisplay_Click() Handles btnDisplay.Click

Dim dblVariable1 as Double = .5

If (1 < dblVariable and < 3 Then

txtOutput.Text = “Number is between 1 and 3.”

End if

End Sub

  1. Private sub btnDisplay_Click() Handles btnDisplay.Click

Dim dblVariable1 as Double = .5

Dim dblVariable2 as Double = 1

If (dblVariable > dblVariable2)

txtOutput.Text = “Number are not equal.”

End if

End Sub

  1. Private sub btnDisplay_Click() Handles btnDisplay.Click

‘Display “OK” if either j or k equal 4

Dim j as Double = 2

Dim k as Double = 3

If j or j = 4 then

txtOutput.Text = “OK”

End if

End Sub

Simplify (rewrite) the following code to make it easier to understand. (2 points)

  1. If (j = 7) then

B = 1

Else

If (j > 7) then

B = 2

End if

End if

  1. If (a< b) then

If (b < c) then

txtOutput.Text = b & “ is between “ & a & “ and “ & c

End if

End if