Display number of characters contained in a string variable

Assignment Help C/C++ Programming
Reference no: EM131583794

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

Reference no: EM131583794

Questions Cloud

Discuss the differences in the number of people : Explain the person you are describing. Discuss what their daily life is like, from the time they wake up to the time they go to bed.
Describe the criteria to rank capital budgeting decisions : A summary of how you will describe the criteria to rank capital budgeting decisions and whether some criteria are more important than others.
Review the document defining the dissertation roles : Review the document defining the Dissertation Roles and Responsibilities on the DC Network. Find it using the DC Network search function.
Define the stock value : Your portfolio is 280 shares of Barden, Inc. The stock currently sells for $98 per share. Assuming no taxes, how much will your stock be worth on April 19?
Display number of characters contained in a string variable : Which of the following displays the number of characters contained in a string variable named address?
What specific topics do you plan to discuss : What specific topics do you plan to discuss? Why did you make these topic choices? You may have time to cover about five issues.
What attribute of a work environment : What attribute of a work environment do you feel has the greatest influence in determining whether the environment becomes hostile or not?
Research work on the study of minor irrigation : Prepare a research work on the study of Minor Irrigation and Water Resources in the History Of Telangana for the past 60 years.
Positioning for the present and adapting to the future : "Strategy has two major dimensions: positioning for the present and adapting to the future".

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd