Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

C++ Programming From Problem Anal-

ysis to Program Design 6th Edition Ma-


lik
Full download at link:

Test bank: https://testbankpack.com/p/test-bank-for-c-programming-


from-problem-analysis-to-program-design-6th-edition-by-malik-isbn-
1133626386-9781133626381/

Solution Manual: https://testbankpack.com/p/solution-manual-for-c-


programming-from-problem-analysis-to-program-design-6th-edition-
by-malik-isbn-1133626386-9781133626381/

Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type

TRUE/FALSE

1. The following is a legal C++ enumeration type:

enum colorType {BLUE, GREEN, PINK, YELLOW, RED};

ANS: T PTS: 1 REF: 453

2. The following is a valid C++ enumeration type:

enum places {1ST, 2ND, 3RD, 4TH};.

ANS: F PTS: 1 REF: 453

3. No arithmetic operations are allowed on the enumeration type.

ANS: T PTS: 1 REF: 455

4. A function cannot return the value of an enumeration type.

ANS: F PTS: 1 REF: 459

5. An enumeration type can be passed as a parameter to a function only by value.

ANS: F PTS: 1 REF: 459


6. An anonymous type can be passed as a parameter to a function.

ANS: F PTS: 1 REF: 461

7. The following statement creates an anonymous type:

enum {1ST, 2ND, 3RD, 4TH} places;

ANS: F PTS: 1 REF: 461

8. The general syntax for accessing a namespace member is: namespace_name->identifier.

ANS: F PTS: 1 REF: 472

9. In C++, namespace is a reserved word.

ANS: T PTS: 1 REF: 472

10. In C++, [] is called the array subscript operator.

ANS: T PTS: 1 REF: 477

MULTIPLE CHOICE

1. Suppose that you have the following declaration.

enum cars {FORD, GM, TOYOTA, HONDA};


cars domesticCars = FORD;

The statement:

domesticCars = static_cast<cars>(domesticCars + 1);

sets the value of domesticCars to ____.

a. FORD c. TOYOTA
b. GM d. HONDA
ANS: B PTS: 1 REF: 453-455

2. Consider the declaration:

enum sports {BASKETBALL, FOOTBALL, HOCKEY, BASEBALL, SOCCER};

which of the following statements is true?

a. SOCCER-- = BASEBALL c. HOCKEY + FOOTBALL < SOCCER


b. BASEBALL++ = SOCCER d. FOOTBALL <= SOCCER
ANS: D PTS: 1 REF: 455

3. What is the output of the following code?


enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS};
courses registered;
registered = ALGEBRA;
cout << registered << endl;

a. ALGEBRA c. 1
b. 0 d. "ALGEBRA"
ANS: B PTS: 1 REF: 458

4. Which of the following statements declares the studentGrade variable?


a. enum studentGrade {A, B, C, D, F};
b. enum int {A, B, C, D, F} studentGrade;
c. enum studentGrade {A, B, C, D, F} grades;
d. enum grades {A, B, C, D, F} studentGrade;
ANS: D PTS: 1 REF: 460

5. Which of the following statements creates an anonymous type?


a. enum grades {A, B, C, D, F};
b. enum grades {};
c. enum {};
d. enum {A, B, C, D, F} grades;
ANS: D PTS: 1 REF: 461

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

7. In C++, ____ is a reserved word.


a. deftype c. typecc
b. typedef d. alias
ANS: B PTS: 1 REF: 461

8. Which of the following is a valid C++ statement?


a. typedef integer; c. typedef int integer;
b. typedef int; d. typedef integer int;
ANS: C PTS: 1 REF: 462

9. In July ____, ANSI/ISO Standard C++ was officially approved.


a. 1996 c. 1999
b. 1998 d. 2000
ANS: B PTS: 1 REF: 471

10. In C++, ____ is called the scope resolution operator.


a. . c. :
b. ? d. ::
ANS: D PTS: 1 REF: 472
11. The scope of a namespace member is local to the ____.
a. function c. file
b. block d. namespace
ANS: D PTS: 1 REF: 472

12. Given the following code

namespace globalType
{
void printResult();
}

which of the following statements is needed to access printResult?


a. globalType.printResult();
b. globalType.printResult;
c. globalType::printResult();
d. globalType:printResult();
ANS: C PTS: 1 REF: 472

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

19. Suppose str = "ABCDEFGHI". The output of the statement

cout << str.length() << endl;

is ____.
a. 7 c. 9
b. 8 d. 10
ANS: C PTS: 1 REF: 482

20. The length of the string "Hello There. " is ____.


a. 11 c. 13
b. 12 d. 14
ANS: C PTS: 1 REF: 481-482

21. Consider the following statements:

string str = "ABCDEFD";


string::size_type position;

After the statement position = str.find('D'); executes, the value of position is


____.
a. 3 c. 6
b. 4 d. 7
ANS: A PTS: 1 REF: 484

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

23. Consider the following statements:

string str1 = "ABCDEFGHIJKLM";


string str2;

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

24. Consider the following statements:

string str1 = "Gone with the wind";


string str2;

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

1. The values in the domain of an enumeration type are called ____________________.

ANS: enumerators

PTS: 1 REF: 453

2. A data type wherein you directly specify values in the variable declaration with no type name is called
a(n) ____________________type.

ANS: anonymous

PTS: 1 REF: 461

3. In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the
problem of overlapping global identifiers.

ANS: namespace

PTS: 1 REF: 471

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

PTS: 1 REF: 471

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

PTS: 1 REF: 477

6. Suppose str = "abcd". After the statement str = str + "ABCD"; the value of str is
"____________________".

ANS: abcdABCD

PTS: 1 REF: 477

7. Suppose str = "abcd"; After the statement str[1] = 'A'; The value of str is
"____________________".

ANS: aBcd

PTS: 1 REF: 478

8. For the operator + to work with the string data type, one of the operands of + must be a(n)
____________________ variable.

ANS: string

PTS: 1 REF: 478

9. The data type string has a named constant, ____________________, associated with it.

ANS: string::npos

PTS: 1 REF: 480

10. The string expression strVar.____________________ deletes n characters from strVar


starting at position pos.

ANS: erase(pos, n)

PTS: 1 REF: 480

11. The string expression strVar.____________________ inserts all the characters of str at index
pos into strVar.

ANS: insert(pos, str);

PTS: 1 REF: 481

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);

PTS: 1 REF: 481

13. The string expression strVar.____________________ starts at index pos, replaces the next n
characters of strVar with all the characters of str.

ANS: strVar.replace(pos, n, str);

PTS: 1 REF: 481

14. Suppose str = "ABCDEFG". The output of the statement

cout << str.length() << endl;

is ____________________.

ANS: 7

PTS: 1 REF: 482

15. The length of the string "Hello There." is ____________________.

ANS: 12

PTS: 1 REF: 482

You might also like