EDN Admin
Well-known member
Hi all,
Im currently taking a college level computer programming course using introductory C++. Im new to this language and only have little experience with programming in Basic. I need help writing a program that uses loops, and any help is more than
welcome.
The assignment is:
<span style="border-collapse:collapse; font-family:arial,sans-serif; font-size:13px
<div dir="ltr <span style="font-family:arial Write a loop that reads 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", and "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.
<div dir="ltr
<div dir="ltr <span style="font-family:arial Hint : Try approaching this a piece at a time.
<div dir="ltr <span style="font-family:arial So the first version of your program may just enter words, concatenate them into a sentence, and display it (use a sentinal):
<div dir="ltr <span style="font-family:arial // create string variables for the word & sentence
<div dir="ltr <span style="font-family:arial // initialize sentence to empty
<div dir="ltr <span style="font-family:arial // get the first word rom the user
<div dir="ltr <span style="font-family:arial // while word is not equal to "***"
<div dir="ltr <span style="font-family:arial // concatenate word to sentence
<div dir="ltr <span style="font-family:arial // get the next word from the user
<div dir="ltr <span style="font-family:arial // display sentence
<div dir="ltr <span style="font-family:arial Get that working. The easiest next step is probably putting the logic in to not concatenate the word if already in the sentence (see http://users.rowan.edu/~leer/csp11sp/Examples/Text%20Versions/Find%20Demo.txt" target="_blank" style="color:#2a5db0 http://users.rowan.edu/~leer/csp11sp/Examples/Text%20Versions/Find%20Demo.txt ). Get
that working. Then the third version might be removing the sentinal and exiting the loop after 20 words are entered. Get that working. Then figure out how to exit the loop after the sentence length is greater than 100 characters. Get that working. Finally
figure out how to exit the loop when a word with a period at the end is entered ( http://word.at/" target="_blank" style="color:#2a5db0 word.at (word.length()-1)==. is true if the string word has a period at the end).
View the full article
Im currently taking a college level computer programming course using introductory C++. Im new to this language and only have little experience with programming in Basic. I need help writing a program that uses loops, and any help is more than
welcome.
The assignment is:
<span style="border-collapse:collapse; font-family:arial,sans-serif; font-size:13px
<div dir="ltr <span style="font-family:arial Write a loop that reads 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", and "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.
<div dir="ltr
<div dir="ltr <span style="font-family:arial Hint : Try approaching this a piece at a time.
<div dir="ltr <span style="font-family:arial So the first version of your program may just enter words, concatenate them into a sentence, and display it (use a sentinal):
<div dir="ltr <span style="font-family:arial // create string variables for the word & sentence
<div dir="ltr <span style="font-family:arial // initialize sentence to empty
<div dir="ltr <span style="font-family:arial // get the first word rom the user
<div dir="ltr <span style="font-family:arial // while word is not equal to "***"
<div dir="ltr <span style="font-family:arial // concatenate word to sentence
<div dir="ltr <span style="font-family:arial // get the next word from the user
<div dir="ltr <span style="font-family:arial // display sentence
<div dir="ltr <span style="font-family:arial Get that working. The easiest next step is probably putting the logic in to not concatenate the word if already in the sentence (see http://users.rowan.edu/~leer/csp11sp/Examples/Text%20Versions/Find%20Demo.txt" target="_blank" style="color:#2a5db0 http://users.rowan.edu/~leer/csp11sp/Examples/Text%20Versions/Find%20Demo.txt ). Get
that working. Then the third version might be removing the sentinal and exiting the loop after 20 words are entered. Get that working. Then figure out how to exit the loop after the sentence length is greater than 100 characters. Get that working. Finally
figure out how to exit the loop when a word with a period at the end is entered ( http://word.at/" target="_blank" style="color:#2a5db0 word.at (word.length()-1)==. is true if the string word has a period at the end).
View the full article