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.
1
Expert's answer
2013-02-26T10:56:33-0500
# 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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment