Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE USE C++ LANGUAGE AND PLEASE TRY TO USE POINTERS, ONLY WRITE CODES IN THE

ID: 3766236 • Letter: P

Question

PLEASE USE C++ LANGUAGE AND PLEASE TRY TO USE POINTERS, ONLY WRITE CODES IN THE JUSTIFY.CPP NOTHING ELSE, PLEASE HELP URGENT MATTER

THE PROBLEM IS:

Implement the function justify in the file justify.cpp to perform left and right justification on a text input of type string. The justified text is a vector of strings.

The assumptions for the input text are as follows:

1. The input text consists only of alphabets (lower and upper case), blank spaces (‘ ‘), and two punctuation marks (periods (‘.’), and commas (‘,’)).

2. Every word in a sentence in the input text is separated by a single blank space.

3. The punctuation marks immediately follow the last character of the preceding word, and a single space is present between a punctuation mark and the following word.

4. There are no new line characters in the input string.

We will perform a very primitive form of justification in this assignment using the following rules:

1. Every line in the justified text must have at least width – 2 characters, with the exception of the last line, which may have fewer characters.

2. Every line in the justified text must have at most width characters, with the exception of lines that terminate with a punctuation mark (period or comma). In such cases, the line may have width+1 characters to accommodate the trailing punctuation mark.

3. Every line in the justified text must start with an alphabet (word). The first character in a line cannot be a punctuation mark or space.

4. If a word needs to be split across lines in order to follow the above rules, a hyphen (‘-‘) character must be inserted after the first part of the word. The hyphen character counts toward the total number of characters in a line.

Given an example unjustified input text as follows, the program should generate justified texts for different column widths as illustrated

Input text (unjustified)

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non culpa qui officia deserunt mollit anim id est laborum.

Output text (justified) with width = 20

Basically if the justify.cpp is right, im asked to enter the width ( lets say 20) and a random text, then i should be given the above. Each row has 20 characters( as width is chosen as 20).

Explanation / Answer

C/C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs (just like water and oil flowing through a pipe). In input operations, data bytes flow from an input source (such as keyboard, file, network or another program) into the program. In output operations, data bytes flow from the program to an output sink (such as console, file, network or another program). Streams acts as an intermediaries between the programs and the actual IO devices, in such the way that frees the programmers from handling the actual devices, so as to archive device independent IO operations.

C++ provides both the formatted and unformatted IO functions. In formatted or high-level IO, bytes are grouped and converted to types such as int, double, string or user-defined types. In unformatted or low-level IO, bytes are treated as raw bytes and unconverted. Formatted IO operations are supported via overloading the stream insertion (<<) and stream extraction (>>) operators, which presents a consistent public IO interface.

To perform input and output, a C++ program:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote