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

  Write a program that will read in 2 numbers per line

1.Write a program that will read in 2 numbers per line, and print the sum. You program should work for any number of lines of data.

  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.

  The fibonacci sequence

In the novel "The DaVinci Code", a scrambled version 13, 3, 2, 21, 1, 1, 8, 5 of the first eight Fibonacci numbers appear as one of the clues left by murdered museum curator Jacques Sauniere. In this assignment, we will do something related to t..

  Use structures to create c program to compute student record

Explain the following and give their suitable syntax. A pointer. Use structures to create C program to compute and store student records of class.

  Program to translates letter grade into number grade

In C++ (should be able to compile in Visual Studio 2010): Write a program to translates letter grade into number grade. Letter grades are A,B,C,D and F, possibly followed by a + or -.

  Cashregister class that can be used with the retailitem clas

Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument.

  Dealerships are awarded the rebate

Dealerships are awarded the rebate on a quarter-by-quarter basis, only for quarters where their actual sales exceeded expected volumes for that quarter. Expected sales volumes for each quarter are as follows:

  Write c function to sort one dimensional integer array

Consider the values sorted in the array. Sort it in ascending order using Bubble sort technique showing all iterations: write C function to sort one dimensional integer array in ascending order.

  Write song playlist class-object-oriented design principles

Write a song playlist class in C++ called "PlayList" using object-oriented design principles. The playlist should support the following ADT.The implementation should be based on an array of strings to store the song titles.

  C program to solve the quadratic equation of rocket launch

Write a C program to solve the quadratic equation of rocket launch by computing the roots (t1 and t2) of that quadratic equation: gt2 + vt + l = 0 (or) for simplicity ax2 + bx + c = 0. Get the values of g, v, and l from the user. The program should d..

  Design a nested program

How many levels of nesting are there in this design?

  Writing a program that creates a linked list

Writing a program that creates a linked list from 100 randomly generated numbers and sorts the using a heap. One heap in ascending order and one heap in descending order. Then displays the original linked list and both sorted lists.

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