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

1. accept input of three words into a C-string 2. parse the input into three sep

ID: 3622536 • Letter: 1

Question

1. accept input of three words into a C-string
2. parse the input into three separate variables
3. change each c-string into a string
4. concatenate all strings together into a single string (example:
string4 = s1 + s2 + s3 [i love you = i + love + you])
5. output that string

Not sure how to do this conversion process, though supposedly it's simple.

Sample coding with algorithm:

#include
#include
using namespace std;

int main()
{
//create c-string

//accept three words of input
cout << "Enter three words of input. "
cin >>

//pass each word into a separate variable
//change each to a c-string
//concatenate them into a single string
//output to main

system("pause");
return EXIT_SUCCESS;
}

Explanation / Answer

please rate - thanks

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
//create c-string
char cstring[80],c1[80],c2[80],c3[80];
string s1,s2,s3,s4;
int i=0,j=0;
//accept three words of input
cout << "Enter three words of input. ";
cin.getline(cstring,80);
//pass each word into a separate variable
while(cstring[j]!=' ')
    c1[i++]=cstring[j++];
c1[i]='';
i=0;
j++;
while(cstring[j]!=' ')
    c2[i++]=cstring[j++];
c2[i]='';
i=0;
j++;
while(cstring[j]!='')
    c3[i++]=cstring[j++];
c3[i]='';
cout<<"The 3 words: "<<c1<<", "<<c2<<", "<<c3<<endl;
s1=c1;
s2=c2;
s3=c3;
//change each to a c-string
//concatenate them into a single string
//output to main
s4=s1+' '+s2+' '+s3+'';
cout<<"Or, as a string: "<<s4<<endl;
system("pause");
return EXIT_SUCCESS;
}