ENGR 200 FINAL EXAM QUESTIONS WITH
ANSWERS AND EXPLANATIONS
| American Public University
1. Identify the concept that means the use of an output stream such as std::cout to send formatted text or values to a
console.
A. operator precedence
B. standard output
C. char type
D. initialization
Correct Answer: B. standard output
Explanation: standard output refers to the use of an output stream such as std::cout to send formatted text or values to a
console.
2. A team observes the following: A vector may have room for additional elements even though size() reports only
the elements currently present. Which principle is the best match?
A. vector size
B. vector capacity concept
C. vector
D. array initialization
Correct Answer: B. vector capacity concept
Explanation: The situation is a direct example of vector capacity concept, which is the amount of storage a vector has
allocated, which may exceed its current element count.
3. What is the standard term for the stack of active function-call frames used to hold return information and local
state?
A. call stack
B. local variable
C. argument
D. pass by value
Correct Answer: A. call stack
Explanation: call stack refers to the stack of active function-call frames used to hold return information and local state.
4. The result is: int flags[4] = {1, 0, 1, 1}; creates the array with specified contents. Which explanation fits better
than an account based on const element reference?
A. a reference used to read an element without copying it and without allowing modification through that reference
B. a loop form that iterates directly over elements in a range
C. supplying initial element values when an array is defined
D. multiple arrays whose elements at the same index represent related attributes
Correct Answer: C. supplying initial element values when an array is defined
Explanation: The case follows array initialization (supplying initial element values when an array is defined) rather
than const element reference (a reference used to read an element without copying it and without allowing modification
through that reference).
,5. Which paired description of setter and public access is defensible?
A. setter is class members declared accessible through the class interface from allowed external code; public access
is a member function used to change object state, often with validation.
B. Both terms refer to class members declared accessible through the class interface from allowed external code.
C. setter is a member function used to change object state, often with validation; public access is class members
declared accessible through the class interface from allowed external code.
D. Both terms refer to a member function used to change object state, often with validation.
Correct Answer: C. setter is a member function used to change object state, often with validation; public access is
class members declared accessible through the class interface from allowed external code.
Explanation: The concepts differ: setter is a member function used to change object state, often with validation,
whereas public access is class members declared accessible through the class interface from allowed external code.
6. A team needs a practical indicator of local variable. Which choice is most diagnostic?
A. A swap routine exchanges two caller variables through parameters declared with &.
B. A temporary sum declared inside a helper function is not directly accessible from main.
C. A formatting function uses a default precision unless the caller specifies another one.
D. Each recursive call creates another active frame until the base case is reached.
Correct Answer: B. A temporary sum declared inside a helper function is not directly accessible from main.
Explanation: The selected observation most specifically demonstrates local variable: a variable declared within a block
or function and limited to that local scope.
7. The evidence favors one concept over infinite loop: Using i <= size when valid indices end at size - 1 attempts to
access one element past the end. Which explanation should be preferred?
A. a pretest repetition statement that repeats while its condition remains true
B. a loop whose termination condition never becomes false during execution
C. a loop that checks its continuation condition after the body executes
D. a loop error that performs one iteration too many or too few because of incorrect bounds
Correct Answer: D. a loop error that performs one iteration too many or too few because of incorrect bounds
Explanation: The case follows off-by-one error (a loop error that performs one iteration too many or too few because of
incorrect bounds) rather than infinite loop (a loop whose termination condition never becomes false during execution).
8. Which statement correctly separates const reference parameter from function definition?
A. Both terms refer to a reference parameter used to avoid copying while preventing modification through that
parameter.
B. Both terms refer to the code that specifies a function's return type, name, parameters, and body.
C. const reference parameter is the code that specifies a function's return type, name, parameters, and body; function
definition is a reference parameter used to avoid copying while preventing modification through that parameter.
D. const reference parameter is a reference parameter used to avoid copying while preventing modification through
that parameter; function definition is the code that specifies a function's return type, name, parameters, and body.
Correct Answer: D. const reference parameter is a reference parameter used to avoid copying while preventing
modification through that parameter; function definition is the code that specifies a function's return type, name,
parameters, and body.
Explanation: The concepts differ: const reference parameter is a reference parameter used to avoid copying while
preventing modification through that parameter, whereas function definition is the code that specifies a function's return
type, name, parameters, and body.
, 9. Which option repairs the conceptual error in defining const element reference as 'an algorithm that tracks the
largest value seen while traversing a collection'?
A. checking elements sequentially until a target is found or the collection is exhausted
B. visiting array elements systematically, typically with an index loop
C. a reference used to read an element without copying it and without allowing modification through that reference
D. an algorithm that tracks the largest value seen while traversing a collection
Correct Answer: C. a reference used to read an element without copying it and without allowing modification
through that reference
Explanation: The correction is that const element reference is a reference used to read an element without copying it
and without allowing modification through that reference. The mistaken wording instead describes maximum scan.
10. Given int x = 5; int* p = &x;, what value does *p produce?
A. 5
B. The address of x
C. 6
D. nullptr
Correct Answer: A. 5
Explanation: Dereferencing p accesses the value stored in x.
11. How should std::string and string indexing be distinguished?
A. Both terms refer to the standard-library string type for managing sequences of characters.
B. Both terms refer to accessing an individual character by its zero-based position.
C. std::string is accessing an individual character by its zero-based position; string indexing is the standard-library
string type for managing sequences of characters.
D. std::string is the standard-library string type for managing sequences of characters; string indexing is accessing an
individual character by its zero-based position.
Correct Answer: D. std::string is the standard-library string type for managing sequences of characters; string
indexing is accessing an individual character by its zero-based position.
Explanation: The concepts differ: std::string is the standard-library string type for managing sequences of characters,
whereas string indexing is accessing an individual character by its zero-based position.
12. A team needs a practical indicator of logical NOT. Which choice is most diagnostic?
A. The expression !valid is true when valid is false.
B. An alarm is raised if temperature is too high or pressure is too low.
C. A pointer-null check on the left of && prevents dereferencing when the pointer is null.
D. A missing break causes statements under a later case label to run unexpectedly.
Correct Answer: A. The expression !valid is true when valid is false.
Explanation: The selected observation most specifically demonstrates logical NOT: the ! operator that reverses a
boolean condition.
ANSWERS AND EXPLANATIONS
| American Public University
1. Identify the concept that means the use of an output stream such as std::cout to send formatted text or values to a
console.
A. operator precedence
B. standard output
C. char type
D. initialization
Correct Answer: B. standard output
Explanation: standard output refers to the use of an output stream such as std::cout to send formatted text or values to a
console.
2. A team observes the following: A vector may have room for additional elements even though size() reports only
the elements currently present. Which principle is the best match?
A. vector size
B. vector capacity concept
C. vector
D. array initialization
Correct Answer: B. vector capacity concept
Explanation: The situation is a direct example of vector capacity concept, which is the amount of storage a vector has
allocated, which may exceed its current element count.
3. What is the standard term for the stack of active function-call frames used to hold return information and local
state?
A. call stack
B. local variable
C. argument
D. pass by value
Correct Answer: A. call stack
Explanation: call stack refers to the stack of active function-call frames used to hold return information and local state.
4. The result is: int flags[4] = {1, 0, 1, 1}; creates the array with specified contents. Which explanation fits better
than an account based on const element reference?
A. a reference used to read an element without copying it and without allowing modification through that reference
B. a loop form that iterates directly over elements in a range
C. supplying initial element values when an array is defined
D. multiple arrays whose elements at the same index represent related attributes
Correct Answer: C. supplying initial element values when an array is defined
Explanation: The case follows array initialization (supplying initial element values when an array is defined) rather
than const element reference (a reference used to read an element without copying it and without allowing modification
through that reference).
,5. Which paired description of setter and public access is defensible?
A. setter is class members declared accessible through the class interface from allowed external code; public access
is a member function used to change object state, often with validation.
B. Both terms refer to class members declared accessible through the class interface from allowed external code.
C. setter is a member function used to change object state, often with validation; public access is class members
declared accessible through the class interface from allowed external code.
D. Both terms refer to a member function used to change object state, often with validation.
Correct Answer: C. setter is a member function used to change object state, often with validation; public access is
class members declared accessible through the class interface from allowed external code.
Explanation: The concepts differ: setter is a member function used to change object state, often with validation,
whereas public access is class members declared accessible through the class interface from allowed external code.
6. A team needs a practical indicator of local variable. Which choice is most diagnostic?
A. A swap routine exchanges two caller variables through parameters declared with &.
B. A temporary sum declared inside a helper function is not directly accessible from main.
C. A formatting function uses a default precision unless the caller specifies another one.
D. Each recursive call creates another active frame until the base case is reached.
Correct Answer: B. A temporary sum declared inside a helper function is not directly accessible from main.
Explanation: The selected observation most specifically demonstrates local variable: a variable declared within a block
or function and limited to that local scope.
7. The evidence favors one concept over infinite loop: Using i <= size when valid indices end at size - 1 attempts to
access one element past the end. Which explanation should be preferred?
A. a pretest repetition statement that repeats while its condition remains true
B. a loop whose termination condition never becomes false during execution
C. a loop that checks its continuation condition after the body executes
D. a loop error that performs one iteration too many or too few because of incorrect bounds
Correct Answer: D. a loop error that performs one iteration too many or too few because of incorrect bounds
Explanation: The case follows off-by-one error (a loop error that performs one iteration too many or too few because of
incorrect bounds) rather than infinite loop (a loop whose termination condition never becomes false during execution).
8. Which statement correctly separates const reference parameter from function definition?
A. Both terms refer to a reference parameter used to avoid copying while preventing modification through that
parameter.
B. Both terms refer to the code that specifies a function's return type, name, parameters, and body.
C. const reference parameter is the code that specifies a function's return type, name, parameters, and body; function
definition is a reference parameter used to avoid copying while preventing modification through that parameter.
D. const reference parameter is a reference parameter used to avoid copying while preventing modification through
that parameter; function definition is the code that specifies a function's return type, name, parameters, and body.
Correct Answer: D. const reference parameter is a reference parameter used to avoid copying while preventing
modification through that parameter; function definition is the code that specifies a function's return type, name,
parameters, and body.
Explanation: The concepts differ: const reference parameter is a reference parameter used to avoid copying while
preventing modification through that parameter, whereas function definition is the code that specifies a function's return
type, name, parameters, and body.
, 9. Which option repairs the conceptual error in defining const element reference as 'an algorithm that tracks the
largest value seen while traversing a collection'?
A. checking elements sequentially until a target is found or the collection is exhausted
B. visiting array elements systematically, typically with an index loop
C. a reference used to read an element without copying it and without allowing modification through that reference
D. an algorithm that tracks the largest value seen while traversing a collection
Correct Answer: C. a reference used to read an element without copying it and without allowing modification
through that reference
Explanation: The correction is that const element reference is a reference used to read an element without copying it
and without allowing modification through that reference. The mistaken wording instead describes maximum scan.
10. Given int x = 5; int* p = &x;, what value does *p produce?
A. 5
B. The address of x
C. 6
D. nullptr
Correct Answer: A. 5
Explanation: Dereferencing p accesses the value stored in x.
11. How should std::string and string indexing be distinguished?
A. Both terms refer to the standard-library string type for managing sequences of characters.
B. Both terms refer to accessing an individual character by its zero-based position.
C. std::string is accessing an individual character by its zero-based position; string indexing is the standard-library
string type for managing sequences of characters.
D. std::string is the standard-library string type for managing sequences of characters; string indexing is accessing an
individual character by its zero-based position.
Correct Answer: D. std::string is the standard-library string type for managing sequences of characters; string
indexing is accessing an individual character by its zero-based position.
Explanation: The concepts differ: std::string is the standard-library string type for managing sequences of characters,
whereas string indexing is accessing an individual character by its zero-based position.
12. A team needs a practical indicator of logical NOT. Which choice is most diagnostic?
A. The expression !valid is true when valid is false.
B. An alarm is raised if temperature is too high or pressure is too low.
C. A pointer-null check on the left of && prevents dereferencing when the pointer is null.
D. A missing break causes statements under a later case label to run unexpectedly.
Correct Answer: A. The expression !valid is true when valid is false.
Explanation: The selected observation most specifically demonstrates logical NOT: the ! operator that reverses a
boolean condition.