Question

In: Computer Science

USE C++ for following problem and also use create full program that takes input from user...

USE C++ for following problem and also use create full program that takes input from user also do not use loops only recursion and try to keep program simple

A palindrome is any word, phrase, or sentence that reads the same forwards or backwards. Here are some palindromes: Level Civic Pot top A man a plan a canal Panama Write a boolean function that determines if a string argument is a palindrome. The function should return true if the argument reads the same forwards and backwards. Your function should ignore spaces and be case-insensitive. Assume the input is just letters and spaces.

Solutions

Expert Solution

NOTE : PROGRAM IS DONE WITH C++ PROGRAMMING LANGUAGE.

IT IS DONE IN DEV-C++ 5.11 SOFTWARE AND IT IS GIVINGE EXACT OUTPUT.

HERE THE PROGRAM IS DONE WITH RECURSION ONLY.

PROGRAM

#include<iostream>
#include<string.h>
using namespace std;

/* define function check_paindrome */
bool check_paindrome(char nm[],int f,int l)
{
/* for first and last character matching */
if(f==l)
{
return true;
}
/* if first and last character do not match each other */
if(nm[f]!=nm[l])
{
/* return false , not palindrome */
   return false;
}
/* if index of first character is less than last character plus 1 index */
if(f<l+1)
{
/* recursively call function check_paindrome to check palindrome */
   return check_paindrome(nm,f+1,l-1);
}
/* if the string scan reaches at end, means it it palindrome*/
return true;
}

/* palindrome is a function whose return type is boolean */
/* if it returns true, means string is palindrome, for false the string is not palindrome */
bool palindrome(char w[])
{
int p;
p=strlen(w);
/* empty string is also a palindrome */
if(p==0)
{
return true;
}
/* if string is not empty call recursive function check_paindrome */
/* if check_paindrome is true, means function palindrome will return true in main function*/
/* if check_paindrome is false, means function palindrome will return false in main function*/
return check_paindrome(w,0,p-1);
}

int main()
{
char name[500],st[500];
int i,j=0;
/* console input the string */
   cout<<"Enter a string : ";
   cin.get(name,500);
   /* scan the whole string */
   for (i=0; i<strlen(name); i++)
   {
       /* if i the character of name is not blank space */
       /*function should ignore spaces */
       if(name[i]!=' ')
       {
           /* function should be case-insensitive, so here convert all character in lower case
           and store in another string st*/
           st[j]=tolower(name[i]);
           j++;
       }
      
   }
/* if palindrome function returns true */
if (palindrome(st)==true)
{
cout<<"The string is palindrome"<<endl;
}
/* if palindrome function returns false */
else
{
cout<<"The string is not palindrome"<<endl;
}
return 0;
}

SCREEN SHOT

OUTPUT


Related Solutions

C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
Create the logic for a rhyming program that takes in five words from a user input...
Create the logic for a rhyming program that takes in five words from a user input and replaces the selected rhyming words with the user's input, then creates and displays the Humpty Dumpty rhyme with the five words from the user input. Hint: 1. You will use the sentinel values: start and stop 2. The program will ask the user for 5 words. 3. The program will store the 5 words 4. The program outputs the rhyme replacing the ____...
IN PYTHON create a python program that accepts input from the user in the following sequence:...
IN PYTHON create a python program that accepts input from the user in the following sequence: 1. Planet Name 2. Planet Gravitational Force(g) for data, use the planets of our solar system. The data input is to be written in 2 separate lists, the names of which are: 1. planetName 2. planet GravitationalForce(g) A third list is required that will store the weight of a person with mass of 100kg, the formula of which is: W=mg(where m is mass of...
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream> and switch and if-else statements only. Thank you. Ex. Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four Enter a number: 100000 One Hundred Thousand Enter a number: -2 Number should be from 0-1000000 only
Create a C++ program that will prompt the user to input an positive integer number and...
Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT