subject

Implement a program that fills text from a plain text file into neatly arranged paragraphs with a particular maximum allowed line length. For example, if the desired maximum line length is 40 characters and the input text is It always does seem to me that I am doing more work than
I should do. It is not that I object to the work, mind you;
I like work: it fascinates me.
I can sit and look at it for hours.
I love to keep it by me: the idea of getting
rid of it nearly breaks my heart. #P# You cannot give me too much work; to accumulate work has almost become a passion with me: my study is so full of it now, that there is hardly
an inch of room for any more.
then the output text will be
It always does seem to me that I am
doing more work than I should do. It is
not that I object to the work, mind you;
I like work: it fascinates me. I can
sit and look at it for hours. I love to
keep it by me: the idea of getting rid
of it nearly breaks my heart.
You cannot give me too much work; to
accumulate work has almost become a
passion with me: my study is so full of
it now, that there is hardly an inch of
room for any more.
from Jerome K. Jerome's Three Men in a Boat (To Say Nothing of the Dog).
You are to implement the following function, whose job it is to do the filling:
int fill(int lineLength, istream& inf, ostream& outf);
You may name the parameters something else, but there must be three parameters of the indicated types in the indicated order. (The File I/O tutorial explains istream and ostream.) The parameters are
an int with the desired maximum line length
an already-opened input source you will read from (probably a file the caller opened).
an already-opened output destination you will write to (probably either cout or an output file the caller created)
The function must return an int with one of the following values:
0 if is successful (i. e., neither of the following problems occurs)
1 if any input word (defined below) is longer than the maximum line length
2 if the desired maximum line length is less than 1
In the case of the error situation that would cause the function to return 2, it must return 2 without writing any output.
Your fill function may, of course, call other functions you write to help it do its job. You can test your fill function by calling it from a main routine of your choosing. Our grading tool will ignore your main routine by renaming it to something harmless. If you wish, your main routine could prompt the user for the file names and the line length. Alternatively, it could hardcode the names of the files to use and prompt for only a line length. Do whatever works best for you to help you test your function. Here is an example:
int main()
{
const int MAX_FILENAME_LENGTH = 100;
for (;;)
{
cout << "Enter input file name (or q to quit): ";
char filename[MAX_FILENAME_LENGTH];
cin. getline(filename, MAX_FILENAME_LENGTH);
if (strcmp(filename, "q") == 0)
break;
ifstream infile(filename);
if (!infile)
{
cerr << "Cannot open " << filename << "!" << endl;
continue;
}
cout << "Enter maximum line length: ";
int len;
cin >> len;
cin. ignore(10000, '\n');
int returnCode = fill(len, infile, cout);
cout << "Return code is " << returnCode << endl;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 17:00
The camera still is bad even with the new iphone xr and especially in low light it is even worst because you can see the pixels more if its in low light. if all you apple customers want apple to fix this then lets fill there feedback with complaints about the can apple do to fix this issue?
Answers: 1
question
Computers and Technology, 24.06.2019 02:30
Write the pseudo code for this problem based on what you learned from the video. the purpose is to design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. the conversion formula is as follows: miles = kilometers x 0.6214
Answers: 3
question
Computers and Technology, 24.06.2019 09:00
Technician a says that a new replacement part is always good. technician b says that sometimes recent repair work will be the cause of a complaint. who is correct? a. both technicians a and b b. technician a c. technician b d. neither technician a nor b
Answers: 3
question
Computers and Technology, 24.06.2019 17:30
What is the next step if your volume does not work on computer
Answers: 2
You know the right answer?
Implement a program that fills text from a plain text file into neatly arranged paragraphs with a pa...
Questions
question
Social Studies, 20.10.2019 01:10
question
Biology, 20.10.2019 01:10
Questions on the website: 13722361