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, 21.06.2019 22:30
The blank is type of decision-maker who over analyzes information
Answers: 3
question
Computers and Technology, 22.06.2019 10:00
Which is a false statement considering copyright law? a. when people upload something to the internet they automatically receive a copyright for the work b. the work does not have to contain a copyright notice to be considered having a copyright c. copyright is legal term describing rights given to the creators for literary and artistic works d. personal pictures are always covered by copyrights
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
Need asap assignment directions: think of an organization (business, religious institution, volunteer organization, sports team) with which you have been involved. imagine outfitting it with an it infrastructure. prepare a plan for what you would do to support outfitting it. draw a map of a network connecting all the individuals, give them pcs and printers, and lay out the design as best you can. the purpose is to begin working with these concepts, not to build a perfect network.
Answers: 2
question
Computers and Technology, 23.06.2019 07:00
To produce a starlight effect in her photograph, lina should choose the filter for her camera.
Answers: 1
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
Mathematics, 04.02.2020 06:11
question
Mathematics, 04.02.2020 06:11
Questions on the website: 13722361