Anda di halaman 1dari 4

Critical Thinking

1. > is only greater than 90 not equal to 90 otherwise it would be >=


2. The way this should be coded is like this:
Dim score As Integer = TextBox1.Text
If score >= 100 Then
Me.lblmessage.text = "You won!"
ElseIf score < 100 Then
Me.lblMessage.Text = "Good try."
End If
If score < 50 Then
Me.lblMessage.Text = "Practice more."
End If

3. A) Textbox allows the user to type in numbers and letters for the computer. A
checkbox will allow you to check things that you would like to add to say a
sandwich. A radio button will only allow you to select one of the radio
buttons.
B) A textbox should be used for a guess a number game. A checkbox would
be used for toppings on a sandwich. And the radio button would be used to
for a calculator to decide if you want it in a certain mode.

4. A) False
B) True
C) True
D) False
E) True
5. A)

If grade >= 90 then


Me.lblmessage.text = Great job
End if

B)
if totalpoints >= 100 and totalpoints <= 200 then
Me.lblHigh.text = High Scorer
End if
C)

If totalpoints > 100 Then


Messagebox.show( "Number must be less than 100")
End If

6. A) even, odd

B)

select case number mod 2


Case 0
Messagebox.show(Your number is even)
Case else
Messagebox.show(Your number is odd)
End Select

7. Wrong: If 50 <= numTickets <= 100 and _


Correct way: if numtickets.text <= 50 then

8. If Me.chkValue1.Checked And Me.chkValue2.Checked Then


MessageBox.Show("Both applied.")
End If

9.

If Val(Me.txtTest1.Text) >= 0 And Val(Me.txtTest1.Text) <= 100 And _


Val(Me.txtTest2.Text) >= 0 And Val(Me.txtTest2.Text) <= 100 And _
Val(Me.txtTest3.Text) >= 0 And Val(Me.txtTest3.Text) <= 100 Then 'valid
scores
average = (Val(Me.txtTest1.Text) + Val(Me.txtTest2.Text) +
Val(Me.txtTest3.Text)) / 3
Me.lblOutput.Text = average
Else
MessageBox.Show("All three scores must be between 0 and 100.")
Me.txtTest1.Text = Nothing
Me.txtTest2.Text = Nothing
Me.txtTest3.Text = Nothing
End if
10. if val(me.txtnum1.text) > val(me.txtnum2.text) then
Messagebox,show(First number is larger)
Elseif Val(me.txtnum1.text) < Val(me.txtnum2.text) then
Messagebox.show(second number is larger)
Else
Messagebox.show(Second number is larger)
endif
11.
Int(46 * Rnd() + 5)
12. A) end select is required o end the select.case statement (Not End Case)
A) Select Case num
Case 2, 3, Is > 10
messageBox.Show("1st Case")
Case 20 To 29
MessageBox.Show("2nd Case")
End Select
B) If num = 2 Or num = 3 Or num > 10 Then
MessageBox.Show("1st Case")
elseIf num >= 20 And num < 30 Then
MessageBox.Show("2nd Case")

End If
13. Select Case Me.txtMonth.Text
Case "JANUARY", "MARCH", "MAY", "JULY", "AUGUST", "OCTOBER", "DECEMBER"
MessageBox.Show("There are 31 days in this month.")
Case "APRIL", "JUNE", "SEPTEMBER", "NOVEMBER"
MessageBox.Show("There are 30 days in this month.")
Case "FEBRUARY"
If Val(Me.txtYear.Text Mod 4 <> 0) Then
MessageBox.Show("There are 28 days in this month.")
ElseIf Val(Me.txtYear.Text Mod 400 = 0) Then
MessageBox.Show("There are 29 days in this month.")
ElseIf Val(Me.txtYear.Text Mod 100 = 0) Then
MessageBox.Show("There are 28 days in this month.")
Else
MessageBox.Show("There are 29 days in this month.")
End If
Case Else
MessageBox.Show("Invalid entry.")
End Select

14. Private Sub btnPurchase_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnPurchase.Click
Const TICKET_COST As Decimal = 8
Static purchase As Integer = 0
Dim tickets As Integer
Dim totalCost As Decimal
purchase += 1
If purchase = 100 Then
MessageBox.Show("Congratulations, the tickets are free!")
purchase = 0
Else()
tickets = Val(Me.txtNumberTickets.Text)
totalCost = TICKET_COST * tickets
MessageBox.Show(totalCost)
End If
End Sub

15. Private Sub btnMessage_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnMessage.Click
Dim random As Integer
random = Int(100 * Rnd() + 1)
Select Case random
Case 1, 2 '2/100 = 2%
MessageBox.Show("You win $100.")
Case 3 To 12 '10/100 = 10%
MessageBox.Show("You win $10.")
Case 13 To 62 '50/100 = 50%
MessageBox.Show("You win $1.")
Case Else
MessageBox.Show("Thanks for trying.")
End Select

16. A) True.

b) False. The Else clause is optional.

c) True.
d) False. The Case Else clause is optional.
e) False. The Select...Case statement can be used for any number of
cases.
f) False. It will not produce an error, but the numbers generated from run
to run will not be different.
g) False. They are floating point numbers with a decimal portion.
h) False. Algorithms are designed before any code is written.
i) False. They are only retained if declared as Static.
j) True.
K) True.
l) False. Not is evaluated before And, which is evaluated before Or.
m) False. They can be used alone, anywhere.
n) True.
o) False. It is not in the form of a counter variable, which is counter +=
constant.
p) False. There is no limit to how many check boxes can be selected at
once.
q) False. The line continuation character may be used to split statements onto
multiple lines.

Anda mungkin juga menyukai