Programming Workshop 2 (CSCI 1061U)
Winter 2021
Faculty of Science
Ontario Tech University
The goal of this lab is to learn the use of abstract classes in C++. Consider the following abstract class Filter
.
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:
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.
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; i<num_filters; ++i) {
cout << "Filter name: " << filters[i]->get_name() << endl;
cout << "Output: " << filters[i]->apply(input) << endl;
}
for (int i=0; i<num_filters; ++i) delete filters[i];
You are asked to provide code for the 7 classes that implement these filters. The functionality of each filter can be inferred 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 nobo 8
Filter name: ReverseString
Output: 8 on bal
Filter name: ToSmall
Output: lab no 8
Filter name: Randomize
Output: alb 8o n
Please implement all of your code in a single file. Let us name this file filters.cpp
. Submit filters.cpp
file via Canvas.