Deck 6: Procedures and Functions

ملء الشاشة (f)
exit full mode
سؤال
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) A procedure's parameter list need not agree with the arguments provided to the procedure.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
When calling a procedure, passed arguments and declared parameters must agree in all of the following ways except __________.

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
سؤال
By writing your own procedures, you can ______an applications code, that is, break it into small, manageable procedures.

A) streamline
B) duplicate
C) modularize
D) functionalize
سؤال
If we were to call the MakeDouble and ChangeArg methods shown below, using the following statements, what value would be assigned to lblResult.Text?

A) 0
B) 20
C) 40
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
سؤال
Which debugging command executes a function call without stepping through function's statements?

A) Step Into
B) Step Over
C) Step Out
D) Step All
سؤال
A is a special variable that receives a value being passed into a procedure or function.

A) temporary variable
B) pseudo-constant
C) class-level variable
D) parameter
سؤال
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

A) 0
B) 5
C) 10
D) 13
سؤال
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
سؤال
In the context of Visual Basic procedures and functions, what is an argument?

A) A value received by a procedure from the caller
B) A value passed to a procedure by 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.
سؤال
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

A) 4
B) 5
C) 6
D) 7
سؤال
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
سؤال
A procedure may not be accessed by procedures from another class or form if the ______access specifier is used.

A) Private
B) Public
C) Static
D) Scope
سؤال
When a procedure finishes execution, __________.

A) control returns to the point where the procedure was called and continues with the next statement
B) the application terminates unless the procedure contains a Return statement
C) control transfers to the next procedure found in the code
D) the application waits for the user to trigger the next event
سؤال
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

A) intAns should not be declared inside the Function.
B) the as Integer at the end of the Function heading should be eliminated.
C) the function does not return a value
D) parameters intA and intB should be declared as ByRef
سؤال
When a parameter is declared using the ______qualifier, the procedure has access to the original argument variable and may make changes to its value.

A) ByValue
B) ByAddress
C) ByRef
D) ByDefault
سؤال
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) Sub GetInput(ByVal intNumber As Integer) intNumber = CInt(InputBox("Enter an Integer"))
End Sub
B) Sub GetInput(ByRef 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() Dim intNumber As Integer
IntNumber = CInt(InputBox("Enter an Integer"))
End Sub
سؤال
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. 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.  <div style=padding-top: 35px>
سؤال
Which of the following calls to the GetNumber procedure is not valid? Sub GetNumber(ByVal intNumber as Integer)
' (procedure body)
End Sub

A) GetNumber(intX)
B) GetNumber(3 + 5 * 8 + intX)
C) GetNumber(intX + 3, intY)
D) GetNumber(CInt(txtNumber.Text))
سؤال
When debugging a program in break mode, the Step Into command causes the currently highlighted line of code to execute.
سؤال
Which of the following code examples is a function that will accept three integer parameters, calculate their average, and return the result?

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
Average = intX + intY + intZ / 3
Return Average
End Function
C) 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) Function Average(ByVal intX As Integer, ByVal IntY as Integer, _ ByVal intZ As Integer) As Single
Return (intX + intY + intZ) / 3
End Function
سؤال
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)

A) Sub IsLetter(ByVal strInput as String) as Boolean
B) Sub IsLetter(ByVal blnResult as Boolean) as String
C) Function IsLetter(ByVal strInput as String) as Boolean
D) Function IsLetter(ByVal blnResult as Boolean) as String
سؤال
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

A) PowersOfTwo
B) SquareRootsOfTwo
C) MultiplyByTwo
D) TwoPlusTwo
سؤال
What is wrong with the following GetName procedure? Sub GetName(ByVal strName As String)
StrName = InputBox("Enter your Name:")
End Sub

A) The procedure is missing a Return statement.
B) GetName is a reserved word and cannot be used as a name of a procedure.
C) strName will be modified, but all changes will be lost when the procedure ends.
D) 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, dblNum2)
LblSum.Text = dblSum.ToString()
End Sub
Function Sum(ByVal dblNum1 As Double, ByVal dblNum2 As Double) as Double
Return dblNum1 + dblNum2
End Function

A) 60
B) 50
C) 0
D) 70
سؤال
Which of the following can be returned by a function?

A) String values
B) Integer values
C) Boolean values
D) All of the above
سؤال
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?

A) Function Square(ByVal intNum as Integer) As Integer Return intNum * intNum
End Function
B) Function Square(ByVal intNum as Integer) Return intNum * intNum
End Function
C) Function Square(ByVal intNum as Integer) As Double Return intNum * intNum
End Function
D) Function Square(ByVal intNum as Integer) As Double Dim dblAns as Double
DblAns = intNum * intNum
Return dblAns
End Function
سؤال
What is the syntax error in the following procedure? Sub DisplayValue(Dim intNumber As Integer)
MessageBox.Show(intNumber.ToString())
End Sub

A) intNumber cannot be converted to a string
B) the procedure's does not have a return value
C) Dim is not valid when declaring parameters
D) all of the above are true
سؤال
If you do not provide an access specifier for a procedure, it will be designated ______by default.

A) Private
B) Protected
C) Friend
D) Public
سؤال
Which one of the following declarations uses Pascal casing for the procedure name?

A) Sub MyProcedure()
End Sub
B) Sub myprocedure()
End Sub
C) Sub my_procedure()
End Sub
D) Sub myProcedure()
End Sub
سؤال
Which statement is not true regarding functions?

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) A function can only return a single value.
D) The same function can return several data types including integer, string, or double
سؤال
Although you can omit the ByVal keyword in a parameter variable declaration, it is still a good idea to use it.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/31
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 6: Procedures and Functions
1
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) A procedure's parameter list need not agree with the arguments provided to the procedure.
A
2
When calling a procedure, passed arguments and declared parameters must agree in all of the following ways except __________.

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
3
By writing your own procedures, you can ______an applications code, that is, break it into small, manageable procedures.

A) streamline
B) duplicate
C) modularize
D) functionalize
C
4
If we were to call the MakeDouble and ChangeArg methods shown below, using the following statements, what value would be assigned to lblResult.Text?

A) 0
B) 20
C) 40
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which debugging command executes a function call without stepping through function's statements?

A) Step Into
B) Step Over
C) Step Out
D) Step All
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
6
A is a special variable that receives a value being passed into a procedure or function.

A) temporary variable
B) pseudo-constant
C) class-level variable
D) parameter
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
7
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

A) 0
B) 5
C) 10
D) 13
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
8
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
9
In the context of Visual Basic procedures and functions, what is an argument?

A) A value received by a procedure from the caller
B) A value passed to a procedure by 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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
10
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

A) 4
B) 5
C) 6
D) 7
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
11
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
12
A procedure may not be accessed by procedures from another class or form if the ______access specifier is used.

A) Private
B) Public
C) Static
D) Scope
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
13
When a procedure finishes execution, __________.

A) control returns to the point where the procedure was called and continues with the next statement
B) the application terminates unless the procedure contains a Return statement
C) control transfers to the next procedure found in the code
D) the application waits for the user to trigger the next event
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
14
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

A) intAns should not be declared inside the Function.
B) the as Integer at the end of the Function heading should be eliminated.
C) the function does not return a value
D) parameters intA and intB should be declared as ByRef
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
15
When a parameter is declared using the ______qualifier, the procedure has access to the original argument variable and may make changes to its value.

A) ByValue
B) ByAddress
C) ByRef
D) ByDefault
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
16
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) Sub GetInput(ByVal intNumber As Integer) intNumber = CInt(InputBox("Enter an Integer"))
End Sub
B) Sub GetInput(ByRef 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() Dim intNumber As Integer
IntNumber = CInt(InputBox("Enter an Integer"))
End Sub
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
17
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. 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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following calls to the GetNumber procedure is not valid? Sub GetNumber(ByVal intNumber as Integer)
' (procedure body)
End Sub

A) GetNumber(intX)
B) GetNumber(3 + 5 * 8 + intX)
C) GetNumber(intX + 3, intY)
D) GetNumber(CInt(txtNumber.Text))
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
19
When debugging a program in break mode, the Step Into command causes the currently highlighted line of code to execute.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following code examples is a function that will accept three integer parameters, calculate their average, and return the result?

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
Average = intX + intY + intZ / 3
Return Average
End Function
C) 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) Function Average(ByVal intX As Integer, ByVal IntY as Integer, _ ByVal intZ As Integer) As Single
Return (intX + intY + intZ) / 3
End Function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
21
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)

A) Sub IsLetter(ByVal strInput as String) as Boolean
B) Sub IsLetter(ByVal blnResult as Boolean) as String
C) Function IsLetter(ByVal strInput as String) as Boolean
D) Function IsLetter(ByVal blnResult as Boolean) as String
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
22
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

A) PowersOfTwo
B) SquareRootsOfTwo
C) MultiplyByTwo
D) TwoPlusTwo
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
23
What is wrong with the following GetName procedure? Sub GetName(ByVal strName As String)
StrName = InputBox("Enter your Name:")
End Sub

A) The procedure is missing a Return statement.
B) GetName is a reserved word and cannot be used as a name of a procedure.
C) strName will be modified, but all changes will be lost when the procedure ends.
D) The syntax for the call to InputBox is incorrect.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
24
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

A) 60
B) 50
C) 0
D) 70
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which of the following can be returned by a function?

A) String values
B) Integer values
C) Boolean values
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
26
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?

A) Function Square(ByVal intNum as Integer) As Integer Return intNum * intNum
End Function
B) Function Square(ByVal intNum as Integer) Return intNum * intNum
End Function
C) Function Square(ByVal intNum as Integer) As Double Return intNum * intNum
End Function
D) Function Square(ByVal intNum as Integer) As Double Dim dblAns as Double
DblAns = intNum * intNum
Return dblAns
End Function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
27
What is the syntax error in the following procedure? Sub DisplayValue(Dim intNumber As Integer)
MessageBox.Show(intNumber.ToString())
End Sub

A) intNumber cannot be converted to a string
B) the procedure's does not have a return value
C) Dim is not valid when declaring parameters
D) all of the above are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
28
If you do not provide an access specifier for a procedure, it will be designated ______by default.

A) Private
B) Protected
C) Friend
D) Public
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
29
Which one of the following declarations uses Pascal casing for the procedure name?

A) Sub MyProcedure()
End Sub
B) Sub myprocedure()
End Sub
C) Sub my_procedure()
End Sub
D) Sub myProcedure()
End Sub
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
30
Which statement is not true regarding functions?

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) A function can only return a single value.
D) The same function can return several data types including integer, string, or double
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
31
Although you can omit the ByVal keyword in a parameter variable declaration, it is still a good idea to use it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.