Please follow the following method and function and main to solve this problem a
ID: 3938200 • Letter: P
Question
Please follow the following method and function and main to solve this problem and output has to be same please.
Question - Write a recursive function to check if a given string is a palindrome. First complete given function prototype: bool isPal(const string &str;, int start, int end); Then use the provided driver program to test your code. 2- Write a recursive function that returns the frequency of occurrence ofa particular digit 'd' in an integer n, First complete given function prototype: int frequencyCount(int number, int digits); Then use the provided driver program to test your code. Submit a single cpp file leExplanation / Answer
#include <iostream>
#include <string.h>
using namespace std;
bool isPal(const string &str, int start, int end){
if(start >= end)
return true;
if(str[start] == str[end]){
return isPal(str, start + 1, end - 1);
}
return false;
}
int frequencyCount(int number, int digit)
{
static int count=0;
int num;
if((number/10)==0)
return count;
num=number%10;
if(num==digit)
count++;
frequencyCount(number/10,digit);
}
int main()
{
string str[5]={"abcba","abba","a","abc","abcdabcd"};
for(int i=0;i<5;i++)
{
if(isPal(str[i], 0, str[i].length()-1))
cout<<str[i]<<" is a Palindrome"<<endl;
else
cout<<str[i]<<"is not a Palindrome"<<endl;
}
cout<<"Frequency of 4 in 1342457 is:"<<frequencyCount(1342457,4)<<endl;
cout<<"Frequency of 6 in 1342457 is:"<<frequencyCount(1342457,6)<<endl;
return 0;
}
the palindrome code is working properly, but the time was insufficient for the other code.