Given a string, an integer position, and an integer length, all on separate lines, output the substring from that position of that length. Ex: If the input is: Fuzzy bear 3 4 the output is: zy b Note: Using a pre-defined string function, the solution can be just one line of code. 1 #include 2 #include 3 using namespace std; 4 5 int main() { string workStr; 7 int idxBegin; 8 int choicelen; 9 string strSelection; 10 11 getline(cin, workStr); 12 cin >> idxBegin; 13 cin >> choiceLen; 14 15 * Your code goes here */ 16 17 cout << strSelection << endl; 18 return; 19} 1 2 3 4 Check Next level

Respuesta :

Program Explanation:

  • Including header file.
  • Defining the main method.
  • Declaring two-string variable "workStr, strSelection" and three integer variable "idxBegin,choiceLen, and i".
  • Using the "getline" method to input the string value and the normal input method to an input integer value.
  • Defining a while loop that checks integer variable "i" value less than "choiceLen"  variable value that uses the "strSelection" variable to hold value.
  • Outside the loop use the print method to print "strSelection" string variable value.

Program:

#include <iostream>//header file

#include <string>//header file

using namespace std;

int main() //defining main method

{

  string workStr, strSelection;//defining string variable

  int idxBegin,choiceLen,i=0;//defining integer variable

  getline(cin, workStr);//using getline method to input string value

  cin >> idxBegin>>  choiceLen;//input integer value

  strSelection = "";//assign empty space value in string variable

  while(i<choiceLen)//defining loop that checks integer value

  {

     strSelection +=  workStr[idxBegin+i];//holding value into string variable

     i++;//incrementing loop value

  }

  cout << strSelection << endl;//print string value

  return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/14391069

Ver imagen codiepienagoya
ACCESS MORE
EDU ACCESS