Answer each of the following:
Program components in C++ are called ________ and ________.
A function is invoked with a(n) ________.
A variable that is known only within the function in which it is defined is called a(n) ________.
The ________ statement in a called function passes the value of an expression back to the calling function.
The keyword ________ is used in a function header to indicate that a function does not return a value or to indicate that a function contains no parameters.
The ________ of an identifier is the portion of the program in which the identifier can be used.
The three ways to return control from a called function to a caller are ________, ________ and ________.
A(n)________ allows the compiler to check the number, types and order of the arguments passed to a function.
Function ________ is used to produce random numbers.
Function ________ is used to set the random number seed to randomize a program.
The storage-class specifiers are mutable, ________, ________, ________ and ________.
Variables declared in a block or in the parameter list of a function are assumed to be of storage class ________ unless specified otherwise.
Storage-class specifier ________ is a recommendation to the compiler to store a variable in one of the computer's registers.
A variable declared outside any block or function is a(n) ________ variable.
For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier.
The six possible scopes of an identifier are ________, ________, ________, ________, ________ and ________.
A function that calls itself either directly or indirectly (i.e., through another function) is a(n) ________ function.
A recursive function typically has two components: One that provides a means for the recursion to terminate by testing for a(n) ________ case and one that expresses the problem as a recursive call for a slightly simpler problem than the original call.
In C++, it is possible to have various functions with the same name that operate on different types or numbers of arguments. This is called function ________.
The ________ enables access to a global variable with the same name as a variable in the current scope.
The ________ qualifier is used to declare read-only variables.
A function ________ enables a single function to be defined to perform a task on many different data types.
For the program in Fig. 6.40, state the scope (either function scope, file scope, block scope or function-prototype scope) of each of the following elements:
The function prototype for cube.
The identifier y in the function prototype for cube.
Figure 6.40. Program for Exercise 6.2
(This item is displayed on page 312 in the print version)
1 // Exercise 6.2: Ex06_02.cpp
2 #include <iostream>
3 using std::cout;
4 using std::endl;
6 int cube( int y ); // function prototype
8 int main()
10 int x;
12 for ( x = 1; x <= 10; x++ ) // loop 10 times
13 cout << cube( x ) << endl; // calculate cube of x and output results
15 return 0; // indicates successful termination
16 } // end main
18 // definition of function cube
19 int cube( int y )
21 return y * y * y;
22 } // end function cube
Write a program that tests whether the examples of the math library function calls shown in Fig. 6.2 actually produce the indicated results.
Give the function header for each of the following functions:
Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
Function smallest that takes three integers, x, y and z, and returns an integer.
Function instructions that does not receive any arguments and does not return a value. [Note: Such functions are commonly used to display instructions to a user.]
Function intToDouble that takes an integer argument, number, and returns a double-precision, floating-point result.
Give the function prototype for each of the following:
Write a declaration for each of the following:
Integer count that should be maintained in a register. Initialize count to 0.
Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined.
Find the error in each of the following program segments, and explain how the error can be corrected (see also Exercise 6.53):
int g( void )
cout << "Inside function g" << endl;
int h( void )
cout << "Inside function h" << endl;
int sum( int x, int y )
result = x + y;
int sum( int n )
if ( n == 0 )
n + sum( n - 1 );
void f ( double a);
cout << a << endl;
void product( void )
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
Why would a function prototype contain a parameter type declaration such as double &?
(True/False) All arguments to function calls in C++ are passed by value.
Write a complete program that prompts the user for the radius of a sphere, and calculates and prints the volume of that sphere. Use an inline function sphereVolume that returns the result of the following expression: ( 4.0 / 3.0 ) * 3.14159 * pow( radius, 3 ).