This preview has intentionally blurred parts. Sign up to view the full document

View Full Document

Unformatted Document Excerpt

6 Multiple Chapter Choice Identify the letter of the choice that best completes the statement or answers the question. ____ 1. If you want to prevent statements from outside a form from accessing a procedure, you set the access specifier to in the procedures declaration. a. b. c. d. ____ Private Public Static 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 a. Const b. Public c. Static d. Dim keyword. ____ 3. A from a calling procedure. a. temporary variable b. constant c. original argument d. parameter is a special variable in a Sub or Function heading that receives an arguments value/address ____ 4. Which of the following calls does not pass in valid arguments to the following GetANumber subprocedure? Sub GetANumber(ByVal intNumber as Integer) ' does some code End Sub a. b. c. d. ____ GetANumber(intX) GetANumber(3 + 5 * 8 + intX) GetANumber(intX + 3, intY) GetANumber(Cint(txtNumber.Text)) 5. When calling a Sub Procedure, the arguments and the corresponding 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 type the arguments and parameters must correspond d. the number of the arguments and the parameters must be the same Chapter 6 1 ____ 6. Which of the following code is a correctly written function named Average that will accept three integers as parameters, calculate their average and return the result. a. Private Function Average(intX As Integer, intY As Integer, intZ 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 ByVal intZ As Integer) As Single Return (intX + intY + intZ) / 3 End Function d. Private Function Average (ByVal intX As Integer,ByVal intY As Integer, _ ____ 7. What is wrong with the following function? Public Function sum( ByVal intA As Integer, ByVal intY As Integer) As Integer Dim intAns As Integer intAns = intX + intY End Function a. intAns should not be declared in the Function b. the Function heading should be replaced with: sum(ByVal intA As Integer, ByVal intY As Integer, ByRef intAns As Integer ) c. the Function does not return a value d. parameters a and b should be ByRef parameters ____ 8. What is displayed in lblDisplay if the following code is executed? Dim intNumber As Integer = 4 AddOne(intNumber, 6) lblDisplay.Text = intNumber ' Code for AddOne Public Sub AddOne(ByVal intFirst As Integer, ByRef intSecond As Integer) intFirst += 1 intSecond += 1 End Sub a. 4 b. 5 c. 6 2 d. 7 Chapter 6 3 ____ 9. What is the value of intTotal after the following code is executed? 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. In break mode, pressing a. F5 b. Ctrl F5 c. F8 d. Shift F8 will activate the Step Into command. ____ 11. All of the following are true about functions except a. you can use a function call in an expression b. you can return one or more values to the calling procedure/function c. you need to have a return statement in a function d. you can assign the return value from a function to a variable ____ 12. Which of the following does not apply to using Sub procedures and functions? a. b. c. d. you can modularize an applications code it will make it easier to maintain and modify code the execution time is significantly reduced you can write code once, and have it performed in many places 4 ____ 13. Which of the following is a Sub procedure that will keep track of the number of times it was called? a. Private Sub KeepTrack( ByVal intCount As Integer) intCount += 1 lstResult.Items.Add(intCount) End Sub Dim intCount As Integer = 0 intCount += 1 lstResult.Items.Add(intCount) End Sub Static intCount As Integer = 0 intCount += 1 lstResult.Items.Add(intCount) End Sub Dim intCount As Integer = 0 intCount += 1 lstResult.Items.Add(intCount) End Sub b. Private Sub KeepTrack ( ) c. Private Sub KeepTrack ( ) d. Private Sub KeepTrack (ByRef intCount As Integer ) ____ 14. What does it mean to pass an argument to a procedure by value? a. that only a copy of the argument is passed to the procedure b. the address of the argument is actually passed to the procedure c. the procedure has access to the original argument and can make changes to it. d. the name the of argument and the parameter must be the same in order to send data to the sub procedure ____ 15. Which of the following is a correctly written Sub procedure that uses an input box to get an integer, which is returned to the calling program? 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 intNumber = CInt(InputBox(Enter an Integer)) Return intNumber End Sub Dim intNumber As Integer intNumber = CInt(InputBox(Enter an Integer)) End Sub c. Public Sub GetInput( ByRef intNumber As Integer) d. Public Sub GetInput ( ) Chapter 6 5 6 ____ 16. Which of the following functions accepts a parameter named dblSales, and returns the commission to the calling program where commission is dblSales * dblCommission rate, based on the following table? Sales < 2,000 2,000 through 5,000 5,001 through 10,000 > 10,000 Commission Rate 10% 20% 30% 40% a. Public Function CalculateCommission(ByVal dblSales As Double, _ ByRef dblCommission As Double) Dim dblRate 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 End Function b. Public Function CalculateCommission(ByVal dblSales As Double) As Double Dim dblRate 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 c. Public Function CalculateCommission(ByVal dblSales As Double) As Double Dim dblRate As Double Select Case dblSales Case Is < 2000 dblRate = .1 Chapter 6 7 Case 2000 To 5000 dblRate = .2 Case 5001 To 10000 dblRate = .3 Case Is > 10000 dblRate = .4 End Select Return dblRate* dblCommission 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 ____ 17. Which VB debugging command will allow the programmer to execute all of the procedures/functions in the program? a. Step Into b. Step Over c. Step Out d. Step All ____ 18. When a Sub procedure has finished executing a. b. c. d. the application branches back to the procedure call, and resumes executing at the next line. the application terminates. the application waits for the user to trigger the next event. the application enters break mode. 1. 2. 8 ____ 19. What is an argument? a. b. c. d. A variable that a parameter is passed into. A value passed to a procedure or function when it is called. A local variable that retains its value between procedure calls. A reason not to create a procedure or function. ____ 20. When an argument is passed to a procedure this way, the procedure has access to the original argument and may make changes to it. a. ByValue b. ByAddress c. ByRef d. ByDefault ____ 21. Which of the following calls does not pass in valid arguments to the following GetANumber Sub Procedure? Sub GetANumber(ByVal intNumber As Integer) ' does some code End Sub a. b. c. d. GetANumber(intX) GetANumber(3 + 5 * 8 + intX) GetANumber(intX +3, intY) GetANumber(Cint(txtNumber.Text)) ____ 22. a. b. c. d. ____ 23. If you do NOT provide an access specifier for a Sub Procedure then it will be Private it will be Protected it will be Friend it will be Public What would be the value of the variable IntShowNum the next time the Sub Procedure ShowLocalNum is called to run? Sub ShowLocalNum ( ) Dim IntShowNum As Integer MessageBox.Show(IntShowNum.Tostring) IntShowNum = 10 End sub a. b. c. d. 0 1 10 Cant be determined Chapter 6 9 ____ 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 What is the problem with the following Sub procedure? Sub DisplayValue(Dim intNumber As Integer) ' This displays a value. MessageBox.Show(intNumber.ToString) End Sub a. b. c. d. intNumber doesnt need to be converted to a string scope of procedure must be declared Dim should not be used in the parameter variable declaration all are problems ____ 25. ____ 26. calls? a. b. c. d. Which is the correct general format to declare a variable that remains the same between procedure Static variableName As DataType Dim variableName As Static VariableName As static = x Sub Static variableName ( ) Chapter 6 Answer Section MULTIPLE CHOICE 1. ans: 2. ans: 3. ans: 4. ans: 5. ans: 6. ans: 7. ans: 8. Register to View Answerc d c b d c a 10 9. ans: 10. ans: 11. ans: 12. ans: 13. ans: 14. ans: 15. ans: 16. ans: 17. ans: 18. ans: 19. ans: 20. ans: 21. Register to View Answerc b c c a b c a a b c c d a d c a 22. ans: 23. ans: 24. ans: 25. ans: 26. ans: Chapter 6 11 ... View Full Document

End of Preview

Sign up now to access the rest of the document