Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions