Write a loop that reads in a collection of words and builds a sentence out of al
ID: 3657936 • Letter: W
Question
Write a loop that reads in a collection of words and builds a sentence out of all the words by appending each new word to the string being formed. For example, if the three words This, is, one are entered, your sentence would be "this", then "This is", and finally "This is one". Exit your loop when a word that ends with a period is entered or the sentence being formed is longer than 20 words or contains more than 100 letters. Do not append a word if it was previously entered.((PLEASE DO IT READABLE,I WILL APRECCIATE THAT,THANKS!!))Explanation / Answer
//This works by reading in each string (str) and appending it to a master string (str1). // The loop will run until 20 words have been entered, the sentence would exceed //100 characters, or a period is found. #include #include using namespace std; int main() { int i=1; string str; string str1; string str2 = "."; while ((str.find(str2) == string::npos)&&(str1.size()str; str1.append(str); str1.append(1,' '); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.