Question: This is in C++ Given the ABC (abstract base class) Filter, create and test a derived class that transforms a file of text to all

This is in C++

Given the ABC (abstract base class) Filter, create and test a derived class that transforms a file of text to all uppercase characters and a derived class that double spaces a file, i.e., inserts a blank line between any two lines of the file.

class Filter

{

public:

void doFilter(fstream & in, fstream & out);

protected:

virtual char transform(char ch) = 0;

};

void Filter::doFilter(fstream & in, fstream & out)

{

char ch = in.get();

while (ch != EOF) {

out.put(transform(ch));

ch = in.get();

} // dowhile

} // end doFilter()

//Here is a sample output

/* Output:

Program creates an uppercase version of a test file

Enter name of input file (story.txt): story.txt

Original file contents:

How many roads must a man walk down

before you call him a man

How many seas must the white dove sail

before she sleeps in the sand

Yes an' how many times must the cannon balls fly

before they're forever banned

Enter name of output file (outcap.txt): outcap.txt

Filtered file is:

HOW MANY ROADS MUST A MAN WALK DOWN

BEFORE YOU CALL HIM A MAN

HOW MANY SEAS MUST THE WHITE DOVE SAIL

BEFORE SHE SLEEPS IN THE SAND

YES AN' HOW MANY TIMES MUST THE CANNON BALLS FLY

BEFORE THEY'RE FOREVER BANNED

Now, program creates a double spaced version of a text file

Enter name of input file (story.txt): story.txt

Original file contents:

How many roads must a man walk down

before you call him a man

How many seas must the white dove sail

before she sleeps in the sand

Yes an' how many times must the cannon balls fly

before they're forever banned

Enter name of output file (outdbl.txt): outdbl.txt

Filtered file contents:

How many roads must a man walk down

before you call him a man

How many seas must the white dove sail

before she sleeps in the sand

Yes an' how many times must the cannon balls fly

before they're forever banned

-- Done -- */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!