Chapter_06_testbank
9 Pages

Chapter_06_testbank

Course Number: CIS 1121, Summer 2011

College/University: Albany Technical College

Word Count: 2131

Rating:

Document Preview

Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack Chapter 6 Multiple Choice Identify the letter of the choice that best completes the statement or answers the question. __a__ 1. If you want to prevent statements from outside a form from accessing a procedure, you set the access specifier to...

Unformatted Document Excerpt
Coursehero >> Georgia >> Albany Technical College >> CIS 1121

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Out Starting with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack Chapter 6 Multiple Choice Identify the letter of the choice that best completes the statement or answers the question. __a__ 1. If you want to prevent statements from outside a form from accessing a procedure, you set the access specifier to in the procedure's declaration. a. Private b. Public c. Static d. Scope 2. If a procedure is called more than once in a program, the values stored in the procedures local variables will persist only if declared with the keyword. a. Const b. Public c. Static d. Dim 3. A is a special variable in a Sub or Function heading that receives an argument's value/address from a calling procedure. a. temporary variable b. constant c. original argument d. parameter 4. Which one of the given procedure calls does not pass in valid arguments to the following GetANumber subprocedure? Sub GetANumber(ByVal intNumber as Integer) ' (procedure body) End Sub a. b. c. d. __B__ GetANumber(intX) GetANumber(3 + 5 * 8 + intX) GetANumber(intX + 3, intY) GetANumber(Cint(txtNumber.Text)) _C___ __D__ __C__ 5. When calling a procedure, the passed arguments and the declared parameters must agree in all of the following ways except one of the following. a. The order of arguments and parameters must correspond b. The names of the arguments and parameters must correspond c. The types of the arguments and parameters must correspond d. the number of arguments and the number of parameters must be the same Chapter 6 38 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack _D___ 6. Which of the following code examples is a correctly written function that will accept three integer parameters, calculate their average, and return the result? a. Private Function Average(intX As Integer, intY As Integer, _ int Z As Integer) As Single Average = (intX + intY + intZ) / 3 End Function b. Private Function Average(ByVal intX As Integer, ByVal intY _ As Integer, ByVal intZ As Integer) As Single Average = intX + intY + intZ / 3 Return Average End Function c. Private Function Average(ByRef intX As Integer, _ ByRef intY As Integer, ByRef intZ As Integer, ByRef Average _ As Double) Average = (intX + intY + intZ) / 3 End Function d. Private Function Average (ByVal intX As Integer, _ ByVal intY As Integer, ByVal intZ As Integer) As Single Return (intX + intY + intZ) / 3 End Function __C__ 7. What is incorrect about the following function? Public Function sum(ByVal intX As Integer, ByVal intY As Integer) As Integer Dim intAns As Integer intAns = intX + intY End Function a. intAns should not be declared inside the Function b. the Function heading should be replaced with: sum(ByVal intX As Integer, ByVal intY As Integer, _ ByRef intAns As Integer ) c. the function does not return a value d. parameters intA and intB should be ByRef parameters __A__ 8. What is assigned to lblDisplay.Text when the following code executes? Dim intNumber As Integer = 4 AddOne(intNumber, 6) lblDisplay.Text = intNumber ' Code for AddOne Public Sub AddOne(ByVal intFirst As Integer, ByVal intSecond As Integer) intFirst += 1 Chapter 6 39 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack intSecond += 1 End Sub a. b. c. d. __B__ 4 5 6 7 9. What is the value of intTotal after the following code executes? Dim intNumber1 As Integer = 2 Dim intNumber2 As Integer = 3 Dim intTotal As Integer intTotal = AddSquares(intNumber1, intNumber2) Public Function AddSquares(ByVal intFirst As Integer, ByVal intSecond As Integer) As Integer intFirst = intFirst * intFirst intSecond = intSecond * intSecond Return intFirst + intSecond intFirst = 0 intSecond = 0 End Function a. b. c. d. 0 5 10 13 ____ 10. (True/False) When debugging a program in break mode, Step Into command displays the source code within a subroutine that has just been called. a. True b. False __B__ 11. All of the following are true about functions except _________. a. you can use a function call in an expression b. they can return one or more values c. they must contain at least one Return statement d. you can assign the return value from a function to a variable _C___ 12. Which of the following does not apply to procedures and functions? a. they help to break up a large body of code into smaller chunks b. they make it easier to maintain and modify code c. the execution time is significantly reduced by calling procedures and functions d. they permit the same sequence of code statements to be called from multiple places __C__ 13. Which of the following procedures will keep track of the number of times it was called? Chapter 6 40 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack A. Private Sub KeepTrack( ByVal intCount As Integer) intCount += 1 lstResult.Items.Add(intCount) End Sub B. Private Sub KeepTrack ( ) Dim intCount As Integer = 0 intCount += 1 lstResult.Items.Add(intCount) End Sub C. Private Sub KeepTrack ( ) Static intCount As Integer = 0 intCount += 1 lstResult.Items.Add(intCount) End Sub D. Private Sub KeepTrack (ByVal intCount As Integer ) intCount += 1 lstResult.Items.Add(intCount) End Sub __A__ 14. Which statement is true in regard to passing an argument by value to a procedure? a. A copy of the argument is passed to the procedure. b. A reference to the argument is passed to the procedure. c. The procedure has access to the original argument and can make changes to it. d. The name of the argument and the parameter must be the same in order for the code to compile without a syntax error. __B__ 15. Which of the following examples correctly uses an input box to assign a value to an integer, and returns the integer to the calling program using a reference parameter? a. Public Sub GetInput( ByVal intNumber As Integer ) intNumber = CInt(InputBox("Enter an Integer")) End Sub b. Public Sub GetInput( ByRef intNumber As Integer ) intNumber = CInt(InputBox("Enter an Integer")) End Sub c. Public Sub GetInput( ByRef intNumber As Integer ) intNumber = CInt(InputBox("Enter an Integer")) Return intNumber End Sub d. Public Sub GetInput( ) Dim intNumber As Integer intNumber = CInt(InputBox("Enter an Integer")) End Sub __C__ 16. Which of the following functions accepts a parameter named dblSales and returns the commission to the calling program? Assume that the commission should equal the sales multiplied by the commission rate. Use the following table as a guide (we assume all amounts are rounded to two decimal 6 41 Starting places): Chapter Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack Sales less than 2,000 2,000 to 4999.99 5,000 to 9999.99 10,000 and over a. Commission Rate 10% 20% 30% 40% Public Function CalculateCommission(ByVal dblSales As _ Double, ByRef dblCommission As Double) Dim dblRate As Double Select Case dblSales Case Is <= 2000.0 dblRate = .1 Case 2001.0 To 5000.0 dblRate = .2 Case 5001.0 To 10000.0 dblRate = .3 Case Is > 10000 dblRate = .4 End Select DblCommission = dblRate End Function Public Function CalculateCommission(ByVal dblSales As _ Double) As Double Dim dblRate As Double, dblCommission as Double Select Case dblSales Case Is < 2000 dblRate = .1 Case 2000 To 5000 dblRate = .2 Case 5001 To 10000 dblRate = .3 Case Is > 10000 dblRate = .4 End Select dblCommission = dblRate * dblSales End Function Public Function CalculateCommission(ByVal dblSales As _ Double) As Double Dim dblRate As Double Select Case dblSales Case Is < 2000.0 dblRate = .1 Case 2000.0 To 4999.99 42 b. c. Chapter 6 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack dblRate = .2 Case 5000.0 To 9999.99 dblRate = .3 Case Is >= 10000 dblRate = .4 End Select Return dblRate * dblSales End Function d. Public Function CalculateCommission(ByVal dblSales As _ Double, ByRef dblCommission As Double) Dim dblRate As Double Select Case dblSales Case Is < 2000 dblCommission = .1 * dblRate Case 2000 To 5000 dblCommission = .2 * dblRate Case 5001 To 10000 dblCommission = .3 * dblRate Case Is > 10000 dblCommission = .5 * dblRate End Select End Function __A__ 17. Which debugging command executes a function call without tracing into the function's source code? a. Step Into b. Step Over c. Step Out d. Step All __A__ 18. When a procedure finishes execution, a. the application branches back to the point from where the procedure was called, and continues to the next program statement. b. the application terminates unless the procedure contains a Returns statement c. the application waits for the user to trigger the next event. d. the application enters break mode. _B___ 19. In the context of Visual Basic procedures and functions, what is an argument? a. A variable that a parameter is passed into. b. A value passed to a procedure or function when the latter is called. c. A local variable that retains its value between procedure calls. d. A reason not to create a procedure or function. Chapter 6 43 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack _C___ 20. When a parameter is declared using the ______ qualifier, the procedure has access to the original argument variable and may make changes its value. a. ByValue b. ByAddress c. ByRef d. ByDefault ____ 21. Which one of the following calls does not pass valid arguments to the GetANumber procedure? Sub GetANumber(ByVal intNumber As Integer) ' does some code End Sub a. b. c. d. __D__ a. b. c. d. GetANumber(intX) GetANumber(3 + 5 * 8 + intX) GetANumber(intX + 3, intY) GetANumber(Cint(txtNumber.Text)) 22. If you do not provide an access specifier for a procedure or function, then ... it will be Private it will be Protected it will be Friend it will be Public __A__ 23. What would be the value of the variable intShowNum the second time ShowLocalNum was called? Sub ShowLocalNum ( ) Dim intShowNum As Integer MessageBox.Show(intShowNum.Tostring) intShowNum = 10 End sub a. b. c. d. 0 1 10 cannot be determined __D__ 24. Which of the following can be returned by a function? a. String values b. nonnumeric values c. Boolean values d. All of the above __C__ 25. What syntax error is there in the following procedure? Sub DisplayValue( Dim intNumber As Integer ) This displays a value. MessageBox.Show( intNumber.ToString() ) End Sub Chapter 6 44 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack a. b. c. d. _A___ 26. a. b. c. d. ____ 27. intNumber cannot be converted to a string the procedure's scope must be declared Dim cannot be used in the parameter variable declaration all of the above are true Which is the correct general format to declare a variable that remains the same between procedure calls? Static variableName As DataType Dim variableName As Static VariableName As static = x Sub Static variableName ( ) What is wrong with the following GetName procedure? Sub GetName(ByVal strName As String) strName = InputBox("Enter your Name:") End Sub a. b. c. d. ____ 28. strName is a reserved word and cannot be used as a variable. GetName is a reserved word and cannot be used as a name of a procedure. strName will be modified, but all changes will be lost when the procedure ends. The syntax for the call to InputBox is incorrect. What will be the value of dblSum after the button btnAdd is clicked, assuming that 25 is entered by the user into txtNum1, and 35 is entered into txtNum2? Private Sub btnAdd_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnAdd.Click Dim dblNum1, dblNum2, dblSum As Double dblNum1 = CDbl(txtNum1.Text) dblNum2 = CDbl(txtNum2.Text) dblSum = Sum(dblNum1, dblNum1) lblSum.Visible = True lblSum.Text = dblSum.ToString() End Sub Function Sum(ByVal dblNum1 As Double, ByVal dblNum2 As Double) Return dblNum1 + dblNum2 End Function a. b. c. d. ___ 29. 60 50 0 70 Which statement is not true regarding functions? a. A function is a self contained code sequence to which you send input. Chapter 6 45 Starting Out with Visual Basic 2008, 4/E by Tony Gaddis/Kip Irvine TEST BANK Test Items prepared by George Dollar/Updated for 4/E by Iskandar Hack b. Visual Basic has many builtin functions such as Abs(x) c. Functions can return several values at the same time d. A function can only return a single value. ____ 30. Which is the correct way to define a function named Square that receives an integer and returns an integer represent ing the square of the input value? a. Function Square(ByVal intNum as Integer) As Integer Return intNum * intNum End Function Function Square(ByVal intNum) Return intNum * intNum End Function Function Square(ByVal intNum) As Double Return intNum * intNum End Function Function Square(ByVal intNum) As Double Dim dblAns as Double dblAns = intNum * intNum Return dblAns End Function b. c. d. ____ 31. What is the correct way to write to declare the variable intNumCalls in a function that keeps track of the number of times the function is called? a. b. c. Dim intNumCalls as Integer Dim intNumCalls as Static Integer Static intNumCalls as Integer You cannot do this in Visual Basic, so you must declare intCalls as a ClassLevel Variable d. Chapter 6 46
MOST POPULAR MATERIALS FROM Albany Technical College