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

Part 2: Read a sentence, word by word, until the user types a period Write a pro

ID: 3870609 • Letter: P

Question

Part 2: Read a sentence, word by word, until the user types a period Write a program that reads words from the console until the user enters a period. Then output the sentence. For example Enter a word, period to end: The Enter a word, period to end: Enter a word, period to end: brown Enter a word, period to Enter a word, period to end: . quick end: fox Your sentence is he quick brown fox . Hint: string variables can be "added" with . Also, strings can be compared against other strings or against string constants. For example strings! "hello", s2 "world", s3; cout

Explanation / Answer

#include<iostream>
using namespace std;

int main() {
string s, sentence="";
cout<<"Enter a word, period to end: ";
cin >> s;
while(s !=".") {
sentence = sentence+s+" ";
cout<<"Enter a word, period to end: ";
cin >> s;
}
cout<<"The sentence is: "<<endl;
cout<<sentence<<endl;
return 0;
}

Output: