Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello Expert programmer. Please help me with this program . please make sure follow the instruction properly and please remember adjustment implementation for extra 2

Hello Expert programmer. Please help me with this program .

please make sure follow the instruction properly and please remember adjustment implementation for extra 2 points. i will be appreciated it. need to be done in 3 days. advance thanks .

A Simple Paragraph Justifier

The mission of this assignment is to realize a simple paragraph justifier. As shown in my coding demonstration, your program will keep reading lines of text image using getline(). After reading a paragraph, it adjusts all the lines into an instructed width, so that it can show the words evenly spread out and fit in a straight edge at both margins (similar to "align full" option in a Microsoft word document).

This can be relatively easily done as we are dealing with a mono-space font set (not a proportional font set) shown on a command-line-type console. As an example, consider a line containing 5 words and 30 characters altogether. If this line needs to be justified into a 40-character width, the remaining10 spaces needs to be spread out between the words. Assume that the first word of the next line has more than 9 characters, that is, the word in the next line cannot be placed in the tail of this line so as to consume the extra spaces.

In this case, 2 spaces are placed between the first 4 words, followed by 4 spaces prior to the last word (tail adjustment), or 3 spaces are placed between the first 4 words, followed by a space prior to the last word (even adjustment).

The requirements of this assignment are:

program keeps reading lines of text until reading an empty line

program then reads a width for the read paragraph

program then justifies the paragraph based on tail adjustment

program then shows the result in a bounding box

program allows to adjust the paragraph by going back to 2

program ends when it reads 0 as a new width

Restriction: Do not use stringstream. Instead parse each line read into words. A word should be defined as a sequence of non-white space characters delimited by white-space before and after it. And, remember that getline does not read the new-line, So here is a hint: Use the length of the line read to determine when your parse has reached the end of the line. Also the functionality provided will be helpful.

Hint: For the solution of this problem you will have to read all of your words into a vector of strings.

Extra points (2 points) will be considered for even adjustment implementation.

Here is a hint to realize this mission - lines of words, say vector words, is a straightforward conversion as implemented in the previous assignment and posted lecture example. Now, user types some width for justification. Let this width be W. The mission is to fill i-words in one line of this W. Note i > 0, i.e., every line must have at least one word. The logic will be:

let { w1, w2, ..., wi } be a collection of words. Then, w1.length() + w2.length() + ... + wi.length() is the total length of this collection

since we need at least one space between these i words, we need i - 1 spaces at least, and therefore, we need Wmin = w1.length() + w2.length() + ... + wi.length() + (i - 1) characters, which must be less than or equal to W

your first loop must identify this i and Wmin by going through vector words you created

in the second loop, you simply create a line by adding w1 through wi-1 by placing a space between the two consecutive words

before placing the last word wi, you need to place W - Wmin spaces because this number is the excess spaces to fill in for justification (tail adjustment)!

There is no miracle or hidden trick to deal with these operations.The left-hand side of the next example shows tail adjustment while the right-hand side shows even adjustment:

Enter text, empty return will quit the input > Every photo, every edit, every album now lives > in your iCloud Photo Library, easily viewable > and consistent on all your devices. > Automatically. The all-new Photos app makes > it simpler than ever to find and rediscover > your favorite photos. And you can make every > shot look even better immediately after you've > taken it with powerful new editing tools. > > Enter the width of text: 25 |-------------------------| |very photo, every edit,| |every album now lives in| |your iCloud Photo| |Library, easily viewable| |and consistent on all| |your devices.| |Automatically. The| |all-new Photos app makes| |it simpler than ever to| |find and rediscover your| |favorite photos. And you| |can make every shot look| |even better immediately| |after you've taken it| |with powerful new editing| |tools. | |-------------------------| Enter the width of text: 30 |------------------------------| |very photo, every edit, every| |album now lives in your iCloud| |Photo Library, easily viewable| |and consistent on all your| |devices. Automatically. The| |all-new Photos app makes it| |simpler than ever to find and| |rediscover your favorite| |photos. And you can make every| |shot look even better| |immediately after you've taken| |it with powerful new editing| |tools. | |------------------------------| Enter the width of text: 0 
 Enter text, empty return will quit the input > Every photo, every edit, every album now lives > in your iCloud Photo Library, easily viewable > and consistent on all your devices. > Automatically. The all-new Photos app makes > it simpler than ever to find and rediscover > your favorite photos. And you can make every > shot look even better immediately after you've > taken it with powerful new editing tools. > > Enter the width of text: 25 |-------------------------| |Every photo, every edit,| |every album now lives in| |your iCloud Photo| |Library, easily viewable| |and consistent on all| |your devices.| |Automatically. The| |all-new Photos app makes| |it simpler than ever to| |find and rediscover your| |favorite photos. And you| |can make every shot look| |even better immediately| |after you've taken it| |with powerful new editing| |tools. | |-------------------------| Enter the width of text: 30 |------------------------------| |Every photo, every edit, every| |album now lives in your iCloud| |Photo Library, easily viewable| |and consistent on all your| |devices. Automatically. The| |all-new Photos app makes it| |simpler than ever to find and| |rediscover your favorite| |photos. And you can make every| |shot look even better| |immediately after you've taken| |it with powerful new editing| |tools. | |------------------------------| Enter the width of text: 0 

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

Step: 3

blur-text-image

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions