Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The goal of this lab is to learn the use of abstract classes in C++. Consider the following abstract class Filter. 1 2 3 4

The goal of this lab is to learn the use of abstract classes in C++. Consider the following abstract class Filter.

1 2 3 4 5 6 7 8 9 10 11 12 13 
class Filter { protected: string _name; public: Filter(const string& name) : _name(name) {} virtual ~Filter() {}; virtual string apply(const string& input) = 0; string get_name() { return _name; } };

This class specifies a generic string filter. Using this class, we have implemented 7 string filters:

  • Capitalize;
  • CapitalizeFirstLetter;
  • CapitalizeFirstLetterOfEveryWord;
  • Obenglobish;
  • ReverseString;
  • ToSmall; and
  • Randomize.

Each of these filter is implemented in a child class of the abstract Filter class. We can apply these filters to an arbitrary string as seen below.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 
const int num_filters = 7; Filter* filters[num_filters]; filters[0] = new Capitalize(); filters[1] = new CapitalizeFirstLetter(); filters[2] = new CapitalizeFirstLetterOfEveryWord(); fitlers[3] = new Obenglobish(); filters[4] = new ReverseString(); filters[5] = new ToSmall(); filters[6] = new Randomize(); string input; cout << "Enter srring: "; getline(cin, input); cout << "Input string: " << input << endl; for (int i=0; iget_name() << endl; cout << "Output: " << filters[i]->apply(input) << endl; } for (int i=0; i 

You are asked to provide code for the 7 classes that implement these filters. The functionality of each filter is clear from its name. Randomize filter randomly move the letter locations in the provided file. Consider the following output from the program.

Enter srring: lab no 8 Input string: lab no 8 Filter name: Capitalize Output: LAB NO 8 Filter name: CapitalizeFirstLetter Output: Lab no 8 Filter name: CapitalizeFirstLetterOfEveryWord Output: Lab No 8 Filter name: Obenglobish Output: lobab no 8 Filter name: ReverseString Output: 8 on bal Filter name: ToSmall Output: lab no 8 Filter name: Randomize Output: alb 8o n

Submit

Submit filters.cpp file via Blackboard.

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

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago