| Text with Placeholders | Values for Placeholders | Merged text |
|---|---|---|
|
Dear <name>: The Zippy Company would like to thank you for the resume you sent us on <date>, however, ... |
<name> = John Smith <date> = January 10th |
Dear John Smith: The Zippy Company would like to thank you for the resume you sent us on January 10th, however, ... |
or for other things, like playing Mad Libs:
| Text with Placeholders | Values for Placeholders | Merged text |
|---|---|---|
| The <adjective-1> <noun-1> ran over the <noun-2> very <adverb-1> ... |
<noun-1> = rooster <noun-2> = octopus <adjective-1> = urban <adverb-1> = quaintly |
The urban rooster ran over the octopus very quaintly ... |
The program should work as follows:
% mergetext
Number of placeholders (no more than 10)? 2
Placeholder #1 (no spaces)? <first-name>
Placeholder #1 value (no spaces)? Robert
Placeholder #2 (no spaces)? <last-name>
Placeholder #2 value (no spaces)? Billings
Now enter the paragraph that uses the above placeholders. Enter the
end-of-file character (i.e., Ctrl-D [UNIX] or Ctrl-Z [MS]) when you are
done:
We would like to welcome <first-name> <last-name> to the wonderful
family of door-to-door representatives for the Raingo Barbecue
Item-of-the-Month Club. <first-name> -- you should be receiving your
sales kit in just a matter of days and will then begin your long
door-to-door career! But first, begin with Chapter 1 in the attached
pamphlet, "Learning to Smile Even When the Customer Slams the Door in
Your Face"!
<end-of-file>
The formatted paragraph is:
We would like to welcome Robert Billings to the wonderful family of
door-to-door representatives for the Raingo Barbecue Item-of-the-Month
Club. Robert -- you should be receiving your sales kit in just a matter of
days and will then begin your long door-to-door career! But first, begin
with Chapter 1 in the attached pamphlet, "Learning to Smile Even When the
Customer Slams the Door in Your Face"!
Note that formatting the paragraph not only involves replacing the placeholders, but also reformatting so that lines wrap properly.
Consider only words ending in the period (.), question
mark (?) or exclamation point (!) and
followed by a word beginning with a capital letter (e.g., "The") as
being at the end of a sentence.
string.h and must use at least 3 of the
string functions you wrote for the lab exercise (e.g.,
StrLength(), StrCompare(),
StrCopy() or StrConcat()) in your solution in
a reasonable manner.
Hints: Note that the whitespace in the original version of the paragraph is ignored. Thus, you can format lines only being concerned about the current and previous word that you are processing. Be sure to replace placeholders before you determine how a word affects line wrapping and the spacing between words.
Prepare this program, adding all appropriate comments and using
attractive and readable formatting conventions. Call the program
mergetext.cpp.