Question: You have to write a function that, given a word and a set of characters, filters the all occurrences of those characters from the word.

You have to write a function that, given a word and a set of characters, filters the all occurrences of those characters from the word. For e.g.

remove_chars("abcdeeeeefmnop", "ebo")

returns: acdfmnp

i.e all occurrences of e, b and o have been removed from abcdeeeeefmnop

You should acquire the word and set of characters both from the user and then pass them to the function.

Note: std::cin terminates when it encounters a space, you should take the word and character set as separate inputs:

std::cin >> word >> charset;

Where word and charset are arbitrarily named variables to store the word and character set.

Hint: You can use substr(i, l) function where i is the index into the string and l is the number of characters to extract. It would be easier if you stored the output in a separate variable.

Write this function recursively. Do not use any loops.

Hint: You will need to create a helper function (also recursive) that checks if any given letter in the word is present in the charset. This function can be prototyped as follows:

bool contains(string letter, string charset)

If you do the recursion properly, you will realize your code is more concise and readable than the one you wrote in the previous lab.

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 Programming Questions!