Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 14, Problem 5P

Explanation of Solution

Recursive function for checking palindrome:

The recursive function definition for checking the given string is a palindrome or not is shown below:

/* Function definition for checkPalindromeRecursion function */

bool checkPalindromeRecursion(string str)

{

      /* If length is "0" or "1", then return "true" */

      if(str.length() == 0 || str.length() == 1)

            return true;

        /* Check the first character*/

        if(isdigit(str.at(0)))

        {

     /* If the first character is equal to the last character, then */

              if(str.at(0) == str.at(str.length()-1))

     /* Recursively call the function "checkPalindromeRecursion" with remaining characters */

       return checkPalindromeRecursion(str.substr(1, str.length()-2));

        }

        //Otherwise

        else

        {

              //For checking the lower characters

     if(tolower(str.at(0)) == tolower(str.at(str.length()-1)))

     return checkPalindromeRecursion(str.substr(1, str.length()-2));

        }

        //Otherwise returns "false"

        return false;

}

Explanation:

The above function is used to check the given string is a palindrome or not using recursive function.

  • If the length of string is “0” or “1”, then returns “true”.
  • Check the first digit of given string.  If it is, then check if the first character is equal to the last character, then recursively call the function “checkPalindromeRecursion” for remaining characters in given string.
  • Otherwise, return “false” that is for not palindrome string.

Complete Executable code:

The complete code is implemented for checking the palindrome is shown below:

//Header file

#include <iostream>

#include <iomanip>

//For standard input and output

using namespace std;

/* Function definition for checkPalindromeRecursion function */

bool checkPalindromeRecursion(string str)

{

      /* If length is "0" or "1", then return "true" */

      if(str...

Blurred answer
Students have asked these similar questions
This is a question that I have and would like someone who has experiences with scene graphs and entity component systems to answer.For context, I am currently implementing a game engine and currently I am debating on our current design.Our current design is we have a singular game component class that every component inherits from. Where we have components like SpriteRendererComponent, Mehs Component, etc. They inherit from this GameComponent class. The point of this is being able to have O(1) access to the scene to being able to modify components to attach more components with the idea of accessing those components to specific scene objects in a scene.Now, my question is what kinds of caveauts can this cause in terms of cache coherence? I am well aware that yes its O(1) and that is great but cache coherence is going to be really bad, but would like to know more explicit details and real-life examples such as write in RAM examples on how this is bad. A follow-up question that is part…
Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) (10 Marks) I want a detailed explanation to understand the mechanism how it is Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less…
Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). (10 Marks) PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less than$20.00. f. Retrieve the names of customers who have not placed…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning