Implement a function to recursively

Assignment Help C/C++ Programming
Reference no: EM13163468

Half of the code is done. It's shown below, please follow as its starting and provide a simplicity code.   

Palindrome Tester (C++)

Implement a function to recursively determine if a word is a palindrome. A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction. Famous examples include "Able was I ere I saw Elba", "A man, a plan, a canal: Panama".

Important questions to ask yourself:

  • What is the base case?
  • What is the recursive case?

The substr method of the string class will be useful. It takes the starting position of the first character to be copied as a substring and the number of characters to include in the substring.
Also useful is the length method. It returns the length of the string in question.

Examples:

string s = "defiant";
cout << s.substr(2, s.length()-4) << endl;

The above example prints out: fia

Here is some code to get you started. Submit your modified palindrome function. Do not modify the main function. When testing your function don't forget to type the word on the command line after "a.out": ./a.out radar
Starting...

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

bool palindrome(string);

int main(int argc, char *argv[]) {

    string s = argc == 2 ? argv[1] : "redivider";

    if (palindrome(s)) {
        cout << "\"" << s << "\" is a palindrome." << endl;
    }
    else {
        cout << "\"" << s << "\" is not a palindrome." << endl;
    }

    return 0;
}

bool palindrome(string w) {

    // your code goes here

    return false;
}

Reference no: EM13163468

Questions Cloud

Display the array, the average and the number of days above : Write a program that stores the daily temperatures for the month of April in an array name dailytemp. Calculate the average temperature for the month and the count the number of days that the daily temperature was above the average.
Simple java application that uses the string : Create a simple Java application that uses the String class and/or the StringBuffer class and at least 4 of the class methods. Show the code, demonstrate it works properly and describe what it is doing.
Using unix extract the various ethnic populations in file : Using Unix extract the various ethnic populations in your file.
Using array subscript notation : Using array subscript notation, base/offset notation with the array name as the pointer, array notation with  vPtr , and pointer/offset notation with  vPtr , add 3 to the value in the 3 rd element and display that number. (Do not modify the value in ..
Implement a function to recursively : Implement a function to recursively determine if a word is a palindrome. A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.
. assume the node is in the usual info-link form with info : Show what is produced by the following C++ code. Assume the node is in the usual info-link form with the info of the type int. (list, trail, and current are pointers of type nodeType.)
Prepare the journal entry to record depreciation expense : Irons Delivery, Inc., purchased a new delivery truck for $42,000 on January 1, 2009. The truck is expected to have a $2,000 residual value at the end of its five-year useful life. Irons uses the straight-line method of depreciation.
Compute price and usage variances for direct materials : Compute price and usage variances for direct materials and compute the direct labor rate and labor efficiency variances.
Find all irreducible polynomials : Find all irreducible polynomials1. of degree 3 over GF(2),2. of degree 4 over GF(2).

Reviews

Write a Review

 

C/C++ Programming Questions & Answers

  Properly store the number from variable value

1. Statement will properly store the number from variable  value  into the output file object AnsFile?

  Multiple choice question on c programming

Create a function to print "88 is a great port number" function name is yourName_PrintFunction no input no return type print "88 is a great port number"

  Design and implement a library system

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality.

  Program to enter number of values to be processed

Write c++ statements to permit the user to enter n, the number of values to be processed; then assign the anonymous array of n double values, storing its address in doublPtr.

  Compute a program that calculates three resistance inputs

C language, compute a program that calculates three RESISTANCE inputs, and gives you the total resistance in OHMS. Like this, the total resistance is _____ ohms. These are three parallel circuits so the formula would be (1/R1 + 1/ R 2 +  1/ R 3 )  -1

  Program to check compatibity for matrix multiplication

Write down program in C++ for matrix multiplication. Program must accept dimension of both matrices to be multiplied and check for compatibity.

  Program to output value of tenth component of array

Write a C++ statements to perform the following: Set value of fourth component of array alpha to three times  value of eight component minus 57.

  Use c-strings without using the c-string library

write a program that implementd and test the following functions for use C-strings without using the c-string libaray  ( that is, you re NOT ALLOWED to use #include in this   program):

  Multiple heaps

Create an application that has two heaps. Place a linked list into each heap. Select one hundred random numbers. Place each of the random numbers into each heap - CSI 345 - Spring 2014 S2

  Program which asks the user for due date of next assignment

Write a program which asks the user for due date of the next assignment (hours, minutes). Then print number of minutes between the current time and the due date in format.

  Illustrate example from ansi c programming language

Illustrate example from ANSI C programming language, without using nested procedures, to show the fact that "assignment-by-sharing in conjunction with quasi-dynamic object binding

  Struct complex

A complex number can be represented by two parts, real and image. A series complex data can be organized as a group of elements by linked list, which is shown as below: struct Complex

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd