67 095
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #25069 in C++ for Sam

Question #25069
Write code to ask the user to enter a line of text. Then, ask the user to enter two numbers, the first representing the first character to extract from the string, and the second representing the last character to extract. Then, output all the characters between that first and last character.
Expert's answer

# include <iostream>
# include<string>
/*Write code to ask the user to enter a line of text. Then, ask the user to
enter two numbers, the first representing the first character to extract
from the string, and the second representing the last character to extract.
Then, output all the characters between that first and last character.*/
using namespace std;
string Extract (string text,const int &f,const int &l){
string newtext="";
for (int it=f;it<l;it++){
newtext.push_back(text[it]);
}

return newtext;
}


int main(){
cout<<"Enter text:";
string str;
int f,l;
getline(cin,str,'\n');
cout<<"Enter first int:";
cin>>f;
cout<<"Enter second int:";
cin>>l;
cout<<Extract(str,f,l);
system("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions