Engineering Problem Solving with C++, 3e Chapter 7 Test Bank
Use the following array when answering questions 1 through 4
1. When searching the list above using the binary search for key value 69, list the values which
would be examined, in the order they are examined.
2. How many values would be examined to determine that 69 is not an element of the list using
the Sequential Search for an ordered list?
3. How many values would be examined to determine that 69 is not an element of the list using
the Sequential Search for an unordered list?
4. Given the declaration string aString{“Hello”}; Show the output generated by
the following range-based for statement:
for(char ch: aString)
cout << ch << endl;
5. Given the declaration double x[] = {0.5, 1.0, 1.5, 2.0}; show the output
generated by the following range-based for statement:
for(double t: x)
cout << t << endl;
6. Given the declaration double x[] = {0.5, 1.0, 1.5, 2.0}; show the output
generated by the following range-based for statement:
for(double& t: x){
++t;
cout << t << endl;
}
7. Write a declaration statement that will declare an array of characters named vowels and
initialized to the letters a, e, i, o, u.
8. Using the following function prototype which statement about the argument passed to
parameter A is true.
void F(const int A[ ], int Cnt);
A. The argument is modified when changes are made to parameter A in function F.
B. The argument passed to parameter A must always have the same number of elements,
every time function F is invoked.
C. Changes can not be made to parameter A in function F.
D. Every element of the argument passed to parameter A must be initialized prior to
invoking function F.
.
9. A restriction on arrays in C++ is:
4
13
15
24
29
32
38
41
50
62
67
75
79
83
91
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Engineering Problem Solving with C++, 3e Chapter 7 Test Bank
A. The size of the array must be specified when the program is written.
B. C++ does not do range checking on array subscripts.
C. The assignment operator may not be used to copy one array to another.
D. All of the above are restrictions on arrays in C++.
10. Which of the following is true for C-style strings
A. C-style strings may be input and output as a unit.
B. The size of the array holding the C-style string is changed based on the value in the string.
C. C++ performs range checking when subscripts are used to access the individual characters of a C
style string
D. None of the above is true about C-style strings
11. A C-style string is represented as
A. An array of just the characters in the string.
B. An array of characters terminated by the \n character.
C. An array of characters and the number of characters in the string.
D. An array of characters terminated by the \0 character.
Engineering Problem Solving with C++, 3e Chapter 7 Test Bank
12. C++ can compare one string object with another using:
A. strcpy()
B. >
C. strcmp()
D. strcat()
13. The C++ function which is used to attach one C-style string to another is:
A. strcpy()
B. strchr()
C. strcmp()
D. strcat()
14. Given the declaration char Sentence[15]; and that the data entered from the keyboard is:
The game is today
what is the value stored into Sentence by the statement: cin >> Sentence;
A. The
B. The game is
C. The game is tod
D. None of the above.
15. When declaring a parameter, pass by value is the default for which of the following data
types.
A. one dimensional arrays
B. C-style strings
C. string objects (i.e. identifiers declared to be type string)
D. None of the above have pass by value as the default.
16. If a subscript in a C++ program is outside of the declared range for that array
A. the “bad” subscript is used.
B. an error message specifying that the subscript is out of range is always generated.
C. A and B are both true.
D. Neither A nor B is true.
17. Given the declarations, string name1(“Joe”), name2(“Jack”); the expression
(name1 < name2) evaluates as true.
A. True
B. False
18. The value placed in the [ ] when declaring an array in C++ is the last subscript of the array.
A. True
B. False
19. When an array is passed to a function the modifier const is placed before the parameter
declaration, if the function should not modify the array.
A. True
B. False
Engineering Problem Solving with C++, 3e Chapter 7 Test Bank
20. If a subscript in a C++ program is outside of the declared range for that array an error
message specifying that the subscript is out of range will always be generated.
A. True
B. False
21. A C-style string is declared as a character array, but in memory the sequence of characters
must be terminated by the ‘\n’ character.
A. True
B. False
22. One difference between C-style strings and string objects (variables declared with the type
string) is that string objects can use the assignment operator but C-style strings can not.
A. True
B. False
23. The input operator >> cannot be used to input a C-style string that contains embedded blank
spaces.
A. True
B. False
24. The Selection Sort compares adjacent elements in an array and if they are out of order the
two elements are swapped, thus small element move toward the top while the largest element
in the array ends up at the bottom in the first pass.
A. True
B. False
25. It is generally more useful for a searching algorithm to return where the key value is located
in the array, and a special value if it is not found, than to return a Boolean value specifying
that it is or is not in the array.
A. True
B. False
26. A Binary search can be performed successfully on an unordered array.
A. True
B. False
27. Assuming the declaration statement char sentence[] = “Breath deeply”; the statement
cout << sentence; will print the entire string Breath deeply.
A. True
B. False
28. The size of a string object can be changed using the resize member function.
A. True
B. False
29. Invalid references to array elements are always reported, either by the compiler or at run
time.
A. True
B. False
30. Which of the following operators has the highest precedence?
A. ,
B. ?:
C. *
D. []
31. Which of the following operators has the lowest precedence?
A. ,
B. ?:
C. *
D. []
32. An array identifier, without subscripts, references the starting address (first element) of the
array.
A. True
B. False
33. Show the output generated by the following program segment. Assume all necessary header
files have been included:
vector<int> v(5);
for(int& i:v){
v = count++;
cout << v[0] << ‘,’ << v[4] << endl;
34. Frequently used classes and functions may be stored in separate, custom header files to allow
them to easily be included in other problem solutions.
A. True
B. False
35. Write a C++ class declaration named Card to implement the following UML class diagram
Card
+Card()
+Card(char, int)
+int getRank()
+int getSuit()