Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use pen and paper to answer the following question: Here is another question: Please explain what is the output of this code fragment and
Please use pen and paper to answer the following question:
Here is another question:
Please explain what is the output of this code fragment and why?
The topic is about C++. Please give full explanations. Thanks.
Consider the following code fragment: string strl; str2; getline (cin, strl); a. Write a single-statement for loop that will output each character of strl on a separate line as fol- lows (e.g.) 1 b. Write a for loop to construct a string, str2 that is exactly the same as str1 but without the last character. Use indexing and the length method only. Do not use any other functions: c. Now write a single C+ statement that will accomplish the same thing as the previous problem us- ing only the length and substr methods (i.e., do not use indexing or loops): d. Assuming that there is an equal sign Csomewhere in strl, write the statement or statements that will save all the characters to the left of the equal sign in str2: [Hint: use the find and sub- str methods ] e. If the input string didn't contain an equal sign, what value would the find method return? f. Write the statement or statements that will find the first occurrence of a comma C, ) in strl and print either"the comma is at index: n" (where n is the index of the comma), or "no comma found" if no comma is found in the string: bool mystery(string fstr). string rstr-""; for (int i-fstr.length ()-1; i>-0i) rstr +-fstr[i]; return rstrfstriStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started