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

NEED HELP!!! This is a right/left justification question on vector string for c+

ID: 3766527 • Letter: N

Question

NEED HELP!!!

This is a right/left justification question on vector string for c++

Problem statement:

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.

This is given:

This is also given:

What I have to do is write the function for the text justification taking into account the constraints at the beginning:

Please Help I have no idea how to do this

Explanation / Answer

Hi,

unsigned int justify(unsigned int width, string in, vector<string> &out)

{
int size = in.size();
vector<char> mod(in.begin(), in.end() + 2;
for (int j = 0; j<width; j += (width))
{
if (isspace(mod[j]))
{

mod.erase(j);
j -= (width);
}
if (isalpha(mod[j + width - 1]) && isspace(mod[j + width]));
if (isalpha(mod[j + width - 1]) && isalpha(mod[j + width]))
{
int pos = (mod.begin() + j - 2);
char hyphen = '-';
mod.insert(pos, hyphen);
}
if (isalpha(mod[j + width - 1]) && ispunct(mod[j + width]))

{
j += 1;
}
}
int row = (size / width) + 1;
int cols = width;
out[row][cols];
for (int i = 0; i<row; i++)
{
for (int k = 0; k<cols; k++)
{
int n = 0;
k = mod[n];
n++;
}
}
return 0;
} // end function justify

Hope that helps...HAPPY ANSWERING!!!!!!!!