C++ Chapter 6
A function ________ contains the statements that make up the function.
body
These types of arguments are passed to parameters automatically if no argument is provided in the function call.
default
Look at the following function prototype. int myFunction(double);What is the data type of the function's parameter?
double
This function causes a program to terminate, regardless of which function or control mechanism is executing.
exit ( )
Which line in the following program contains (or begins) the call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }
10
A function is executed when it is:
called
Here is the prototype for a function named computeValue: void computeValue(int value);Which of the following is a valid call to that function?
computeValue (10);
It is a good programming practice to ________ your functions by writing comments that describe what they do.
document
This type of variable is defined inside a function and is not accessible outside the function.
local
What is the output produced by this program? #include <iostream> using namespace std; void showDub(int); int main(){ int x = 2; showDub(x); return 0; } void showDub(int x){ cout << ( x * 2 ) << endl; }
4
Look at the following function prototype. int myFunction(double);What is the data type of the funtion's return value?
int
A named collection of statements that performs a specific task is a
function
#include <iostream> using namespace std; void showInts(int, int); void changeInts(int, int); int main(){ int first = 1, second = 2; showInts(first, second); changeInts(first, second); showInts(first, second); return 0; } void showInts(int first, int second){ cout << first << " " << second << endl; } void changeInts(int aNumber, int anotherNumber){ int first = 3, second = 4; anotherNumber = second * anotherNumber; aNumber = first * aNumber; }
1 2 1 2
#include <iostream> using namespace std; void showInts(int, int); void changeInts(int, int &); int main(){ int first = 1, second = 2; showInts(first, second); changeInts(first, second); showInts(first, second); return 0; } void showInts(int first, int second){ cout << first << " " << second << endl; } void changeInts(int aNumber, int & anotherNumber){ int first = 3, second = 4; anotherNumber = second * anotherNumber; aNumber = first * aNumber; }
1 2 1 8
#include <iostream> using namespace std; void showInts(int, int); void changeInts(int &, int); int main(){ int first = 1, second = 2; showInts(first, second); changeInts(first, second); showInts(first, second); return 0; } void showInts(int first, int second){ cout << first << " " << second << endl; } void changeInts(int & aNumber, int anotherNumber){ int first = 3, second = 4; anotherNumber = second * anotherNumber; aNumber = first * aNumber; }
1 2 3 2
#include <iostream> using namespace std; void showInts(int, int); void changeInts(int &, int &); int main(){ int first = 1, second = 2; showInts(first, second); changeInts(first, second); showInts(first, second); return 0; } void showInts(int first, int second){ cout << first << " " << second << endl; } void changeInts(int & aNumber, int & anotherNumber){ int first = 3, second = 4; anotherNumber = second * anotherNumber; aNumber = first * aNumber; }
1 2 3 8
#include <iostream> using namespace std; void doSomething(int&); int main( ){ int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; }void doSomething(int& num){ num = 0; }
2 0
What is the output of the following program?#include <iostream>using namespace std; void doSomething(int&);int main( ){ int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0;}void doSomething(int& num){ num = 0;}
2 0
# include <iostream> using namespace std; void doSomething(int); int main( ){ int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num){ num = num * 2; }
2 2
# include <iostream> using namespace std; void doSomething(int &); int main( ){ int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; }void doSomething(int & num){ num = num * 2; }
2 4
Which line in the following program contains (or begins) the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0;13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }
4
Which line in the following program contains (or begins) the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x);11 cout << x << endl;12 return 0;13 }14 15 void showDub(int num)16 {17 cout << (num * 2) << endl;18 }
4
int myFunction(double, double, double, double); How many parameters does this function have?
4
If a function does not have a prototype, default arguments may be specified in the function ________.
header
Which line in the following program contains (or begins) the declaration for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x);11 cout << x << endl;12 return 0;13 }14 15 void showDub(int num)16 {17 cout << (num * 2) << endl;18 }
15
# include <iostream> using namespace std; int getValue(int); int main( ){ int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num){ return num*3; }
6
What is the output of the following program?# include <iostream>using namespace std; int getValue(int);int main( ){ int x = 2; cout << getValue(x) << endl; return 0;}int getValue(int num){ return num*3;}
6
In a function header, you must furnish: Select one: a. the names of all of the parameters b. the name of function c. the data type of the return value d. the data types of the parameters e. All of these
All of these
A function's return data type must be the same as the function's parameter(s).
False
Arguments are passed to a function in the order in which they appear in the function call.
True
Function prototypes are terminated with a semicolon
True
Function prototypes are terminated with a semicolon.
True
One reason for using functions is to break programs into manageable units, or modules.
True
You may use the exit( ) function to terminate a program, regardless of which control mechanism is executing.
True
What are the two parts of a function signature? Select one or more: a. return type b. parameter list c. function name
parameter list function name
A function ________ eliminates the need to place a function definition before all calls to the function.
prototype
In C++, parameters are passed to functions in three different ways. These three ways are:
reference pointer value
This statement causes a function to end.
return