Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a C++ program that can recognize if a given string of characters s of l

ID: 3632927 • Letter: 1

Question

1. Write a C++ program that can recognize if a given string of characters s of length n is a palindrome or not. You should write three functions in addition to the main function. The main function should call an integer function named InputString that reads the input characters of length n. The integer returned is this value n representing the length of the current string which is not selected a priori. Use a global array for the string s of size m > n. n is local variable which will change depending on the size of the input string by the user. Once the string is entered, check to see if the string length is greater than zero. For a non zero string length, call another function named PalindromeTest to test if the string is a palindrome. The returned value of the function is Boolean. Call another function PrintMessage upon return from PalindromeTest to display the result of the test. Print “The string ‘s’ is a palindrome”/ “The string ‘s’ is NOT a palindrome” depending on the situation. You must substitute the real string for s in the printed message. Use a switch statement in this function to select the appropriate print statement. The main function must continue to read the next string until an empty string is entered (string with length 0).


PLEASE USE THE STRING LIBRARY AND COMMENT ON EXACTLY WHY YOU DID WHAT YOU DID AND MAKE IT AS EASY AS POSSIBLE







Explanation / Answer

Dear Friend hope this will help u i tried to make it simple as u required and as the statements in the assignment want PLEASE RATE #include #include using namespace std; /*Program that tells you whether what you enter is a palindrome or not*/ const int N =100; char pal[N]; //input line int i; //counter int k; //counter int tag;//size of line int PALINDROME =0; int NONPALINDROME=1; int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/ int InputString(char pal[]) { coutpal; /*determine length of string*/ return strlen(pal); } bool PalindromeTest() { /* pointer running from the beginning and the end simultaneously looking for two characters that don't match */ /* initially assumed that string IS a palindrome */ /* the following for loop looks for inequality and flags the string as a non palindrome the moment two characters don't match */ for (i=0,k=tag-1; i=0; i++,k--) { if(pal[i] != pal[k]) { return false; } } return true; } void PrintMessage () { if(flag == PALINDROME) cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote