Topical Information

This lab will help you show your mastery of strings (and branching, looping, etc.).

Program Information

Write a program that reads in a sentence from the user. But wait! That's not all it must do! Your program should output the sentence with spacing corrected and with letters corrected for capitalization.

In terms of spacing correctness, the output sentence should have all sequences of two or more blanks compressed to a single space — unless there were blanks at the beginning of the sentence. Blanks at the beginning of a sentence should be obliterated utterly! (Blank here can mean any type of spacing — space, tab, new-line, ...)

The sentence should start with an uppercase letter but should contain no other uppercase letters. (Do not worry about proper names; if their first letters are changed to lowercase, that's acceptable.)

For simplicity, you may assume that the user's sentence ends in a period and contains no other periods (i.e. no abbreviations or such).

$ sentence.out

                   Welcome to the Style Stabilizing Program!

Please enter your sentence (end with a period):
the         Answer to life, the Universe, and   everything
IS 42.

Corrected, your sentence is:

The answer to life, the universe, and everything is 42.

Thanks for stabilizing your style with us today!

Try to have a punctual day here-after!


Perhaps, you might find this example of help..?

Thought Provoking Questions

  1. How can you read in an entire line of text at once? Does this act — even sometimes — need any special precaution?

  2. How do you let the line of text end with something other than a \n? (Hint: Maybe it could involve a default argument or an overloaded version of the function you found above...)

  3. Once you've read in an entire 'line' of text, how can you clean up the spacing (in case the user has a sticky space-bar or tab key, for instance)? (Hint: You aren't actually erase'ing the extra spaces per-se, but rather replace'ing lots (i.e. all pairs) of spaces with a little space (i.e. a single space). Seriously! See the referenced example!)

This assignment is (Level 2).