Question: Consider the following code fragment: string str1; str2; getline(cin, str1); Using pencil/pen and paper, answer the following questions and show your results to one of

 Consider the following code fragment: string str1; str2; getline(cin, str1); Using

Consider the following code fragment: string str1; str2; getline(cin, str1); Using pencil/pen and paper, answer the following questions and show your results to one of the TAs: Write a single-statement for loop that will output each character of str1 on a separate line as follows(e.g.): H e l l o Write a for loop to construct a string, str2 that is exactly the same as str1 but without the lastcharacter. Use indexing and the length method only. Do not use any other functions: Now write a single C++ statement that will accomplish the same thing as the previous problem using onlythe length and substr methods (i.e., do not use indexing or loops): Assuming that there is an equal sign (' = ') somewhere in str1, write the statement or statements that willsave all the characters to the left of the equal sign in str2: If the input string didn't contain an equal sign, what value would the find method return? Write the statement or statements that will find the first occurrence of a comma (', ') in str1 and printeither "the comma is at index: n" (where n is the index of the comma), or "no comma found" if no comma isfound in the string

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!