Computer Programming II

Lab Project #2

 

DESIGN:

You are to perform a top-down modular design for this and all following programming projects.  In this case you will hand in the design as comments at the top of your source code listing.

PROBLEM: For this project, you will develop a C++ program that will read in any text file of plain text and reformat the text. Your program will break up the lines word by word and output a fully justified version of the text, which  will then resemble a newspaper column of print.

Input data: The input to the program will come from a pure ASCII text data file.  Use notepad or the compiler’s editor to create this file.  You must use the data provided at the end of this description. Your program should work with any dataset, but make sure it does the job like the example below.

Analysis: For the purposes of this project, read in the text line by line into a string, break up the strings into words and then build a new string with an appropriate number of spaces between the words (to space them out).

Output: Your program will echo the input data, then dump out the new version of the text as shown below. Keep in mind it must work for any body of text, not just the one provided. Each output line should be 30 spaces wide, no more, and these lines don’t need to be “centered”.

Suggestions:  Take this project in stages. First get it to read in and echo the input. Next get it to chop the sentences off at 30 spaces. Next, get it to chop it off at the point of the last complete word. Finally, to get full credit, get it to sprinkle back in spaces to justify the text.

Example:

Input data: (Use this data!)
 
...and the country awaited the inevitable German assault against the West. Initially nothing happened. Indeed for over six months scarcely any fighting took place between the combatant powers and Britain settled into the welcome leisure of the 'Phony War'. Then in May 1940 Germany's surprise Blitzkrieg offensive against France and the Low Countries shattered this unnatural calm for good. British forces were rudely ejected from the European mainland and England suddenly found itself alone and facing the possibility of imminent invasion. However, a heroic air defense that summer forestalled Hitler's 'Operation Sealion' attack. The summer of 1941 finds Britain in a difficult situation. British forces are in peril in North Africa...
 
Output data: (must be fully justified 30 characters per line.)
 
Text Box: ...and the country awaited the inevitable German assault against the West. Initially nothing happened. Indeed for over six months scarcely any fighting took place between the combatant powers and Britain settled into the welcome leisure of the 'Phony War'. Then in May 1940 Germany's surprise Blitzkrieg offensive against France and the Low Countries shattered this unnatural calm for good. British forces were rudely ejected from the European mainland and England suddenly found itself alone and facing the possibility of imminent invasion. However, a heroic air defense that summer forestalled Hitler's 'Operation Sealion' attack. The summer of 1941 finds Britain in a difficult situation. British forces are in peril in North Africa...