Programming Chapter 4 Review Worksheet
Name: ______Hour:______
True/False
Indicate whether the statement is true or false.
____1.The If…Then statement executes a set of statements when a condition is false.
____2.An example of a relational operator is And.
____3.Relational operators are used to form Boolean expressions.
____4.The indentation used in an If…Then…Else statement has an effect on the execution of the statement.
____5.A decision structure must have anElseclause.
____6.Aligning the If, the Else, and the End If statements in a decision structure and indenting the lines in between is a code convention that makes that statement easier to read.
____7.An If…Then…Else statement that contains another If…Then statement is said to be nested.
____8.A Select…Case statement uses the result of an expression to determine which block of code to execute.
____9.Rnd() generates random numbers greater than or equal to 0 and less than 1.
____10.Random numbers in a computer application are referred to as pseudorandom.
____11.Using Rnd() without including Randomize() will produce an error.
____12.Including the statementRnd(new) ensures a different sequence of random numbers will be generated each time the program is run.
____13.An algorithm is a set of steps that tell how to solve a problem.
____14.Algorithms are designed after the source code is created.
____15.Pseudocode consists of only program code.
____16.A static variable’s scope is local to the procedure in which it is declared, but its lifetime is the duration of the program.
____17.The lifetime of a global variable is the duration of the program.
____18.In logical expressions,Andis evaluated before Not.
____19.In logical expressions,Oris evaluated after Not and And.
____20.Operator precedence can be changed by using parentheses.
____21.Given the following statements:
Dim attendance As Integer = 8
Dim grade As Integer = 85
Determine the value, True or False, for the expression
Not attendance = 8
____22.Given the following statements:
Dim attendance As Integer = 8
Dim grade As Integer = 85
Determine the value, True or False, for the expression
attendance < 5 Or grade > 80
____23.A counter in an event procedure should be declared as aStaticvariable so that it is initialized only once.
____24.A counter variable can count backwards.
____25.A counter variable is a variable storing a number that is incremented by varying amounts.
____26.The statementnumAttempts += 1 updates the counternumAttemptsby 1.
____27.Only one check box can be selected at a time.
____28.Setting the Checked property of a CheckBox object to True displays an empty check box.
____29.Visual Basic statements must be placed within a single line.
____30.Dividing a statement into two or more lines of code is considered poor programming style.
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____31.Given the following statements:
If guess = selected Then
Me.lblMessage.Text="Correct"
Else
Me.lblMessage.Text="Incorrect"
End If
What is displayed when guess is 8 and selected is 9?
a. / Correctb. / Incorrect
c. / nothing would be displayed
d. / Correct on one line and Incorrect on the next line
____32.Given the following code segment:
Dim finished As Boolean = False
If finished Then
lblMessage.Text = "Game finished"
Else
lblMessage.Text = "Next round"
End If
Which will be displayed when the code segment is run?
a. / Falseb. / Game finished
c. / Next round
d. / A syntax error will be generated because finished is not a correct Boolean expression.
____33.Which statement should be used to decide among three or more actions?
a. / If…Then statement / c. / nested If…Then…Else statementb. / If…Then…Else statement / d. / If…Then…ElseIfstatement
____34.What kind of error do the following statements contain?
Dim grossPay As Decimal = 4250.50
If grossPay > 3000 Then
lblMessage.Text = "Your tax rate is 33%"
ElseIfgrossPay > 4000
lblMessage.Text ="Your tax rate is 35%"
End If
a. / a semantic error / c. / a run-time errorb. / a syntax error / d. / an exception error
____35.Given the following statements:
Dim experience As Integer = 10
If experience > 5 Then
Me.lblMessage.Text="Sufficient Experience"
Else
Me.lblMessage.Text="Inexperienced"
End If
What is displayed when the statements execute?
a. / Sufficient Experienceb. / Inexperienced
c. / nothing would be displayed
d. / Sufficient Experience on one line and Inexperienced on the next line
____36.Given the following statements:
Select Case quantity
Case Is < 10
Me.lblMessage.Text = "Quantity is too low."
Case Is < 20
Me.lblMessage.Text = "Quantity is in the correct range."
Case Is >= 20
Me.lblMessage.Text = "Quantity is too high."
End Select
What message would be displayed if quantity is 20?
a. / Quantity is too low.b. / Quantity is in the correct range.
c. / Quantity is too high.
d. / No message would be displayed.
____37.Given the following statements:
Select Case bestPrice
Case Is < 10
Me.lblMessage.Text = "Price is too low."
Case Is < 20
Me.lblMessage.Text = "Price is in the correct range."
Case Is >=20
Me.lblMessage.Text = "Price is too high."
End Select
What message would be displayed ifbestPriceis 16?
a. / Price is too low. / c. / Price is too high.b. / Price is in the correct range. / d. / No message would be displayed.
____38.Using Rnd() alone generates random numbers
a. / less than or equal to 0.b. / greater than or equal to 0 and less than 1.
c. / greater than or equal to 0 and less than or equal to 1.
d. / greater than or equal to 1.
____39.The statementMe.lblRandNum.Text = Rnd()*100 generates random numbers
a. / less than or equal to 100.b. / greater than or equal to 0 and less than 100.
c. / greater than or equal to 100.
d. / greater than or equal to 1 and less than or equal to 100.
____40.Which statement generates random numbers greater than or equal to 10 and less than 51?
a. / Rnd() * 41 / c. / 51 * Rnd() + 10b. / 10 * Rnd() + 51 / d. / 42 * Rnd() + 10
____41.Which statement is included in the beginning of an event procedure to initialize the Rnd() function so that different random numbers are generated from run to run?
a. / Initialize() / c. / Randomize()b. / Random() / d. / RndInt()
____42.Which is not a logical operator?
a. / And / c. / Notb. / Or / d. / If
____43.Which statement displays the following message box?
a. / MessageBox.Show("Try again") / c. / Show.Message("Try again")b. / MessageBox.Display("Try again") / d. / Message.Show("Try again")
____44.Which statement correctly updates the counter amount?
a. / amount = amount + 1 / c. / amount = value + 1b. / value = amount + amount / d. / value = amount + value
____45.Which is used to place related check boxes together?
a. / Label / c. / ListBoxb. / GroupBox / d. / TextBox