Which of the following displays the number of characters


Questions: 1. Which of the following displays the number of characters contained in a string variable named address?

a. cout << address.length() << endl;

b. cout << numChars(address) << endl;

c. cout << length(address) << endl;

d. cout << size.address() << endl;

2. Which of the following should a program use to store the name of any city in a string variable named city Name?

a. cin >> cityName;

b. cin(cityName);

c. getline(cityName, cin);

d. getline(cin, cityName);

3. If the amount variable contains the string "$56.55", which of the following statements will remove the dollar sign from the variable's contents?

a. amount.erase("tiny_mce_markerquot;);

b. amount.erase(0, 1);

c. amount = amount.substr(1);

d. both b and c

4. If the state variable contains the two letters MI followed by three spaces, which of the following statements will remove the three spaces from the variable's contents?

a. state.erase(" ");

b. state.erase(3, "");

c. state.remove(2, 3);

d. none of the above

5. What is the subscript of the first character contained in a string variable?

a. 0 (zero)

b. 1 (one)

6. Which of the following determines whether the string stored in the part variable begins with the letter A?

a. if (part.begins("A"))

b. if (part.beginswith("A"))

c. if (part.substr(0, 1) == "A")

d. if (part.substr(1) == "A")

7. Which of the following determines whether the string stored in the part variable ends with the letter B?

a. if (part.ends("B"))

b. if (part.endswith("B")

c. if (part.substr(part.length() - 1, 1) == "B")

d. none of the above

8. Which of the following statements assigns the first three characters in the part variable to the code variable?

a. code = part.assign(0, 3);

b. code = part.substr(0, 3);

c. code = part.substr(1, 3);

d. code = part.substring(0, 3);

9. If the word variable contains the string "Bells", which of the following statements will change the contents of the variable to "Bell"?

a. word.erase(word.length() - 1, 1);

b. word.replace(word.length() - 1, 1, "");

c. word = word.substr(0, word.length() - 1);

d. all of the above

10. Which of the following statements changes the contents of the word variable from "men" to "mean"?

a. word.addTo(2, "a");

b. word.insert(2, "a");

c. word.insert(3, "a");

d. none of the above

11. If the msg variable contains the string "Happy holidays", what will the cout?

12. If the msg variable contains the string "Happy holidays", what will the location = msg.find("Day", 0); statement assign to the location variable?

a. -1

b. 0

c. 10

d. 11

13. Which of the following statements assigns the location of the comma in the amount variable to an int variable named loc?

a. loc = amount.contains(",");

b. loc = amount.substr(",");

c. loc = amount.find(",", 0);

d. none of the above

14. Which of the following searches for the string "CA" in a string variable named state and then assigns the result to an int variable named result? The search should begin with the character located in subscript 5 in the state variable. The state variable's contents are uppercase.

a. result = find(state, 5, "CA");

b. result = state.find(5, "CA");

c. result = state.find("CA", 5);

d. result = state.find("CA", 5, 2);

15. If the state variable contains the string "San Francisco, CA", what will the correct statement in Question 14 assign to the result variable?

a. -1

b. 0

c. 11

d. 15

16. Which of the following replaces the two characters located in subscripts 4 and 5 in a string variable named code with the string "AB"?

a. code.replace(2, 4, "AB");

b. code.replace(4, 2, "AB");

c. code.replace(4, 5, "AB");

d. replace(code, 4, "AB");

17. Which of the following assigns five asterisks to a string variable named divider?

a. divider.assign(5, '*');

b. divider.assign(5, "*");

c. divider.assign('*', 5);

d. assign(divider, '*', 5);

18. Which of the following concatenates the contents of a string variable named city, a comma, a space, and the contents of a string variable named state and then assigns the result to a string variable named cityState?

a. cityState = "city" + ", " + "state";

b. cityState = city + ", " + state;

c. cityState = city & ", " & state;

d. cityState = "city, + state";

19. Which of the following assigns the fifth character in the word variable to the letter variable?

a. letter = word.substr(4);

b. letter = word.substr(4, 1);

c. letter = word(5).substring;

d. letter = substring(word, 5);

20. Which of the following statements tells the computer to consume the next 100 characters?

a. cin.ignore(100);

b. cin.ignore('100');

c. ignore(cin, 100);

d. none of the above

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Which of the following displays the number of characters
Reference No:- TGS02379338

Now Priced at $10 (50% Discount)

Recommended (96%)

Rated (4.8/5)