Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C ++ text justification Your program will read words from an input file and greedily pack the words one at a time onto each line,

image text in transcribed

C ++ text justification

Your program will read words from an input file and greedily pack the words one at a time onto each line, making sure not to exceed the specified width. Your program will support three different methods for dealing with any extra, unused space on each line. The first, flush left, simply positions each word as far to the left as possible, leaving a gap of spaces (if any) on the right. The second, flush right, does the opposite, pushing all the words to the right, and puts the extra spaces on the left. In the final mode, full justify, the extra spaces are distributed evenly between the words. If the number of extra spaces on the line do not divide evenly into those "between slots, the slots on the left will be assigned more spaces that the slots on the right. Let's look at a simple example. Here is a sample input file, named example.txt: Here is an example of text justification. And here's the output produced for that input file for the three different justification modes, for the specified text width of 16: flush left flush right full justify I is | Here is an | example of text | justification. 1 Here is an | example of text | justification. Here an | example of text | | justification First note that the output includes a simple ascii art line box drawn around the text, but those characters do not count towards the specified line width of the text. In other words, each line of final output is actually 4 characters longer, in this example, 20 total characters. Notice that the same words appear on each line in all three cases. The only difference is where the "extra" spaces appear. The top line has 6 extra spaces (16 - # of characters in Here is an = 6). In full justify mode, these spaces are evenly divided into the 2 slots between the 3 words. The second line has 1 extra space (16 - # of characters in example of text = 1). This extra space is assigned to the leftmost of the two slots on the second line. Also note a typical convention for full justify formatting: The last line of a block of text formatted with full justify is not forced to stretch all the way to the right edge. No extra space is inserted between words on the last line - it should be flush left justified only. File I/O You will read the words to format from an input text file. You should not make any assumptions about the formatting of this file, except that the words will be separated by at least one whitespace character. Remember that whitespace characters include spaces, tabs, and newlines. Any punctuation in the file (including periods, commas, apostrophes, etc.) should be treated as part of the word if it is not separated from the word by spaces. The basic iostream string input operator, >>, will work perfectly for this assignment. The output of your program will be written to a file, and should follow the specifications in this handout and match our examples. Reading and writing files in C++ is very similar to std::cin and std::cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago