Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92392509
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As