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

  Design a simple game of blackjack

Prepare a simple game of blackjack using object oriented programming.

  We wish to process survey results

Suppose we wish to process survey results that are stored in a file. This exercise requires twoseparate programs. First, create a program that prompts the user for survey responses and outputseach response to a file

  Determine the meaof the numbers in the array

Determine the mean(average) of the numbers in the array, and output the reslt. Use a subprogram to input the numbers, a function to find the mean.

  Program to print out invalid number to character

The integer must contain 3 distinct non-zero number, or the program will print out invalid number.it should print out invalid query.

  Write c++ program that reads in the average monthly rainfall

Write a C++ program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months

  Create a base employee class

Create a base Employee class and a derived StudentEmployee class

  Change this code to read in strings from a text file

code takes in a string from a user, checks if the paranthesis are ballanced (as defined by my class) and also returns the variable from my line (also from my class). All like to change this code to read in strings from a text file (each line is a str..

  Write a very basic doubly-linked list

CptS 122 Lab #2: Linked Lists ,  Along with vectors, linked lists are one of the fundamental data structures in computer science. Unlike vectors, which store information in a contiguous block of computer memory, linked lists have the potential to sto..

  Use the top-down modular approach to design program

Use the top-down modular approach and pseudocode to design a suitable program to solve it. Where appropriate, use defensive programming techniques.

  Write c program for linked list applications

Write a complete C program which illustrates the Linked list applications data structures and algorithms. The program will read in mid-semester test scores as Main Linked List and produce six outputs:

  Write a c program which takes a string from command line

Write a c program which takes a string from command line with mainfunction has no parameter and convert the string in upperca

  Create class integerset

Create class IntegerSet for which each object can hold integers in the range 0 through 100. Represent the set internally as a vector of bool values. Element a[i] is true if integer i is in the set. Element a[j] is false if integer j is not in the set..

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