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

A palindrome is a character string that is equal to its reverse. A simple palind

ID: 3704962 • Letter: A

Question

A palindrome is a character string that is equal to its reverse. A simple palindrome would be a word that is the same spelled forward or backward such as “level”. A palindrome can also be a phrase such as "Never odd or even". This is not a simple palindrome, since making it the same as its reverse requires that we ignore spaces and punctuation marks. For this assignment, a palindrome is defined to be a character string, where all non-alphabetic characters are ignored, and upper-case and lower-case versions of the same letter are viewed as equivalent. Alphabetic characters includes characters ’A’ through ’Z’ and ’a’ through ’z’ inclusive. Thus punctuation marks, digits, space, tab, carriage return, hyphens, underscores, and other non-alphabetic characters are ignored in the palindrome decision process. The assignment is to write a program that does the following. You will need to define extra functions to complete some of these tasks such as the first two bullet items: • Prompts the user to type in a character string • Gets the characters and stores them in a stack data structure. • Makes use of the stack and a queue data structure to check for a palindrome. • Defines a function “isPalindrome” that determines whether the string is a palindrome. The function “isPalindrome” returns 1 if x is a palindrome, and 0 if x is not a palindrome. int isPalindrome(char *x) • Displays an appropriate message on the screen that indicates the string and whether the string is a palindrome or not. Programming Hints • Your program will involve three files: main.cpp, Palindrome.cpp, and Palindrome.h. o The file Palindrome.h contains exactly one line, the prototype of your function isPalindrome. o The file Palindrome.cpp contains the definition of your function isPalindrome. It should have your name, the date, and #include "Palindrome.h". It should not contain a main function. o Your file main.cpp contains your main function. That file should also specify any #include files, including Palindrome.h. Your main program should thoroughly test the Palindrome program • The following header files must be defined and included in the source code using the stacks and queues. o #include “stack” o #include “queue” You will need to submit the files with your submission of the other 3 files mentioned above. • The following functions may be helpful and are provided by the C Standard Library: o int isalpha(char c) // returns non-zero integer if c is an alphabetic character, 0 if not o char toupper(char c) // returns the upper-case version of an alphabetic character Testing Suggestions A list of examples is given below in a C++ variable declaration. Make sure that you test for the following situations. 1. Test that your program returns a value of 1 on the examples. 2. Test that your program returns 0 if you change one of the characters in any of the examples. Examples "A dog, a panic in a pagoda" "A dog, a plan, a canal, pagoda" "A man, a plan, a canal-- Panama!” // punctuation and spaces are ignored "civic" "If I had a hi-fi" "Do geese see God?" "Madam, I’m Adam." "Madam, in Eden, I’m Adam." "Neil, a trap! Sid is part alien!" "Never odd or even" "No devil lived on." "No lemons, no melon" "racecar" "RACEcar" // uppercase equals lowercase “Rats live on no evil star." "Red rum, sir, is murder!" "Rise to vote, sir." "rotator" "rotor" "Step on no pets." "Was it a cat I saw?" "Was it a car or a cat I saw?" "Yawn a more Roman way. " Extra Credit (20 Points) • Allow the user to choose whether to enter a string to check or a file to check • In the case of a file, read each line of text from an input data file • Write to the screen all lines that are palindromes with an appropriate message

Explanation / Answer

Hi Dear, As mentioned in Question, you have not posted stack.h and queue.h files. So, I can not test the program.

I have implemented required functionality.

Copyable code:

//Palindrome.h

#ifndef _PALINDROME

#define _PALINDROME

     // method protocol declaration

     int isPalindrome(char *isPl);

#endif

//Palindrome.c

#include "Palindrome.h"

#include "stackh"

#include "queue.h"

// method to check the input is palindrome or not

int isPalindrome(char *isPl)

{

     // declare the required variables

     int lp = 0;

     stack palstk;

     queue palqu;

     // code to check the palindrome

     while( isPl[lp] != '' )

     {

          if(isalpha(isPl[lp]))

          {

              palstk.push(toupper(isPl[lp]));

              palqu.push(toupper(isPl[lp]));

          }

          lp++;

     }

     while(!palstk.empty())

     {

          if(palqu.front()==palstk.top())

          {

              palqu.pop();

              palstk.pop();

          }else

          {

              return 0;

          }

     }

     return 1;

}

//main.c

#include "Palindrome.h"

#include <stdio.h>

// main method to invoke the functions to test palindrome

int main()

{

     //Character array with a set of strings

     char *palcheck[] = {

     "Hello world", "A dog, a panic in a pagoda",

     "A dog, a plan, a canal, pagoda",

     "A man, a plan, a canal?? Panama!",

     "civic",

     "No lemons, no melon",

     "racecar",

     "RACEcar",

     "Rats live on no evil star.",

     "Red rum, sir, is murder!",

     "Rise to vote, sir.",

     "rotator",   

     };

    

     // loop code to check each string is palindrome or not

     for(int lp=0;lp<12;lp++)

     {

          printf("%s:",palcheck[lp]);

     printf("%s ",isPalindrome(palcheck[lp])?printf("yes")

: printf("no"));

     }   

}

Please DONT forgot to rate my answer. We are working hard for you Guys!!

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