Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code is in C++. Write a function named flipLines that accepts as its parameter a string representing a file name, opens that file and reads

Code is in C++. Write a function named flipLines that accepts as its parameter a string representing a file name, opens that file and reads its contents as a sequence of lines, and writes to the console the same file's contents with successive pairs of lines reversed in order, with alternating capitalization. For example, if the input file named carroll.txt contains the following text:

TWAS brillig and the Slithy Toves did GYRE and gimble in the Wabe. All mimsey were the Borogroves, and the mome RATHS outgrabe. "Beware the Jabberwock, my Son, the JAWS that bite, the claws that Catch, Beware the JubJub bird and SHUN The Frumious Bandersnatch." 

Then the call of flipLines("carroll.txt"); should print the first pair of lines in reverse order, then the second pair in reverse order, then the third pair in reverse order, and so on. It should produce the following console output:

DID GYRE AND GIMBLE IN THE WABE. twas brillig and the slithy toves AND THE MOME RATHS OUTGRABE. all mimsey were the borogroves, "BEWARE THE JABBERWOCK, MY SON, BEWARE THE JUBJUB BIRD AND SHUN the jaws that bite, the claws that catch, THE FRUMIOUS BANDERSNATCH." 

Notice the alternation between all-uppercase and all-lowercase. Also note that a line can be blank, as in the third pair. An input file can have an odd number of lines, as in the one above, in which case the last line is printed in its original position. You should not make any assumptions about how many lines are in the file.

If the input file does not exist or is not readable, your function should instead print a message in exactly the following format:

Unable to open input file "carroll.txt"! 

Constraints: Your solution should read the file only once, not make multiple passes over the file data.

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

Students also viewed these Databases questions

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago

Question

=+What forms of industrial action are common?

Answered: 1 week ago