Question

Write a function that, given a word and a set of characters, filters all occurrences of...

Write a function that, given a word and a set of characters, filters 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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer! un cpp code: #include <iostream> #include <string.h> using namespace std; 1 Function to Filter the kord */ String remIxread Characters in set of character like character by Character. * For (int j = 0; chars [J]!= \0; I++ ) l*if character ireturn filtered -word; Il return filtered word int main( It variable declarations */ String filtered – word; Chars chars (100images of code: #include<iostream> #include<string.h> using namespace star string remove_chats (char word). char chassis stri

Add a comment
Know the answer?
Add Answer to:
Write a function that, given a word and a set of characters, filters all occurrences of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified...

    Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified character in a string) Write a recursive function that finds the number of occurrences of a specified letter in a string using the following function header. int count(const string& s, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the...

  • Write a C program that takes two sets of characters entered by the user and merge...

    Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...

  • You are to write two functions, printString() and testString(), which are called from the main function....

    You are to write two functions, printString() and testString(), which are called from the main function. printString (string) prints characters to std::cout with a space after every character and a newline at the end. testString (string) returns true if the string contains two consecutive characters that are the same, false otherwise. See the main() to see how the two functions are called. Some sample runs are given below: string: “hello” printString prints: h e l l o testString returns: true...

  • Let us define a word to be a maximal nonempty sequence of alphanumeric characters and underscores...

    Let us define a word to be a maximal nonempty sequence of alphanumeric characters and underscores (i.e. matching BRE [[:alnum:]_]\{1,\}). Consider the word to name a variable (function, type, etc.) in a programming language. We say that the word is in camel case if the subwords are introduced with an upper case letter (such as MyVerySpecialVariable). The word can start with an upper case character (UpperCamelCase) or a lower case character (lowerCamelCase). For simplicity, we assume underscores are not present...

  • In Python 1 2 Write a function that removes all occurrences of a given letter from...

    In Python 1 2 Write a function that removes all occurrences of a given letter from a string: test (remove_letter ("a", "apple") "pple") test (remove_letter ("a", "banana") "bnn") test (remove_letter (2", "banana") "banana") test (remove_letter ("i", "Mississippi") "Msssspp") test (remove letter (",) "") test (remove_letter("b","0"> MO) 4 5 ### Run the following lines. # If you get "Correct" you # did it right. if remove_letter("a", "banana") == "nn": print("Correct!") else: print("Incorrect :(")

  • Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is...

    Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • Write a client function parenthesesMatch that given a string containing only the characters for parentheses, braces...

    Write a client function parenthesesMatch that given a string containing only the characters for parentheses, braces or curly braces, i.e., the characters in ’([{}])’, returns True if the parentheses, brackets and braces match and False otherwise. Your solution must use a Stack. For, example: >>> parenthesesMatch('(){}[]') True >>> parenthesesMatch('{[()]}') True >>> parenthesesMatch('((())){[()]}') True >>> parenthesesMatch('(}') False >>> parenthesesMatch('({])') False >>> parenthesesMatch('((())') False >>> parenthesesMatch('(()))') False >>> Hint: It is not sufficient to just count the number of opening and closing...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

  • Recursion and Trees Application – Building a Word Index Make sure you have read and understood...

    Recursion and Trees Application – Building a Word Index Make sure you have read and understood ·         lesson modules week 10 and 11 ·         chapters 9 and 10 of our text ·         module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT