Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. The pow function contains two arguments, the base number and the square root value.
a.
True
b.
False
2. Unless you specify otherwise, variables in C++ are automatically passed by reference.
a.
True
b.
False
3. The value that the main function returns to the operating system indicates whether the program ended normally.
a.
True
b.
False
4. A program that uses the pow and sqrt functions requires the #include <iostream> directive.
a.
True
b.
False
5. The statement int getRandomnumber(void) is a proper declaration of a function that is not passed any
information.
a.
True
b.
False
6. All program-defined and built-in functions are categorized as either value-returning functions or void functions.
a.
True
b.
False
7. A variable’s scope indicates how long the variable remains in the computer’s internal memory.
a.
True
b.
False
8. Value-returning functions can return multiple values.
a.
True
b.
False
9. The constant RAND_MAX is a value your must define in your C++ program before using the rand function.
a.
True
b.
False
10. The main() function is found in some, but not all C++ programs.
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
11. When do you need to include a function prototype?
Name:
Class:
Date:
Page 2
a.
When a function is defined after the main function
b.
When a function is defined inside
the main function
c.
When a function is defined before
the main function
d.
When a function is defined in an external library
12. What is needed, if anything, to make this function correct?
double calculateArea()
{
const double PI = 3.141593;
double area = 0.0;
area = PI * pow(radius, 2);
return area;
}
a.
Nothing is wrong with the function
b.
the returnDataType is missing
c.
The return statement requires parentheses
d.
A variable in the parameterList is needed
13. In the following code, what is the scope and lifetime of the num1 variable?
int num2 = 100;
int main()
{
for (int num1=1; num1 < num2; num1+=1)
{
…………. more code here ………..
}
}
a.
global, until the for loop ends
b.
local, until the program ends
c.
local, until the for loop ends
d.
global, until the program ends
14. What is (are) the argument(s) passed to the pow function?
a.
base number and exponent
b.
the dividend and divsior
c.
the number to be squared
d.
a long value
15. What property of a variable indicates where in the program the variable an be used?
a.
scope
b.
lifetime
c.
type
d.
range
16. What is the data type of the value returned by the sqrt function?
a.
int
b.
short
c.
double
d.
float
17. What value is returned by the time function?
a.
seconds elapsed since midnight, 1/1/1970
b.
minutes elapsed since midnight, 1/1/1970
c.
hours elapsed since midnight, 1/1/1970
d.
days elapsed since midnight, 1/1/1970
18. If you want to send the value contained in a variable to a function, which method should you use?
Name:
Class:
Date:
Page 3
a.
passing by value
b.
calling by reference
c.
calling by value
d.
passing by reference
19. Which #include directive must be in a program that uses the sqrt function?
a.
<iostream>
b.
<cmath>
c.
<cstrlib>
d.
<sqrt>
20. How many values does a value-returning function return at its completion?
a.
one
b.
as many as defined in the parameter list
c.
none
d.
the number is predefined in the compiler
21. The rand function returns an integer that is greater than or equal 0 but less than or equal to the value stored in which
constant?
a.
MAX
b.
NUMBER_MAX
c.
MAX_NUMBER
d.
RAND_MAX
22. The function header for a value-returning function begins with which of the following?
a.
opening and closing parentheses
b.
the keyword function
c.
opening braces
d.
the returnDataType
23. What is the term for the starting point value used by the random number generator?
a.
rand
b.
seed
c.
clock
d.
tick
24. What statement is required in the function getSquarePerimeter to assign a value to the variable p in the following
statement?
p = getSquarePerimeter(side);
a.
release
b.
return
c.
assign
d.
set
25. What type of function alerts the C++ compiler that the function will be defined later in the program?
a.
value-returning
b.
uninitialized
c.
void
d.
prototype
26. In the code below, what is the scope of the num1 variable?
int num1;
int main()
{
cin >> num1;
cout << num1 *.10;
more code here
}
a.
the program lifetime
b.
local
c.
until the cout function finishes
d.
global
Name:
Class:
Date:
Page 4
27. If you want to send the address of a variable to a function, which method should you use?
a.
passing by value
b.
calling by reference
c.
calling by value
d.
passing by reference
28. Which #include directive may you need in your program in order to use the random number generator functions?
a.
<iostream>
b.
<ctime>
c.
<cstdlib>
d.
<srand>
29. What function is used to initialize the random number generator, and what type of function is it?
a.
rand, value-returning
b.
srand, void
c.
time, void
d.
init, value-returning
30. What are the memory locations in a function’s parameterList called?
a.
formal parameters
b.
actual arguments
c.
void parameters
d.
return values
31. Where does the main function return its value?
a.
to the function that invoked it
b.
to the command line
c.
to the operating system
d.
to an error handler
32. What type of variables can be used only by the function in which they are declared or in whose parameter list they
appear?
a.
Literal
b.
Lifetime
c.
Local
d.
Global
33. Unless you specify otherwise, variables in C++ are automatically passed by which method?
a.
value
b.
register
c.
address
d.
reference
34. What type of arguments are passed to a function?
a.
Actual
b.
Formal
c.
Return
d.
Value-returning
35. What type of functions allow large and complex programs to be broken into small and manageable tasks?
a.
Program-defined
b.
Built-in
c.
Value-returning
d.
Void
36. Which of the following is true about global variables?
a.
They are declared using the global keyword
b.
The are declared outside of any functions
c.
Their lifetime begins the first time they are
used
d.
They are declared right before the opening brace in
main
37. Given the statement below, write an equivalent statement using the sqrt function. Assume the variables answer and
number have been declared to be of the double data type.
Name:
Class:
Date:
Page 5
answer = pow( number, 0.5 );
38. Write a value-returning function called getAge that returns an int data value corresponding to a person’s age. The
function should prompt the user for their age and return it appropriately. Declare any local variables if needed.
39. Write an equation that will create a random number between 135 and 150, including 135 and 150.
40. Why should functions never be allowed to use global variables?
41. Most programming languages provide random number generator. Why are these numbers not truly random when
generated?
42. Actual and formal parameters must match in three ways. What are they?
43. Write an equation that will create a random number between 1 and 100, including 1 and 100.
44. Write a value-returning function called addOne that is passed an int data value and returns the value increased by one.
Declare any local variables if needed.
45. Write the statement to initialize the random number generator using the time function. Assume all include directives
have been included.
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Name:
Class:
Date:
Page 8