I need help fixing my code.
My output should be the following.
Hello, world! : false
A dog, a panic in a pagoda : true
A dog, a plan, a canal, pagoda : true
Aman, a plan, a canal--Panama! : true
civic : true
If I had a hi-fi : true
Do geese see God? : true
Madam, I’m Adam. : true
Madam, in Eden, I’m Adam. : true
Neil, a trap! Sid is part alien! : true
Never odd or even : true
No devil lived on. : true
No lemons, nomelon : true
racecar : true
RACEcar : true
Rats live on no evil star. : true
Red rum, sir, is murder! : true
Rise to vote, sir. : true
rotator : true
rotor : true
Step on no pets. : true
Was it a cat I saw? : true
Was it a car or a cat I saw? : true
Yawn a more Roman way. : true
Heres my assignment:
https://www.dropbox.com/s/mawyte4ivhadipw/CSC260_P5-Palindrone_StacksQueues.pdf?dl=0
CODE
Palindrome.cpp
*******************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include "Palindrome.h"
#include "Stack.h"
#include "Queue.h"
// method to check the input is palindrome or not
int isPalindrome(char *isPl)
{
// declare the required variables
int lp = 0;
Stack<char> palstk(100);
Queue<char> palqu(100);
// code to check the palindrome
while( isPl[lp] != '\0' )
{
if(isalpha(isPl[lp]))
{
palstk.push(toupper(isPl[lp]));
palqu.enqueue(toupper(isPl[lp]));
}
lp++;
}
while(!palstk.isEmpty())
{
if(palqu.front==palstk.top)
{
palqu.dequeue();
palstk.pop();
}else
{
return 0;
}
}
return 1;
}
|
Main.cpp
*******************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include "Palindrome.h"
#include <cstdio>
// 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]);
if(isPalindrome(palcheck[lp]))
printf("yes\n");
else
printf("no\n");
}
}
|
Palindrome.h
*******************************
1 2 3 4 5 6 7 8 9
|
#ifndef _PALINDROME
#define _PALINDROME
// method protocol declaration
int isPalindrome(char *isPl);
#endif
|