Ch.4 Flashcards
In the function declaration shown, the mechanism used to call this function is known as:
double pow(double base, double exp);
call by value
If you need to write a function that will compute the cost of some candy, where each piece costs 25 cents, which would be an appropriate function declaration?
int calculateCost(int count);
What is the value of the following?
sqrt(sqrt(pow(2,4)));
2
Using namespace std; tells the compiler
where to get the definitions of certain objects (variables).
What is the output of the following program fragment?
cout ≤≤ static_cast ≤ float > (3/4) ≤≤ endl;
0.0
What is the output of the following program fragment?
cout ≤≤ static_cast ≤ double > (3)/4 ≤≤ endl;
0.75
Information Hiding is analogous to using
a black-box methodology.
Which of the following functions is a properly overloaded function of the following?
int doSomething(int first, float second);
A) int doSomething(int first, int second, float third);
B) int doSomething( int next, float last);
C) int doSome(int first, float second);
D) float doSomething(int first, float second);
int doSomething(int first, int second, float third);
If the variable x has the original value of 3.4, what is the value in x after the following?
cout << static_cast < int > (x);
3
When the function below is called, the ________ of the actual parameters is passed to the function definition.
double sqrt(double value);
value
If you have the following variable declaration in your program,
const int SIZE = 34;
then which of the following statements are legal?
cout << SIZE;
The functions pow( ), sqrt( ), and fabs( ) are found in which include file?
cmath
When overloading a function, what must be true?
A) The names should be different with the same number and/or types of parameters.
B) The names should be the same with the same number and/or types of parameters.
C) The names should be different with different number and/or types of parameters.
D) The names should be the same with different number and/or types of parameters.
The names should be the same with different number and/or types of parameters
When parameters are passed between the calling code and the called function, parameters and arguments are matched by
their relative positions in the parameter and argument lists
If you have the two functions as shown,
int someFunction(int value);
float someFunction(float value);
and a variable x, which is a double, which function is called by the following statement?
cout ≤≤ someFunction(x);
Nothing, it is a syntax error.
When a variable is local to a function, we say that it has ________ of the function.
scope
What is the value of x after the following code fragment executes?
float x = 36.0;
x = sqrt(x)
6.0
The expression static_cast < double > (3) is called a
type cast
What is the value returned by the following function?
int function( )
{
int value = 35;
return value + 5;
value += 10;
}
40
What is the value of i after the following function call?
//function definition
int doSomething(int value)
{
value = 35;
return value;
value = 13
}
//fragment of main program
int i = 0;
cout << doSomething(i);
0
In the following function declaration, the variable size is known as a ________.
int myFunction ( int size);
formal parameter
Constant variables that might be used in different functions should be
global
Write the code to convert the value in an integer variable named count to a double
static_cast(count)
The absolute value function abs is located in the ________ library
stdio.h>
The ________ of a variable is where that variable can be used.
scope
Variables that are declared inside a function are said to be ________ to that function.
local
Converting from one type to another is called ________.
type casting
When you want to use a function in your program, you would make a function ________.
call or invocation
Algorithms are typically described in ________.
pseudo code
The ________ describes how the function will work.
body
Function naming rules follow variable naming rules.
True
Every include directive must be followed by using namespace std;
False
The parameter names are mandatory in the function header.
False
Functions may have multiple return statements.
True
A function may return more than one item.
False
Variables that are declared outside of any function body or parameter list are considered global.
True
The parameters listed in the function declaration are considered global variables.
False