Question: Recursion (C++ programming) Complete the following two programs 1. Implement a function isPalindrome which takes a string as an argument and returns true if the
Recursion (C++ programming)
Complete the following two programs
1. Implement a function isPalindrome which takes a string as an argument and returns true if the word reads the same forward and backwards and false otherwise. For example, racecar and noon are palindromes, but banana is not. Your function should be recursive (i.e. it should call itself and have a base case). You will find the substr function of the string class useful in your solution.
2. Implement a function printAllSubsets which takes a string and prints all subsets of the string. For example, if the string was dog, the subsets would be:
dog do dg og d o g
Note that the order in which the subsets are printed does not matter, nor does the ordering of the letters within each subset (i.e. including og or go is fine, just not both). In order to implement this, printAllSubsets will be a wrapper function for your actual recursion. That is the prototype for printAllSubsets will be:
void printAllSubsets(string word);
For your recursive function youll need two strings, an input string holding the letters youve not yet considered adding to your output, and an output string holding the letters you have added to your outputs. Thus, the prototype for your recursive function should look like this:
void recPrintAllSubsets(string input, string output);
Your printAllSubsets function should just call recPrintAllSubsets with the initial word as the input and the empty string as the output.
Once youve completed these two functions, write a main to test their functionality
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
