Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write a program that reads a string containing exactly four words (separated

ID: 3639316 • Letter: 1

Question

1) Write a program that reads a string containing exactly four words
(separated by * symbols) into a single string object. Next, extract
each word from the original string and store each word in a string
object. Then concatenate the words in reverse order to form another
string. Display both the original and final strings. (Hint: To extract
the words, you should use the find member function to find
each symbol *, assign the characters up to the * to one of the four
string objects, and then remove those characters from the original
string.)


Explanation / Answer

please rate - thanks

#include<iostream>
using namespace std;
int main()
{string input,s1,s2,s3,s4,output="";
int a1,a2,a3,n=0;
int i;
cout<<"enter string: ";
    cin>>input;
a1=input.find("*",n);
n=a1+1;
a2=input.find("*",n);
n=a2+1;
a3=input.find("*",n);
n=a3+1;
s1=input.substr(0,a1);
s2=input.substr(a1+1,a2-a1-1);
s3=input.substr(a2+1,a3-a2-1);
s4=input.substr(a3+1,input.length()-a3-1);
output=s4+s3+s2+s1;   
cout<<"original string: "<<input<<endl;
cout<<"final string: "<<output<<endl;
system("pause");
return 0;
}