Programming 1 final exam review 5
In the code below, if Button1 is repeatedly clicked, how often will MessageBox.Show display the string "Only 0 and 3"? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gen As New System.Random() Dim intX As Integer intX = gen.Next(4) + 1 Select Case intX Case 0 MessageBox.Show("Spades") Case 1 MessageBox.Show("Hearts") Case 2 MessageBox.Show("Clubs") Case 3 MessageBox.Show("Diamonds") Case 4 MessageBox.Show("other") Case 1, 2 MessageBox.Show("a 1 or 2") Case 0 To 4 MessageBox.Show("Only 0 and 3") End Select End Sub
0% of the time
If 5 and 2 are entered in txtNumber1 and txtNumber2, respectively, what will the following code display? Dim intNumber1 As Integer= Convert.ToInt32(txtNumber1.Text) Dim intNumber2 As Integer= Convert.ToIn32(txtNumber2.Text) Dim intResult As Integer intResult= intNumber1 Mod intNumber2 lblAnswer.Text= intResult.ToString()
1
Typically, accumulators and counters are initialized to what value?
1
In the code below, if the user enters 5 into the TextBox1, the MessageBox will display: Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim intX As Integer Dim dblD As Double = 50.0 Try intX = Convert.ToInt32(TextBox1.Text) dblD = dblD / intX Messagebox.Show(dblD.ToString()) Catch ex As Exception Messagebox.Show("Sorry, not allowed!") End Try End Sub
10
In the code below, when the MessageBox is displayed, the variable intJ will be: Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do intTot += gen.Next(0, 101) intJ += 2 Loop While intJ < 10 MessageBox.Show(intTot) End Sub
10
When the MessageBox is displayed in the code below, the variable intJ will be: Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random Dim intTot As Integer Dim intJ As Integer = 0 Do while intJ < 10 intTot += gen.Next(0, 101) intJ += 2 Loop MessageBox.Show(intTot) End Sub
10
Given the following statements: Dim intNum As Integer For intNum = 1 To 11 MessageBox.Show(intNum) Next intNum What is the value of intNum after the last loop iteration?
12
In the code below, if the Random Number generator is fair, the value in intTot after the loop completes, on average, will tend to be close to: Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do While intJ < 10 intTot += gen.Next(0, 101) intJ += 2 Loop MessageBox.Show(intTot) End Sub
250
In the following code, how many times does the program execute the loop body? For intCounter as integer = 1 To 9 Step 3
3
In the code below, the for loop has how many iterations? Dim gen As New System.Random() Dim intGrade, intSum, intX As Integer For intX = 0 To 6 Step 2 intGrade = gen.Next(60, 100) intSum += intGrade Next intX MessageBox.Show(intSum)
4
Given the following statements: Dim intNum As Integer = 0 Do intNum = intNum + 1 Loop While intNum < 5 How many times will the body of the Do ... Loop execute?
5
In the code below, how many iterations will the loop execute? Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do While intJ < 10 intTot += gen.Next(0, 101) intJ += 2 Loop MessageBox.Show(intTot) End Sub
5
In the code below, how many times will the loop execute? Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do intTot += gen.Next(0, 101) intJ += 2 Loop While intJ < 10 MessageBox.Show(intTot) End Sub
5
In the following code, how many times does the program execute the loop body? For intCounter as integer = 1 To 5
5
Apex High-Semester 1 Announcements Modules Unit 5 Final Exam Review Due No due date Points 58 Questions 58 Time Limit None Allowed Attempts Unlimited Take the Quiz Again Attempt History Attempt Time Score KEPT Attempt 2 29 minutes 57 out of 58 LATEST Attempt 2 29 minutes 57 out of 58 Attempt 1 1,280 minutes 47 out of 58 Correct answers are hidden. Score for this attempt: 57 out of 58 Submitted Jan 7 at 2:37pm This attempt took 29 minutes. Question 1 1 / 1 pts Examine the code below. What value is stored in intResult after the loop executes? Dim intCount As Integer Dim intResult As Integer For intCount = 0 to 11 Step 2 intResult= intResult + 1 Next intCount
6
Given the following statements: Dim intNum As Integer For intNum = 1 to 5 MessageBox.Show(intNum) Next intNum What is the value of intNum after the last loop iteration?
6
In the code below, the For loop has how many iterations? Dim gen As New System.Random() Dim intGrade, intSum, intCount As Integer Dim dblAvg As Double For intCount = 0 To 6 intGrade = gen.Next(60, 100) intSum += intGrade Next intCount dblAvg = intSum / (intCount - 1) MessageBox.Show(dblAvg.ToString("###.00"))
7
In the code below, what is the value stored in intCount when the MessageBox is displayed? Dim gen As New System.Random() Dim intGrade, intSum, intCount As Integer Dim dblAvg As Double For intCount = 0 To 6 intGrade = gen.Next(60, 100) intSum += intGrade Next intCount dblAvg = intSum / (intCount - 1) MessageBox.Show(dblAvg.ToString("###.00"))
7
In the code below, what is the value stored in intX when the loop terminates? Dim gen As New System.Random() Dim intGrade, intSum, intX As Integer For intX = 0 To 6 Step 2 intGrade = gen.Next(60, 100) intSum += intGrade Next intX MessageBox.Show(intSum)
8
Which logical condition will determine if the AccountBalance is not less than CreditLimit ?
AccountBalance >= CreditLimit
Alice wrote a program that executed but did not produce the expected output. What is the best method for Alice to use to find the error?
Add breakpoints and step through the code while watching the variable output
A meat packer grades meat "P" for Prime, "C" for Choice, "S" for Standard, and "G" for Good. Which case expression will represent Choice meat?
Case "C"
Which case condition is correct?
Case 10
Which condition is correct?
Case 2, 5
What is the correct syntax for a pretest Do Loop?
Do While <condition> <statements> Loop
Which type of error produces undesired or unexpected results?
Logic error
In the code below, determine the value of intJ displayed in the MessageBox . Dim intJ As Integer = 0 Dim intK As Integer = 0 Do While intJ < 10 Do While intK < 5 intK -= 1 Loop intJ += 1 Loop MessageBox.Show(intJ.ToString())
MessageBox will not display due to an infinite loop
When the code is completely written but will not execute, what is the appropriate action?
Perform programmer debugging and/or program debugging.
In the code below, the Do Loop is a: Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do While intJ < 10 intTot += gen.Next(0, 101) intJ += 2 Loop MessageBox.Show(intTot) End Sub
Pretest loop
In the code below, if the user enters "thirtyseven" into TextBox1, the MessageBox will display what? Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim intX As Integer Try intX = Convert.ToInt32(TextBox1.Text) Messagebox.Show(intX) Catch ex As Exception Messagebox.Show("Sorry, that is not a valid number, try again!") End Try End Sub
Sorry, that is not a valid number, try again!
In the code below, if the line of code intJ += 2 were changed to intJ -= 2, what would be the result? Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do intTot += gen.Next(0, 101) intJ += 2 Loop While intJ < 10 MessageBox.Show(intTot) End Sub
The program would lock up in an infinite loop.
What is a purpose of the Watch window?
To examine values during the execution of a program
Grades are based on the scale below. Using this scale, which condition(s) would be used to identify students who made a "B"? A 93-100 B 85-92 C 78-84 D 70-77 F 0-69
dblScore > = 85 And dblScore < 93
Grades are based on the scale below. Using this scale, which condition(s) would be used to identify students who made an "A" or a "B"? A 93-100 B 85-92 C 78-84 D 70-77 F 0-69
dblScore >= 85
The reason to use a breakpoint is to:
examine variables and check logic
Evaluate the code below. If intX is 1 and intY is 0, what is displayed in the MessageBox? Private Sub btn1_Click(ByVal sender as System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen as New System.Random() Dim intX, intY As Integer intX = gen.Next(2) intY = gen.Next(2) if intX = 0 Or intY = 0 Then MessageBox.Show("False") ElseIf intX = 1 Or intY = 1 Then MessageBox.Show("True") Else MessageBox.Show("Unknown")
false
If the 12 months are numbered 1 through 12, which statement generates a random whole number to represent one of the months, given the following code? Dim gen As New System.Random()
gen.Next(1,13)
If there are 6 sides on a die, which statement generates a random whole number to represent one of the sides, given the following code? Dim gen As New System.Random()
gen.Next(1,7)
If the 7 weekdays are numbered 1 through 7, which statement generates a random whole number to represent one of the days, given the following code? Dim gen As New System.Random()
gen.Next(1,8)
Which statement generates random whole numbers greater than or equal to 10 and less than 51, given the following code? Dim gen As New System.Random()
gen.Next(10, 51)
Given the following statements: If intGuess=intSelected Then lblMessage.Text="Correct" Else lblMessage.Text="Incorrect" End If What is displayed when intGuess is 11 and intSelected is 15?
incorrect
North Carolina allows a teenager to have a learner's permit if he/she is 15 and has had driver's education training. Consider the intAge and blnHasHadDrivEd variables. Which of the following If conditions would allow a learner's permit?
intAge >= 15 And blnHasHadDrivEd = True
In the code below, which variable is the loop counter? Dim gen As New System.Random Dim intGrade, intSum, intCount As Integer Dim dblAvg As Double For intCount = 0 To 6 intGrade = gen.Next(60, 100) intSum += intGrade Next intCount dblAvg = intSum / (intCount - 1) MessageBox.Show(dblAvg.ToString("###.00"))
intCount
In the code below, which variable is the accumulator? Dim gen As New System.Random() Dim intGrade, intSum, intCount As Integer Dim dblAvg As Double For intCount = 0 To 6 intGrade = gen.Next(60, 100) intSum += intGrade Next intCount dblAvg = intSum / (intCount - 1) MessageBox.Show(dblAvg.ToString("###.00"))
intSum
Sara thought her program would calculate grade point averages, but the program listed the highest grade instead. What type of error is this?
logic error
In the code below, if the Button1 is repeatedly clicked, how often will MessageBox.Show display the string "a 1 or 2"? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gen As New System.Random() Dim intX As Integer intX = gen.Next(4) + 1 Select Case intX Case 0 MessageBox.Show("Spades") Case 1 MessageBox.Show("Hearts") Case 2 MessageBox.Show("Clubs") Case 3 MessageBox.Show("Diamonds") Case 4 MessageBox.Show("other") Case 1, 2 MessageBox.Show("a 1 or 2") Case 0 To 4 MessageBox.Show("Only 0 and 3") End Select End Sub
never
What type of Do Loop is executed by the code below? Private Sub btn1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen As New System.Random() Dim intTot As Integer Dim intJ As Integer = 0 Do intTot += gen.Next(0, 101) intJ += 2 Loop While intJ < 10 MessageBox.Show(intTot) End Sub
posttest loop
In what type of loop are the conditions evaluated before the instructions are processed?
pretest
John's computer program stopped executing and displayed an error message. What type of error is this?
runtime error
Which type of error halts the program when a statement cannot be executed?
runtime error
What are the 3 categories of errors
runtime, logic, syntax
In the code below, if the user enters zero (0) into TextBox1, the MessageBox will display which message? Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim intX As Integer Dim dblD As Double = 50.0 Try intX = Convert.ToInt32(TextBox1.Text) dblD = dblD / intX MessageBox.Show(dblD.ToString()) Catch ex As Exception MessageBox.Show("Sorry, not allowed.") End Try End Sub
sorry, not allowed
In the code below, which suit will never be selected? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gen As New System.Random Dim intX As Integer intX = gen.Next(4) + 1 Select Case intX Case 0 MessageBox.Show("Spades") Case 1 MessageBox.Show("Hearts") Case 2 MessageBox.Show("Clubs") Case 3 MessageBox.Show("Diamonds") Case 4 MessageBox.Show("other") Case 1, 2 MessageBox.Show("a 1 or 2") Case 0 To 4 MessageBox.Show("Only 0 and 3") End Select End Sub
spades
Given the following statements: Dim intExperience As Integer = 10 If intExperience > 5 Then lblMessage.Text="Sufficient Experience" Else lblMessage.Text="Inexperienced" End If What is displayed when the statements execute?
sufficient experience
Jamie keyed "Interger" instead of "Integer". What type of error resulted?
syntax error
Misspelling a keyword is an example of a:
syntax error
If the user clicks on btn1 in the code below: Private Sub btn1_Click(ByVal sender as System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim gen as New System.Random() Dim intX As Integer intX = gen.Next(2) if intX = 0 Then btn1.Visible = False ElseIf intX = 1 Then btn1.Visible = True Else MessageBox.Show("intX is: " & intX) End If End Sub
the button may become invisible