Please read the problem carefully and answer the 2 questions below
code:
/*****************************************************************
* Program: palindrome.c
*
* Purpose: implements a recursive function for determining
* if a string is a palindrome
*
* Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek
*
*****************************************************************/
#include
#include
#include
/*****************************************************************
* is_palindrome - determines whether a string of characters is a
palindrome
*
* calling sequence:
* result = is_palindrome(str, first_index,
last_index)
*
* parameters -
* str - the string to test
* first_index - index of the first character
in the string
* last_index - index of the last character
of the string
*
* result -
* Returns a 1 if the string in the range
first_index..last_index is a
* palindrome; otherwise returns a 0.
*
* example -
* If idx1 is 0 and idx2 is 4, and str is
"radar in range", then a 1 is
* returned; if the string were "rural", then
0 is returned.
*
* implementation -
* The first and last characters are
examined. If they don't match,
* a zero is returned. Otherwise
we (recursively) test the string
* without the first and last
characters.
*
*****************************************************************/
int is_palindrome(char *str, int first_index, int last_index)
{
if (first_index >= last_index) {
/* BASE CASE: string of length 1 or less:
return 1 for true */
return 1;
}
else if (str[first_index] != str[last_index]) {
/* BASE CASE: first and last chars
mismatch: return 0 for false */
return 0;
}
else {
/* RECURSIVE CASE: str[first_index] ==
str[last_index] */
/* store result in temporary variable so
that we can look at it
in debugger */
int result = 0; // update this to be the
result of the recursive call
//
should just be one line of code
return result;
}
}
/*****************************************************************
* main - main program to exercise 'is_palindrome'
*
* This program prompts the user a string, and then calls
'is_palindrome' on the
* string.
* note: only works for strings of < 10000 characters
* DO NOT MODIFY
*****************************************************************/
int main(int argc, char *argv[]) {
char buffer[10000]; /* buffer, hopefully plenty big to
hold the string */
buffer[0] = 0; /*
(in case empty string is typed) */
printf("Please type a line of text: ");
scanf("%9999[^\n]", &buffer);
int length = strlen(buffer); /* length of string up to
first null-character */
printf("The string is %sa palindrome.\n",
is_palindrome(buffer, 0,
length-1) ? "" : "not ");
return EXIT_SUCCESS;
}
int is_palindrome(char *str, int first_index, int last_index) { if (first_index >= last_index) { /* BASE CASE: string of length 1 or less: return 1 for true */ return 1; } else if (str[first_index] != str[last_index]) { /* BASE CASE: first and last chars mismatch: return 0 for false */ return 0; } else { /* RECURSIVE CASE: str[first_index] == str[last_index] */ /* store result in temporary variable so that we can look at it in debugger */ int result = 0; // update this to be the result of the recursive call // should just be one line of code result = is_palindrome(str, first_index+1, last_index-1); return result; } }
Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...
In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...
C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...
Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly. please put comment with code! and please do not just copy other solutions. 1. write the code using function 2. Please try to implement a function after the main function and provide prototype before main function. Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...
Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...
Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...
Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...