Deck 7: Namespaces, the Class String, and User-Defined Simple Data Types

Full screen (f)
exit full mode
Question
Which of the following is a valid C++ statement?

A) typedef integer;
B) typedef int;
C) typedef int integer;
D) typedef integer int;
Use Space or
up arrow
down arrow
to flip the card.
Question
The following is a valid C++ enumeration type:enum places {1ST, 2ND, 3RD, 4TH};.
Question
In C++, ____ is a reserved word.

A) deftype
B) typedef
C) typecc
D) alias
Question
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
Question
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;
Question
The following is a legal C++ enumeration type:enum colorType {BLUE, GREEN, PINK, YELLOW, RED};
Question
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;
Question
The scope of a namespace member is local to the ____.

A) function
B) block
C) file
D) namespace
Question
A function cannot return the value of an enumeration type.
Question
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"
Question
No arithmetic operations are allowed on the enumeration type.
Question
An enumeration type can be passed as a parameter to a function only by value.
Question
The general syntax for accessing a namespace member is: namespace_name->identifier.
Question
In C++, namespace is a reserved word.
Question
In C++, you can create aliases to a previously defined data type by using the ____ statement.

A) typedef
B) using
C) namespace
D) alias
Question
Suppose that you have the following declaration. enum cars {FORD, GM, TOYOTA, HONDA};
Cars domesticCars = FORD;
The statement:domesticCars = static_cast(domesticCars + 1);
Sets the value of domesticCars to ____.

A) FORD
B) GM
C) TOYOTA
D) HONDA
Question
In C++, ____ is called the scope resolution operator.

A) .
B) ?
C) :
D) ::
Question
The following statement creates an anonymous type:enum {1ST, 2ND, 3RD, 4TH} places;
Question
In C++, [] is called the array subscript operator.
Question
An anonymous type can be passed as a parameter to a function.
Question
The string expression strVar.____________________ inserts all the characters of str at index pos into strVar.
Question
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
Question
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
Question
The ____ function is used to interchange the contents of two string variables.

A) iterator
B) traverse
C) swap
D) change
Question
The values in the domain of an enumeration type are called ____________________.
Question
Suppose str = "ABCDEFGHI".The output of the statement cout << str.length() << endl;
Is ____.

A) 7
B) 8
C) 9
D) 10
Question
Suppose that str1, str2, and str3 are string variables.After the following statements execute, the value of str3 is "____". <strong>Suppose that str1, str2, and str3 are string variables.After the following statements execute, the value of str3 is ____.  </strong> A) abc B) xyz C) abc-xyz D) xyz-abc <div style=padding-top: 35px>

A) abc
B) xyz
C) abc-xyz
D) xyz-abc
Question
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.
Question
The data type string has a named constant, ____, associated with it.

A) string::size
B) string::size_type
C) string::pos
D) string::npos
Question
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
Question
The length of the string "Hello There." is ____.

A) 11
B) 12
C) 13
D) 14
Question
A data type wherein you directly specify values in the variable declaration with no type name is called a(n) ____________________type.
Question
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) globa
Question
Suppose str = "xyzw";.After the statement str[2] = 'Y'; The value of str is "____".

A) xyzw
B) xYzw
C) xyYw
D) xzYw
Question
In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the problem of overlapping global identifiers.
Question
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
Question
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
Question
The string expression strVar.____________________ starts at index pos, replaces the next n characters of strVar with all the characters of str.
Question
Which of the following statements is used to simplify the accessing of all globalType namespace members?

A) using globalType;
B) using namespace globa
Question
Before using the data type string, the program must include the header file ____.

A) enum
B) iostream
C) string
D) std
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 7: Namespaces, the Class String, and User-Defined Simple Data Types
1
Which of the following is a valid C++ statement?

A) typedef integer;
B) typedef int;
C) typedef int integer;
D) typedef integer int;
C
2
The following is a valid C++ enumeration type:enum places {1ST, 2ND, 3RD, 4TH};.
False
3
In C++, ____ is a reserved word.

A) deftype
B) typedef
C) typecc
D) alias
B
4
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
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;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
The following is a legal C++ enumeration type:enum colorType {BLUE, GREEN, PINK, YELLOW, RED};
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
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;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
The scope of a namespace member is local to the ____.

A) function
B) block
C) file
D) namespace
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
A function cannot return the value of an enumeration type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
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"
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
No arithmetic operations are allowed on the enumeration type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
An enumeration type can be passed as a parameter to a function only by value.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
The general syntax for accessing a namespace member is: namespace_name->identifier.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
In C++, namespace is a reserved word.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
In C++, you can create aliases to a previously defined data type by using the ____ statement.

A) typedef
B) using
C) namespace
D) alias
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
Suppose that you have the following declaration. enum cars {FORD, GM, TOYOTA, HONDA};
Cars domesticCars = FORD;
The statement:domesticCars = static_cast(domesticCars + 1);
Sets the value of domesticCars to ____.

A) FORD
B) GM
C) TOYOTA
D) HONDA
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
In C++, ____ is called the scope resolution operator.

A) .
B) ?
C) :
D) ::
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
The following statement creates an anonymous type:enum {1ST, 2ND, 3RD, 4TH} places;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
In C++, [] is called the array subscript operator.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
An anonymous type can be passed as a parameter to a function.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
The string expression strVar.____________________ inserts all the characters of str at index pos into strVar.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
The ____ function is used to interchange the contents of two string variables.

A) iterator
B) traverse
C) swap
D) change
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
The values in the domain of an enumeration type are called ____________________.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
Suppose str = "ABCDEFGHI".The output of the statement cout << str.length() << endl;
Is ____.

A) 7
B) 8
C) 9
D) 10
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
Suppose that str1, str2, and str3 are string variables.After the following statements execute, the value of str3 is "____". <strong>Suppose that str1, str2, and str3 are string variables.After the following statements execute, the value of str3 is ____.  </strong> A) abc B) xyz C) abc-xyz D) xyz-abc

A) abc
B) xyz
C) abc-xyz
D) xyz-abc
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
The data type string has a named constant, ____, associated with it.

A) string::size
B) string::size_type
C) string::pos
D) string::npos
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
The length of the string "Hello There." is ____.

A) 11
B) 12
C) 13
D) 14
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
A data type wherein you directly specify values in the variable declaration with no type name is called a(n) ____________________type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
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) globa
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
Suppose str = "xyzw";.After the statement str[2] = 'Y'; The value of str is "____".

A) xyzw
B) xYzw
C) xyYw
D) xzYw
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the problem of overlapping global identifiers.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
The string expression strVar.____________________ starts at index pos, replaces the next n characters of strVar with all the characters of str.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following statements is used to simplify the accessing of all globalType namespace members?

A) using globalType;
B) using namespace globa
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
Before using the data type string, the program must include the header file ____.

A) enum
B) iostream
C) string
D) std
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.