Name:     ID: 
 
Email: 

Chapter 9 C++

True/False
Indicate whether the statement is true or false.
 

 1. 

A C++ program cannot contain more than one function.
 

 2. 

Functions allow the programmer to avoid duplicating code in different parts of a program.
 

 3. 

Functions allow large and complex programs to be broken into small and manageable tasks.
 

 4. 

A value-returning function can return multiple values after completing its assigned task, using a multi-valued return statement.
 

 5. 

A pseudo-random number generator is a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
 

 6. 

The rand() function returns an integer that is greater than or equal to zero but less than or equal to the value stored in the RAND_LIMIT constant.
 

 7. 

The statement  cout << 1 + rand() % (6 – 1 + 1); displays a random integer from 0 through 6 on the screen.
 

 8. 

You should initialize the random number generator in each program in which it is used; otherwise, it will generate the same series of numbers each time the program is executed.
 

 9. 

When generating pseudo-random numbers, a seed is an integer that represents the starting point for the random number generator.
 

 10. 

The time( ) function is a value-returning function that returns the current time (according to your computer system’s clock) as seconds elapsed since midnight on January 1, 1960.
 

 11. 

A function header is considered a statement in C++.
 

 12. 

It is common practice to begin the name of a function with a noun.
 

 13. 

The rules for naming functions are the same as for naming variables.
 

 14. 

Each variable you declare in a program has both a value and a unique address that represents the location of the variable in the computer’s internal memory.
 

 15. 

Passing a variable’s value to a function is referred to as passing by reference.
 

 16. 

Passing a variable’s address to a function is referred to as passing by value.
 

 17. 

Unless you specify otherwise, variables in C++ are automatically passed by value.
 

 18. 

When you pass a literal constant, a keyword, a named constant, or a variable’s value to a function, the function stores the value it receives in a memory location
 

 19. 

The data type and position of each formal parameter in the parameterList of a function call must agree with the data type and position of its corresponding actual argument.
 

 20. 

In C++, you can define a default value for one or more of a function’s formal parameters.
 

 21. 

Few C++ programmers enter the function definitions below the main() function in a program.
 

 22. 

You must include the name of each formal parameter in the function prototype.
 

 23. 

You call a program-defined function in exactly the same way as you call a built-in function.
 

 24. 

The scope and lifetime of a variable are typically determined by where you declare the variable in the program.
 

 25. 

Declaring a variable as global rather than local allows unintentional errors to occur when a function that should not have access to the variable inadvertently changes the variable’s contents.
 

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 26. 

A(n) ____ is a block of code that performs a task.
a.
statement
c.
function
b.
expression
d.
program
 

 27. 

Every C++ program contains at least one function: ____.
a.
main()
c.
return()
b.
pow()
d.
rand()
 

 28. 

____ functions do not return a value.
a.
Empty
c.
Null
b.
Void
d.
Abstract
 

 29. 

You can use the built-in C++ ____ function to raise a number to a power and then return the result as a double number.
a.
xy()
c.
power()
b.
raise()
d.
pow()
 

 30. 

The statement cout << pow(100, .5); displays the number ____ on the screen.
a.
5
c.
50
b.
10
d.
100
 

 31. 

In standard C++, the random number generator is a built-in function named ____.
a.
rand()
c.
rnd()
b.
random()
d.
rndm()
 

 32. 

Although the value of RAND_MAX varies with different systems, its value is always at least ____.
a.
8,191
c.
32,767
b.
16,382
d.
65,534
 

 33. 

In .NET C++, you use the ____ class to generate random numbers.
a.
Math
c.
Random
b.
Rand
d.
Util
 

 34. 

The modulus arithmetic operator (____) divides two integers and results in the remainder of the division.
a.
&
c.
%
b.
^
d.
#
 

 35. 

The statement num = 10 + rand() % (100 – 10 + 1); assigns 53 to the num variable if the value returned by rand() is ____.
a.
4
c.
352
b.
323
d.
2500
 

 36. 

You initialize the random number generator using the ____ function.
a.
srand()
c.
init()
b.
seed()
d.
start()
 

 37. 

The ____ function is a void function.
a.
rand()
c.
toupper()
b.
srand()
d.
main()
 

 38. 

To use the time() function in a program, the program must contain the ____ directive.
a.
#include <time>
c.
#include <rand>
b.
#include <ctime>
d.
#include <crand>
 

 39. 

The ____ store the information passed to the function when the function is invoked.
a.
actual parameters
c.
actual arguments
b.
formal parameters
d.
formal arguments
 

 40. 

The items of information you pass to a function are called ____.
a.
actual parameters
c.
actual arguments
b.
formal parameters
d.
formal arguments
 

 41. 

An actual argument can be a variable, named constant, literal constant, or keyword; however, in most cases it will be a ____.
a.
variable
c.
literal constant
b.
named constant
d.
keyword
 

 42. 

The ____ contains the instructions the function must follow to perform its assigned task.
a.
function header
c.
formal parameters list
b.
function body
d.
actual arguments list
 

 43. 

The function body begins with ____.
a.
{
c.
<
b.
(
d.
[
 

 44. 

The ____ alerts the computer that the function has completed its task.
a.
)
c.
exit statement
b.
quit statement
d.
return statement
 

 45. 

When a function definition appears below the main() function, you must enter a function ____ above the main() function.
a.
prototype
c.
argument
b.
parameter
d.
declaration
 

 46. 

A variable’s ____ indicates where in the program the variable can be used.
a.
limit
c.
scope
b.
span
d.
lifetime
 

 47. 

A variable’s ____ indicates how long the variable remains in the computer’s internal memory.
a.
limit
c.
scope
b.
span
d.
lifetime
 

 48. 

The scope of a variable can be either ____.
a.
local or global
c.
real or virtual
b.
small or large
d.
internal or external
 

 49. 

____ variables are declared outside of any function in the program, and they remain in memory until the program ends.
a.
Global
c.
External
b.
Local
d.
Internal
 

 50. 

____ variables can be used only by the function in which they are declared or in whose parameterList they appear.
a.
Global
c.
External
b.
Local
d.
Internal
 



 
         Start Over