You are on page 1of 12

Name: Class: Date:

Chapter 7

C++ Programming From Problem Analysis


to Program Design 8th Edition Malik
Full download at link:

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


analysis-to-program-design-8th-edition-by-malik-isbn-9781337102087/

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


from-problem-analysis-to-program-design-8th-edition-by-malik-isbn-
9781337102087/
1. The following is a legal C++ enumeration type:

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


a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 469
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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

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


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 469
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


Copyright Cengage Learning. Powered by Cognero. Page 1
Name: Class: Date:

Chapter 7
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 469
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 475
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 475
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 475
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

Copyright Cengage Learning. Powered by Cognero. Page 2


Name: Class: Date:

Chapter 7
7. The following statement creates an anonymous type:

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


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 477
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 488
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 488
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 494
QUESTION TYPE: True / False
HAS VARIABLES: False
Copyright Cengage Learning. Powered by Cognero. Page 3
Name: Class: Date:

Chapter 7
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

11. 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 b. GM
c. TOYOTA d. HONDA
ANSWER: b
POINTS: 1
REFERENCES: 468-470
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

12. Consider the declaration:


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

Which of the following statements is true?

a. SOCCER-- = BASEBALL b. BASEBALL++ = SOCCER


c. HOCKEY + FOOTBALL < SOCCER d. FOOTBALL <= SOCCER
ANSWER: d
POINTS: 1
REFERENCES: 471
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/16/2016 9:32 AM

13. What is the output of the following code?

enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS};


courses registered;
registered = ALGEBRA;
cout << registered << endl;
a. ALGEBRA b. 0
c. 1 d. "ALGEBRA"
Copyright Cengage Learning. Powered by Cognero. Page 4
Name: Class: Date:

Chapter 7
ANSWER: b
POINTS: 1
REFERENCES: 474
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

14. 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;
ANSWER: d
POINTS: 1
REFERENCES: 476
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

15. 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;
ANSWER: d
POINTS: 1
REFERENCES: 477
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

16. In C++, you can create aliases to a previously defined data type by using the ____ statement.
a. typedef b. using
c. namespace d. alias
ANSWER: a
POINTS: 1
REFERENCES: 477
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False

Copyright Cengage Learning. Powered by Cognero. Page 5


Name: Class: Date:

Chapter 7
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. deftype b. typedef
c. typecc d. alias
ANSWER: b
POINTS: 1
REFERENCES: 477
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. typedef integer; b. typedef int;
c. typedef int integer; d. typedef integer int;
ANSWER: c
POINTS: 1
REFERENCES: 478
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. . b. ?
c. : d. ::
ANSWER: d
POINTS: 1
REFERENCES: 488
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

20. The scope of a namespace member is local to the ____.


a. function b. block
c. file d. namespace
ANSWER: d
POINTS: 1
REFERENCES: 488
QUESTION TYPE: Multiple Choice
Copyright Cengage Learning. Powered by Cognero. Page 6
Name: Class: Date:

Chapter 7
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

21. 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();
ANSWER: c
POINTS: 1
REFERENCES: 488
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

22. 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;
ANSWER: d
POINTS: 1
REFERENCES: 488-489
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

23. The identifiers in the system-provided header files such as iostream, cmath, and iomanip are defined in the
namespace ____.
a. cctype b. stdl
c. std d. stdlib
ANSWER: c
POINTS: 1
REFERENCES: 492
Copyright Cengage Learning. Powered by Cognero. Page 7
Name: Class: Date:

Chapter 7
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

24. Before using the data type string, the program must include the header file ____.
a. enum b. iostream
c. string d. std
ANSWER: c
POINTS: 1
REFERENCES: 492
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

25. Suppose str = "xyzw";. After the statement str[2] = 'Y'; The value of str is "____".
a. xyzw b. xYzw
c. xyYw d. xzYw
ANSWER: c
POINTS: 1
REFERENCES: 493
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

26. 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 b. xyz
c. abc-xyz d. xyz-abc
ANSWER: c
POINTS: 1
REFERENCES: 493
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

27. The data type string has a named constant, ____, associated with it.
Copyright Cengage Learning. Powered by Cognero. Page 8
Name: Class: Date:

Chapter 7
a. string::size b. string::size_type
c. string::pos d. string::npos
ANSWER: d
POINTS: 1
REFERENCES: 496
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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

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

is ____.
a. 7 b. 8
c. 9 d. 10
ANSWER: c
POINTS: 1
REFERENCES: 498
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

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


a. 11 b. 12
c. 13 d. 14
ANSWER: c
POINTS: 1
REFERENCES: 497-498
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

30. 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 b. 4
c. 6 d. 7
Copyright Cengage Learning. Powered by Cognero. Page 9
Name: Class: Date:

Chapter 7
ANSWER: a
POINTS: 1
REFERENCES: 500
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

31. Considering the statement string str = "Gone with the wind";, the output of the statement cout <<
str.find("the") << endl; is ____.
a. 9 b. 10
c. 11 d. 12
ANSWER: b
POINTS: 1
REFERENCES: 500
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

32. 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 b. BCDE
c. BCD d. CDE
ANSWER: b
POINTS: 1
REFERENCES: 503-504
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

33. The ____ function is used to interchange the contents of two string variables.
a. iterator b. traverse
c. swap d. change
ANSWER: c
POINTS: 1
REFERENCES: 505
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
Copyright Cengage Learning. Powered by Cognero. Page 10
Name: Class: Date:

Chapter 7
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

34. 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 b. with
c. the d. wind
ANSWER: b
POINTS: 1
REFERENCES: 503-504
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

35. The values in the domain of an enumeration type are called ____________________.
ANSWER: enumerators
POINTS: 1
REFERENCES: 469
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

36. A data type wherein you directly specify values in the variable declaration with no type name is called a(n)
____________________type.
ANSWER: anonymous
POINTS: 1
REFERENCES: 477
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

37. In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the problem of
overlapping global identifiers.
ANSWER: namespace
POINTS: 1
REFERENCES: 487
QUESTION TYPE: Completion
HAS VARIABLES: False
Copyright Cengage Learning. Powered by Cognero. Page 11
Name: Class: Date:

Chapter 7
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

38. 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.
ANSWER: syntax
POINTS: 1
REFERENCES: 487
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

39. The string expression strVar.____________________ inserts all the characters of str at index pos into
strVar.
ANSWER: insert(pos, str);
POINTS: 1
REFERENCES: 497
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

40. The string expression strVar.____________________ starts at index pos, replaces the next n characters of
strVar with all the characters of str.
ANSWER: strVar.replace(pos, n, str);
POINTS: 1
REFERENCES: 497
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/5/2016 1:40 PM

Copyright Cengage Learning. Powered by Cognero. Page 12

You might also like