You are on page 1of 7

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 "____".
Another document from Scribd.com that is
random and unrelated content:
International donations are gratefully accepted, but we cannot make any
statements concerning tax treatment of donations received from outside
the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of other
ways including checks, online payments and credit card donations. To
donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works

Professor Michael S. Hart was the originator of the Project Gutenberg™


concept of a library of electronic works that could be freely shared with
anyone. For forty years, he produced and distributed Project
Gutenberg™ eBooks with only a loose network of volunteer support.

Project Gutenberg™ eBooks are often created from several printed


editions, all of which are confirmed as not protected by copyright in the
U.S. unless a copyright notice is included. Thus, we do not necessarily
keep eBooks in compliance with any particular paper edition.

Most people start at our website which has the main PG search facility:
www.gutenberg.org.

This website includes information about Project Gutenberg™, including


how to make donations to the Project Gutenberg Literary Archive
Foundation, how to help produce our new eBooks, and how to subscribe
to our email newsletter to hear about new eBooks.

You might also like