Deck 18: Class String and String Stream Processing

Full screen (f)
exit full mode
Question
Which of the following is false?

A) If a string is converted to a C-style array using data, modifying the string could cause the pointer previously returned by data to become invalid.
B) Converting a string containing one or more null characters to a C-style string can cause logic errors.
C) c_str returns a character array of the same length as the string object it is called on.
D) copy implicitly converts a string to a non-null terminated character array.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following is not overloaded for strings?

A) -=
B) >>
C) +=
D) getline)
Question
Which of the following returns a bool?

A) length
B) empty
C) capacity
D) resize
Question
The arguments passed to replace do not include:

A) The subscript of the element where the replace operation ends.
B) The subscript of the element where the replace operation begins.
C) A replacement character string from which a substring is used to replace characters.
D) The element in the replacement character string where the replacement substring begins.
Question
If string s1 has the value "computer" and string s2 has the value "promise", which call to insert will produce the string "compromise"?

A) s1.insert 4, s2, 0, string::npos );
B) s1.insert string::npos, s2, 0, 4 );
C) s2.insert 0, s1, 0, 3 );
D) s2.insert 3, s1, 0, 3 );
Question
If string s contains "antidisestablishmentarianism", then s.substr 7, 13 ) would be:

A) "establish"
B) "ishmenta"
C) "establi"
D) "establishment"
Question
What type of value is returned by the overloaded equality and relational operators for strings?

A) int
B) bool
C) double
D) null
Question
The function call string1.erase 5 ) will:

A) Return a copy of string1 minus the character that occupied position 5.
B) Erase all characters up to and including the character in position 5 from string1.
C) Erase all characters starting from and including the character in position 5 to the end of string1.
D) Return a copy of string1 minus every fifth character.
Question
Which of the following would not return string::npos when used on the string s which contains "rack":

A) s.find_first_not_of "crackling" );
B) s.find_first_not_of "packrat" );
C) s.rfind "car" );
D) s.find "ack" );
Question
Strings:

A) Can use the subscript operator to access individual characters.
B) Must be null-terminated.
C) Are pointers.
D) Have a first subscript of 1.
Question
If string s1 is lexicographically greater than string s2, then the value returned by s2.compare0, s2.size), s1) must be?

A) 0
B) -1
C) A negative number.
D) A positive number.
Question
Class string has member function __________ to interchange the data stored in two string objects

A) exchange
B) switch
C) swap
D) copyto
Question
Which of the following cannot be used to concatenate strings?

A) +
B) +=
C) append
D) assign
Question
Which of the following searches through a string object from right-to-left?

A) find
B) find_first_of
C) find_last_of
D) find_first_not_of
Question
Iterators do not:

A) Allow the characters to be modified.
B) Allow backward traversal of strings.
C) Have range checking.
D) Have syntax similar to pointer operations.
Question
Given the strings defined below, which statement will not return 0?
String s1 = "Mighty Mouse";
String s2 = "Mickey Mouse";

A) s1.compare 0, 3, s2, 0, 3 );
B) s1.compare 7, 5, s2, 7, 5 );
C) s1.compare 8, 12, s2, 8, 12 );
D) s1.compare 7, 11, s2, 7, 11 );
Question
Which function changes the actual string stored in the string object i.e., is not a const member function)?

A) length
B) empty
C) capacity
D) resize
Question
Which of the following is an invalid definition?

A) string sa = "computers";
B) string sb "computers" );
C) string sc 'c' );
D) string sd 9, 'c' );
Question
The total number of elements that can be stored in a string without increasing its current amount of allocated memory is called its:

A) Size.
B) Length.
C) Capacity.
D) Maximum size.
Question
Which of the following is not an argument of the assign member function?

A) The start location.
B) The number of characters to copy.
C) The end location.
D) The string to copy.
Question
The capabilities of inputting and outputting strings in memory are known as:

A) String i/o manipulation.
B) String stream processing.
C) Character handling.
D) Dynamic string operations.
Question
Which of the following does not apply to an istringstream object?

A) Data is stored in the object as characters.
B) Input from the object works identically to input from any file stream.
C) Data in a string can be appended to it.
D) It is used to inputs data from a string in memory to program variables.
Question
All of the following are true of an ostringstream object except that:

A) It uses a string to store output data.
B) A stream insertion operation cannot be used to append additional data to it.
C) The string data it stores is dynamically allocated.
D) The data it stores can be accessed using the function str.
Question
What is the code for a loop that iterates from the end of a string toward the beginning?

A) string::reverse_iterator i = s.begin) while i != s.end) )
{
Cout << *i;
++i;
}
B) string::reverse_iterator i = s.rbegin) while i != s.rend) )
{
Cout << *i;
++i;
}
C) string::reverse_iterator i = s.end) while i != s.begin) )
{
Cout << *i;
--i;
}
D) string::reverse_iterator i = s.rbegin) while i != s.rend) )
{
Cout << *i;
--i;
}
Question
Which of the following provides bounds checking?

A) at
B) iterator
C) reverse_iterator
D) [ ]
Question
String iterators:

A) Must be dereferenced in order to access the character at each location.
B) Are not range checked.
C) Come in const and non-const forms.
D) All of the above.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/26
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 18: Class String and String Stream Processing
1
Which of the following is false?

A) If a string is converted to a C-style array using data, modifying the string could cause the pointer previously returned by data to become invalid.
B) Converting a string containing one or more null characters to a C-style string can cause logic errors.
C) c_str returns a character array of the same length as the string object it is called on.
D) copy implicitly converts a string to a non-null terminated character array.
C
2
Which of the following is not overloaded for strings?

A) -=
B) >>
C) +=
D) getline)
A
3
Which of the following returns a bool?

A) length
B) empty
C) capacity
D) resize
B
4
The arguments passed to replace do not include:

A) The subscript of the element where the replace operation ends.
B) The subscript of the element where the replace operation begins.
C) A replacement character string from which a substring is used to replace characters.
D) The element in the replacement character string where the replacement substring begins.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
5
If string s1 has the value "computer" and string s2 has the value "promise", which call to insert will produce the string "compromise"?

A) s1.insert 4, s2, 0, string::npos );
B) s1.insert string::npos, s2, 0, 4 );
C) s2.insert 0, s1, 0, 3 );
D) s2.insert 3, s1, 0, 3 );
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
6
If string s contains "antidisestablishmentarianism", then s.substr 7, 13 ) would be:

A) "establish"
B) "ishmenta"
C) "establi"
D) "establishment"
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
7
What type of value is returned by the overloaded equality and relational operators for strings?

A) int
B) bool
C) double
D) null
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
8
The function call string1.erase 5 ) will:

A) Return a copy of string1 minus the character that occupied position 5.
B) Erase all characters up to and including the character in position 5 from string1.
C) Erase all characters starting from and including the character in position 5 to the end of string1.
D) Return a copy of string1 minus every fifth character.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following would not return string::npos when used on the string s which contains "rack":

A) s.find_first_not_of "crackling" );
B) s.find_first_not_of "packrat" );
C) s.rfind "car" );
D) s.find "ack" );
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
10
Strings:

A) Can use the subscript operator to access individual characters.
B) Must be null-terminated.
C) Are pointers.
D) Have a first subscript of 1.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
11
If string s1 is lexicographically greater than string s2, then the value returned by s2.compare0, s2.size), s1) must be?

A) 0
B) -1
C) A negative number.
D) A positive number.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
12
Class string has member function __________ to interchange the data stored in two string objects

A) exchange
B) switch
C) swap
D) copyto
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following cannot be used to concatenate strings?

A) +
B) +=
C) append
D) assign
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following searches through a string object from right-to-left?

A) find
B) find_first_of
C) find_last_of
D) find_first_not_of
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
15
Iterators do not:

A) Allow the characters to be modified.
B) Allow backward traversal of strings.
C) Have range checking.
D) Have syntax similar to pointer operations.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
16
Given the strings defined below, which statement will not return 0?
String s1 = "Mighty Mouse";
String s2 = "Mickey Mouse";

A) s1.compare 0, 3, s2, 0, 3 );
B) s1.compare 7, 5, s2, 7, 5 );
C) s1.compare 8, 12, s2, 8, 12 );
D) s1.compare 7, 11, s2, 7, 11 );
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
17
Which function changes the actual string stored in the string object i.e., is not a const member function)?

A) length
B) empty
C) capacity
D) resize
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following is an invalid definition?

A) string sa = "computers";
B) string sb "computers" );
C) string sc 'c' );
D) string sd 9, 'c' );
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
19
The total number of elements that can be stored in a string without increasing its current amount of allocated memory is called its:

A) Size.
B) Length.
C) Capacity.
D) Maximum size.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following is not an argument of the assign member function?

A) The start location.
B) The number of characters to copy.
C) The end location.
D) The string to copy.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
21
The capabilities of inputting and outputting strings in memory are known as:

A) String i/o manipulation.
B) String stream processing.
C) Character handling.
D) Dynamic string operations.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following does not apply to an istringstream object?

A) Data is stored in the object as characters.
B) Input from the object works identically to input from any file stream.
C) Data in a string can be appended to it.
D) It is used to inputs data from a string in memory to program variables.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
23
All of the following are true of an ostringstream object except that:

A) It uses a string to store output data.
B) A stream insertion operation cannot be used to append additional data to it.
C) The string data it stores is dynamically allocated.
D) The data it stores can be accessed using the function str.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
24
What is the code for a loop that iterates from the end of a string toward the beginning?

A) string::reverse_iterator i = s.begin) while i != s.end) )
{
Cout << *i;
++i;
}
B) string::reverse_iterator i = s.rbegin) while i != s.rend) )
{
Cout << *i;
++i;
}
C) string::reverse_iterator i = s.end) while i != s.begin) )
{
Cout << *i;
--i;
}
D) string::reverse_iterator i = s.rbegin) while i != s.rend) )
{
Cout << *i;
--i;
}
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following provides bounds checking?

A) at
B) iterator
C) reverse_iterator
D) [ ]
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
26
String iterators:

A) Must be dereferenced in order to access the character at each location.
B) Are not range checked.
C) Come in const and non-const forms.
D) All of the above.
Unlock Deck
Unlock for access to all 26 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 26 flashcards in this deck.