3.13 String access operations

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the length of string "Hey"?

3

For string "Light", what is t's index?

4

userText is "March 17, 2034". What character does userText.at(userText.size() - 1) return?

4

For string "Light", what is L's index?

0

For string "Light", what is i's index?

1

Given string userString is "Run!". Indicate char x's value. x = userString.at(3);

!

Given string firstName is "Ron". What is firstName after: firstName.at(0) = 'XX';

(error)

Given string firstName is "Ron". What is firstName after: firstName.at(3) = '!';

(error)

Given string userString is "Run!". Indicate char x's value. x = userString.at(4);

(error)

For string "Oh my", which character is at index 2?

(space)

userText is "March 17, 2034". What is the index of the last character in userText?

13

userText is "March 17, 2034". What does userText.size() return?

14

What is the index of the last letter in "Hey"?

2

For each question userString is initially "Done". Indicate userString's value after the statment provided. Do not type quotes in your answer, so type Done rather than "Done". If appropriate, type: Error userString.append(" now");

Done now

For each question userString is initially "Done". Indicate userString's value after the statement provided. Do not type quotes in your answer, so type Done rather than "Done". If appropriate, type: Error userString.append("!");

Done!

For each question userString is initially "Done". Indicate userString's value after the statment provided. Do not type quotes in your answer, so type Done rather than "Done". If appropriate, type: Error anotherString = "yet..."; userString.append(anotherString);

Doneyet...

For each question userString is initially "Done". Indicate userString's value after the statment provided. Do not type quotes in your answer, so type Done rather than "Done". If appropriate, type: Error userString.at(userString.size() - 1) = 't';

Dont

Is a string's length the same as a string's last index? _____, length is one greater (type this too)

No, length is 1 greater

For string "You wish!", which character is at index 9?

None

Given string userString is "Run!". Indicate char x's value. x = userString.at(0);

R

Given string firstName is "Ron". What is firstName after: firstName.at(1) = '@';

R@n

Assign the size of userInput to stringSize. Ex: if userInput = "Hello", output is: Size of userInput: 5 #include <iostream> #include <string> using namespace std; int main() { string userInput; int stringSize = 0; userInput = "Hello"; /* Your solution goes here */ cout << "Size of userInput: " << stringSize << endl; return 0; }

stringSize = userInput.length();

Write an expression to detect that the first character of userInput matches firstLetter. #include <iostream> #include <string> using namespace std; int main() { string userInput; char firstLetter = '-'; userInput = "banana"; firstLetter = 'b'; if (/* Your solution goes here */) { cout << "Found match: " << firstLetter << endl; } else { cout << "No match: " << firstLetter << endl; } return 0; }

userInput. at() == firstLetter

For string "You wish!", which character is at index 4?

w

For each question userString is initially "Done". Indicate userString's value after the statment provided. Do not type quotes in your answer, so type Done rather than "Done". If appropriate, type: Error userString.append('?');

Error

For each question userString is initially "Done". Indicate userString's value after the statment provided. Do not type quotes in your answer, so type Done rather than "Done". If appropriate, type: Error userString.at(user.String()) = 't';

Error

userText is "Monday". userText.at(7) = '!' may write to another variable's location and cause bizarre program behavior. True or False.

False

userText is "Monday". userText.at(userText.size()) yields 'y'.

False

userText is "Monday". userText[7] = '!' may write to another variable's location and cause bizarre program behavior. True or False.

True


Conjuntos de estudio relacionados

Chapter 2- The California State Department of Real Estate

View Set

Patients w/ renal Disorders (chapter. 27)

View Set