Professional Documents
Culture Documents
C++ Programming From Problem Analysis To Program Design 6th Edition Malik Test Bank 1
C++ Programming From Problem Analysis To Program Design 6th Edition Malik Test Bank 1
Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type
TRUE/FALSE
MULTIPLE CHOICE
The statement:
a. FORD c. TOYOTA
b. GM d. HONDA
ANS: B PTS: 1 REF: 453-455
a. ALGEBRA c. 1
b. 0 d. "ALGEBRA"
ANS: B PTS: 1 REF: 458
6. In C++, you can create aliases to a previously defined data type by using the ____ statement.
a. typedef c. namespace
b. using d. alias
ANS: A PTS: 1 REF: 461
namespace globalType
{
void printResult();
}
13. Which of the following statements is used to simplify the accessing of all globalType namespace
members?
a. using globalType;
b. using namespace globalType:all;
c. using namespace globalType::all;
d. using namespace globalType;
ANS: D PTS: 1 REF: 472-473
14. The identifiers in the system-provided header files such as iostream, cmath, and iomanip are
defined in the namespace ____.
a. cctype c. std
b. stdl d. stdlib
ANS: C PTS: 1 REF: 476
15. Before using the data type string, the program must include the header file ____.
a. enum c. string
b. iostream d. std
ANS: C PTS: 1 REF: 476
16. Suppose str = "xyzw";. After the statement str[2] = 'Y'; The value of str is
"____".
a. xyzw c. xyYw
b. xYzw d. xzYw
ANS: C PTS: 1 REF: 477-478
17. Suppose that str1, str2, and str3 are string variables. After the following statements execute,
the value of str3 is "____".
str1 = "abc";
str2 = "xyz";
str3 = str1 + '-' + str2;
a. abc c. abc-xyz
b. xyz d. xyz-abc
ANS: C PTS: 1 REF: 477-479
18. The data type string has a named constant, ____, associated with it.
a. string::size c. string::pos
b. string::size_type d. string::npos
ANS: D PTS: 1 REF: 480
is ____.
a. 7 c. 9
b. 8 d. 10
ANS: C PTS: 1 REF: 482
22. Considering the statement string str = "Gone with the wind";, the output of the
statement cout << str.find("the") << endl; is ____.
a. 9 c. 11
b. 10 d. 12
ANS: B PTS: 1 REF: 484
After the statement str2 = str1.substr(1,4); executes, the value of str2 is "____".
a. ABCD c. BCD
b. BCDE d. CDE
ANS: B PTS: 1 REF: 487-488
After the statement str2 = str1.substr(5,4); executes, the value of str2 is "____".
a. Gone c. the
b. with d. wind
ANS: B PTS: 1 REF: 487-488
25. The ____ function is used to interchange the contents of two string variables.
a. iterator c. swap
b. traverse d. change
ANS: C PTS: 1 REF: 489
COMPLETION
ANS: enumerators
2. A data type wherein you directly specify values in the variable declaration with no type name is called
a(n) ____________________type.
ANS: anonymous
3. In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the
problem of overlapping global identifiers.
ANS: namespace
4. If a global identifier in a program has the same name as one of the global identifiers in the header file,
the compiler generates a(n) ____________________ error.
ANS: syntax
5. Suppose that str1 and str2 are string variables. After the following statements execute, the
value of str2 is "____________________".
str1 = "abc";
str2 = str1 + '-';
str2 = str2 + "xyz";
ANS: abc-xyz
6. Suppose str = "abcd". After the statement str = str + "ABCD"; the value of str is
"____________________".
ANS: abcdABCD
7. Suppose str = "abcd"; After the statement str[1] = 'A'; The value of str is
"____________________".
ANS: aBcd
8. For the operator + to work with the string data type, one of the operands of + must be a(n)
____________________ variable.
ANS: string
9. The data type string has a named constant, ____________________, associated with it.
ANS: string::npos
ANS: erase(pos, n)
11. The string expression strVar.____________________ inserts all the characters of str at index
pos into strVar.
12. The string expression strVar.____________________ returns the index of the first occurrence
at or after pos where str is found in strVar.
ANS: find(str, pos);
13. The string expression strVar.____________________ starts at index pos, replaces the next n
characters of strVar with all the characters of str.
is ____________________.
ANS: 7
ANS: 12