13 VB

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

By writing your own procedures, you can ________ an applications code, that is, break it into small, manageable procedures. Select one: A. modularize B. streamline C. functionalize D. duplicate

A

If we were to call the MakeDouble and ChangeArg methods shown below, using the following statements, what value would be assigned to lblResult.Text? Select one: A. 40 B. 20 C. 0 D. (cannot be determined) Dim intValue As Integer = 20 ChangeArg(intValue) lblResult.Text = MakeDouble(intValue).ToString() Function MakeDouble (ByVal intArg As Integer) As Integer Return intArg * 2 End Function Sub ChangeArg2(ByRef intArg As Integer) ' Display the value of intArg. lstOutput.Items.Add(" ") lstOutput.Items.Add("Inside the ChangeArg procedure, " & "intArg is " & intArg.ToString()) lstOutput.Items.Add("I will change the value of intArg.") ' Assign 0 to intArg. intArg = 0 ' Display the value of intArg. lstOutput.Items.Add("intArg is now " & intArg.ToString()) lstOutput.Items.Add(" ") End Sub

A

In the context of Visual Basic procedures and functions, what is an argument? Select one: A. A value passed to a procedure by the caller. B. A value received by a procedure from the caller C. A local variable that retains its value between procedure calls. D. A disagreement between the procedure and the statement that calls it.

A

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 intSecond += 1 End Sub Select one: A. 4 B. 5 C. 6 D. 7

A

What is the syntax error in the following procedure? Sub DisplayValue(Dim intNumber As Integer) MessageBox.Show(intNumber.ToString()) End Sub Select one: A. Dim is not valid when declaring parameters B. the procedure's does not have a return value C. intNumber cannot be converted to a string D. all of the above are true

A

A procedure may not be accessed by procedures from another class or form if the ________ access specifier is used. Select one: A. Static B. Private C. Public D. Scope

B

All of the following are true about functions except ________. Select one: A. you can use a function call in an expression B. they can return one or more values C. you can assign the return value from a function to a variable D. they must contain at least one Return statement

B

Choose a new, more descriptive name for the WhatIsIt function based on the result of the code below. Function WhatIsIt(ByVal intRepeat as Integer) as Integer Dim intResult as Integer = 1 Dim intCount as Integer For intCount = 1 to intRepeat intResult = intResult * 2 Next intCount Return intResult End Function Select one: A. SquareRootsOfTwo B. PowersOfTwo C. TwoPlusTwo D. MultiplyByTwo

B

What is wrong with the following GetName procedure? Sub GetName(ByVal strName As String) strName = InputBox("Enter your Name:") End Sub Select one: A. The syntax for the call to InputBox is incorrect. B. strName will be modified, but all changes will be lost when the procedure ends. C. The procedure is missing a Return statement. D. GetName is a reserved word and cannot be used as a name of a procedure.

B

When a parameter is declared using the ________ qualifier, the procedure has access to the original argument variable and may make changes to its value. Select one: A. ByAddress B. ByRef C. ByDefault D. ByValue

B

When a procedure finishes execution, ________. Select one: A. the application waits for the user to trigger the next event B. control returns to the point where the procedure was called and continues with the next statement C. the application terminates unless the procedure contains a Return statement D. control transfers to the next procedure found in the code

B

When calling a procedure, passed arguments and declared parameters must agree in all of the following ways except ________. Select one: 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

B

Which of the following calls to the GetNumber procedure is not valid? Sub GetNumber(ByVal intNumber as Integer) ' (procedure body) End Sub Select one: A. GetNumber(3 + 5 * 8 + intX) B. GetNumber(intX + 3, intY) C. GetNumber(intX) D. GetNumber(CInt(txtNumber.Text))

B

Which of the following code examples is a function that will accept three integer parameters, calculate their average, and return the result? Select one: A. Function Average(ByVal intX As Integer, ByVal intY As Integer, _ ByVal intZ As Integer) As Single Average = (intX + intY + intZ) / 3 End Function B. Function Average(ByVal intX As Integer, ByVal IntY as Integer, _ ByVal intZ As Integer) As Single Return (intX + intY + intZ) / 3 End Function C. 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 D. 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

B

Which one of the following declarations uses Pascal casing for the procedure name? Select one: A. Sub my_procedure() End Sub B. Sub MyProcedure() End Sub C. Sub myprocedure() End Sub D. Sub myProcedure() End Sub

B

Which statement is true in regard to passing an argument by value to a procedure? Select one: A. A procedure's parameter list need not agree with the arguments provided to the procedure. B. A copy of the argument is passed to the procedure. C. A reference to the argument is passed to the procedure. D. The procedure has access to the original argument and can make changes to it.

B

A ________ is a special variable that receives a value being passed into a procedure or function. Select one: A. temporary variable B. class-level variable C. parameter D. pseudo-constant

C

What is incorrect about the following function? Function sum(ByVal intX As Integer, ByVal intY As Integer) As Integer Dim intAns As Integer intAns = intX + intY End Function Select one: A. parameters intA and intB should be declared as ByRef B. the as Integer at the end of the Function heading should be eliminated C. the function does not return a value D. intAns should not be declared inside the Function

C

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, dblNum2) lblSum.Text = dblSum.ToString() End Sub Function Sum(ByVal dblNum1 As Double, ByVal dblNum2 As Double) as Double Return dblNum1 + dblNum2 End Function Select one: A. 0 B. 70 C. 60 D. 50

C

Which is the correct way to define a function named Square that receives an integer and returns an integer representing the square of the input value? Select one: A. Function Square(ByVal intNum as Integer) As Double Dim dblAns as Double dblAns = intNum * intNum Return dblAns End Function B. Function Square(ByVal intNum as Integer) Return intNum * intNum End Function C. Function Square(ByVal intNum as Integer) As Integer Return intNum * intNum End Function D. Function Square(ByVal intNum as Integer) As Double Return intNum * intNum End Function

C

Which of the following does not apply to procedures and functions? Select one: A. they permit the same sequence of code statements to be called from multiple places B. they make it easier to maintain and modify code C. the execution time is significantly reduced by calling procedures and functions D. they help to break up a large body of code into smaller chunks

C

Which of the following procedure declarations matches the call to the IsLetter procedure below? Dim strText as String = txtInput.Text Dim blnLetter as Boolean = IsLetter(strText) Select one: A. Sub IsLetter(ByVal blnResult as Boolean) as String B. Function IsLetter(ByVal blnResult as Boolean) as String C. Function IsLetter(ByVal strInput as String) as Boolean D. Sub IsLetter(ByVal strInput as String) as Boolean

C

Which statement is not true regarding functions? Select one: A. A function is a self-contained set of statements that can receive input values. B. Visual Basic has many built-in functions such as CSng(txtInput.Text). C. The same function can return several data types including integer, string, or double D. A function can only return a single value.

C

If you do not provide an access specifier for a procedure, it will be designated ________ by default. Select one: A. Private B. Protected C. Friend D. Public

D

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) Function AddSquares(ByVal intA As Integer, ByVal intB As Integer) As Integer intA = intA * intA intB = intB * intB Return intA + intB intA = 0 intB = 0 End Function Select one: A. 0 B. 5 C. 10 D. 13

D

Which debugging command executes a function call without stepping through function's statements? Select one: A. Step Out B. Step Into C. Step All D. Step Over

D

Which of the following can be returned by a function? Select one: A. String values B. Boolean values C. Integer values D. all of the above

D

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? Select one: A. Sub GetInput() Dim intNumber As Integer intNumber = CInt(InputBox("Enter an Integer")) End Sub B. Sub GetInput(ByVal intNumber As Integer) intNumber = CInt(InputBox("Enter an Integer")) End Sub C. Sub GetInput(ByRef intNumber As Integer) intNumber = CInt(InputBox("Enter an Integer")) Return intNumber End Sub D. Sub GetInput(ByRef intNumber As Integer) intNumber = CInt(InputBox("Enter an Integer")) End Sub

D

Which of the following functions accepts a parameter named dblSales and returns the commission to the calling statement? Assume that the commission should equal the sales multiplied by the commission rate. Use the following table as a guide to the calculation of the commission rate. Sales - Commission Rate less than 2,000 - 10% 2,000 or more - 15% A. Function Calc(ByVal dblSales As Double, ByRef dblComm As Double) Dim dblRate As Double Select Case dblSales Case Is < 2000 dblRate = .1 Case Is >= 2000 dblRate = .15 End Select DblComm = dblRate End Function B. Function Calc(ByVal dblSales As Double, ByRef dblComm as Double) Dim dblRate As Double Select Case dblSales Case Is < 2000 dblComm = .1 * dblRate Case Is >= 2000 dblComm = .15 * dblRate End Select End Function C. Function Calc(ByVal dblSales As Double) As Double Dim dblRate, dblComm as Double Select Case dblSales Case Is < 2000 dblRate = .1 Case Is >= 2000 dblRate = .15 End Select dblCommission = dblRate * dblSales End Function D. Function Calc(ByVal dblSales As Double) As Double Dim dblRate As Double Select Case dblSales Case Is < 2000 dblRate = .1 Case Is >= 2000 dblRate = .15 End Select Return dblRate * dblSales End Function

D

Although you can omit the ByVal keyword in a parameter variable declaration, it is still a good idea to use it. Select one: True False

True

When debugging a program in break mode, the Step Into command causes the currently highlighted line of code to execute. Select one: True False

True


Set pelajaran terkait

Ch 10 - Socioemotional Development in Adolescence

View Set

Alabama (Department of Insurance) Life and Health Insurance

View Set

The Human Body: An Orientation (Ch 1.2 cont.)

View Set