ch(8,9) True/False Indicate whether the statement is true or false. ____ 1. The values in the domain of an enumeration type are called enum values. ____ 2. The following is a legal C++ enumeration type: enum colorType {BLUE, GREEN, PINK, YELLOW, RED}; ____ 3. The following C++ enumeration type is illegal because DARKGREEN is not a soft color: enum softColor {LIGHTBLUE, DARKGREEN, PINK, YELLOW, WHITE};. ____ 4. The following is a valid C++ enumeration type: enum places{1ST, 2ND, 3RD, 4TH};. ____ 5. The only allowable arithmetic operations on enumeration types are addition and the increment operator. ____ 6. The values of an enumeration type cannot be output directly to the standard output device. ____ 7. A function cannot return the value of an enumeration type. ____ 8. An enumeration type can be passed as a parameter to a function only by value. ____ 9. An anonymous type can be passed as a parameter to a function. ____ 10. The following statement creates an anonymous type: enum {1ST, 2ND, 3RD, 4TH} places; ____ 11. An anonymous type is a data type that has no associated type identifier. ____ 12. In ANSI/ISO Standard C++, the namespace mechanism was designed to solve the problem of overlapping global identifiers. ____ 13. The namespace mechanism cannot be used with header files with the extension h. ____ 14. Suppose nameSpaceType is a namespace and x is a member (variable of type int) of nameSpaceType. After the statement using namespace nameSpaceType; the following statement is illegal: nameSpaceType::x = 5; ____ 15. In C++, namespace is a reserved word. ____ 16. In C++, using is not a reserved word. ____ 17. The data type string is a built-in type of the ANSI C++ language. ____ 18. To use the string functions length, substr, and swap, the program must include the header file iostream. ____ 19. It is legal to concatenate two string literals, such as "abc" and "def". ____ 20. Suppose that str is a string variable. The following statement is legal in C++: str = "abc" + "xyz"; ____ 21. The operator + can be used to concatenate two values of the type string. ____ 22. Suppose that str1 and str2 are string variables. After the following statements execute, the value of str2 is "abcxyz". str1 = "abc"; str2 = str1 + '-'; str2 = str2 + "xyz"; ____ 23. Suppose str = "abcd". After the statement str = str + "ABCD"; the value of str is "ABCD". ____ 24. Suppose str = "xyzw"; After the statement str[2] = 'Y'; The value of str is "xYzw". ____ 25. When determining the length of a string, embedded blank spaces are ignored. ____ 26. Suppose str = "ABCDEFGHI". The output of the statement cout << str.length() << endl; is 8 since the position of the first character in str is 0. ____ 27. The length of the string "Hello There." is 12. ____ 28. The function substr returns true if its second argument is a substring of its first argument. Multiple Choice Identify the choice that best completes the statement or answers the question. ____ 29. Suppose that you have the following declaration. enum cars {FORD, GM, TOYOTA, HONDA}; cars demesticCars = FORD; The statement domesticCars = static_cast<cars>(domesticCars + 1); sets the value of domesticCars to ____. a. FORD c. TOYOTA b. GM d. HONDA ____ 30. 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 ____ 31. What is the output of the following code? d. FOOTBALL <= SOCCER enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS}; courses registered; registered = ALGEBRA; cout << registered << endl; ____ 32. ____ 33. ____ 34. ____ 35. ____ 36. ____ 37. ____ 38. ____ 39. ____ 40. a. ALGEBRA c. 1 b. 0 d. "ALGEBRA" 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; 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; In C++, you can create aliases to a previously defined data type by using the ____ statement. a. typedef c. namespace b. using d. alias In C++, ____ is a reserved word. a. deftype c. typecc b. typedef d. alias Which of the following is a valid C++ statement? a. typedef integer; c. typedef int integer; b. typedef int; d. typedef integer int; In July ____, the ANSI/ISO Standard C++ was officially approved. a. 1996 c. 1999 b. 1998 d. 2000 In C++, ____ is called the scope resolution operator. a. . c. : b. ? d. :: The scope of a namespace member is local to the ____. a. function c. file b. block d. namespace 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(); ____ 41. ____ 42. ____ 43. ____ 44. d. globalType:printResult(); 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; 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 Before using the data type string, the program must include the header file ____. a. enum c. string iostream b. d. std Suppose that str1, str2, and str3 are string variables. After the following statements above execute, the value of str3 is "____". str1 = "abc"; str2 = "xyz"; str3 = str1 + '-' + str2; a. abc c. b. xyz d. ____ 45. Suppose str = "xyzw";. After the statement a. xyzw c. b. xYzw d. ____ 46. Consider the following C++ code. abc-xyz xyz-abc str[2] = 'Y'; The value of str is "____". xyYw xzYw string str = "goofy"; string newStr = ""; for (int j = 0; i < str.length(); j++) newStr = str[j] + newStr; cout << newStr << endl; The output is ____. a. goofy c. foogy b. ygoof d. yfoog ____ 47. Suppose str = "ABCDEFGHI". The output of the statement cout << str.length() << endl; is ____. a. 7 c. 9 b. 8 d. 10 ____ 48. The length of the string "Hello There. " is ____. a. 11 c. 13 b. 12 d. 14 ____ 49. 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 ____ 50. 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 ____ 51. 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 ____ 52. Consider the following statements. string str1 = "Gone with the wind"; string str2; After the statement str2 = str1.substr(5,8); executes, the value of str2 is "____". the a. Gone c. b. with d. wind ____ 53. The ____ function is used to interchange the contents of two string variables. a. iterator c. swap b. traverse d. change ch(8,9) Answer Section TRUE/FALSE 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: F T F F F T F F F F T T T F T F F F F F T F F F F F T F PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 421 421 421 421 423 424 426 426 428 428 | 421 428 441 441 | 465 442 442 443 446-447 447 | 450 447 447 447 447 447 448 450 450 450 456 PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 423 423 424-426 428 428 429 429 429 441 442 MULTIPLE CHOICE 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: B D B D D A B C B D 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: D C D C C C C D C C A B B B C PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 442 442 443 446 447 447 448 448-450 450 450 453 453 456 456 458
© Copyright 2025 Paperzz