473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Palindrome program - unsure what to do next

Expand|Select|Wrap|Line Numbers
  1. class MyStack{
  2.   public:
  3.       MyStack(int sz=10);
  4.       ~MyStack();
  5.       char pop(); 
  6.       void push(char ch);
  7.       bool isEmpty();
  8.       bool isFull();
  9.   private:
  10.       char *value;
  11.       int  top;    
  12.       int  size;
  13. };
  14.  
  15. MyStack::MyStack(int sz){
  16.    size = sz;
  17.    value = new char[size];
  18.    top = -1;
  19. }
  20. MyStack::~MyStack(){
  21.     delete [] value;
  22. }
  23. bool MyStack::isEmpty(){
  24.     if (top == -1) return true; 
  25.     else return false;
  26. }
  27. bool MyStack::isFull(){
  28.     if (top == size) return true; 
  29.     else return false;
  30. }
  31. void MyStack::push(char ch){
  32.      if (!isFull()) value[++top]=ch;
  33.      else cout << "stack is full" << endl;
  34. }
  35. char MyStack::pop(){
  36.     char ch;
  37.     if (!isEmpty()) return value[top--];
  38.     else 
  39.     cout << "stack is Empty" << endl;
  40.     return '.';
  41. }
  42.  
  43. int main(){
  44.     string str2;
  45.     string str;
  46.     cout<< "input a word: ";
  47.     cin >> str;
  48.     MyStack  a(str.length());
  49.     for (int i=0;i<str.length();++i) 
  50.     a.push(str[i]);
  51.     while (!a.isEmpty())
  52.     {
  53.           cout << a.pop();  
  54.     }
  55.      str2=a.pop();
  56.      if(str ==str2)
  57.      cout<<"Palindrome"<<endl;
  58.      else 
  59.      cout<<"Sorry No Palindrome"<<endl;
  60.  
  61.     cout << endl;   
  62.     system("pause");   
  63. }
  64.  
im stuck in the place to show wheter it is palindrome or not!!
Nov 11 '07 #1
1 1990
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. int main(){
  2.     string str2;
  3.     string str;
  4.     cout<< "input a word: ";
  5.     cin >> str;
  6.     MyStack  a(str.length());
  7.     for (int i=0;i<str.length();++i) 
  8.     a.push(str[i]);
  9.     while (!a.isEmpty())
  10.     {
  11.           cout << a.pop();  
  12.     }
  13.      str2=a.pop();
  14.      if(str ==str2)
  15.      cout<<"Palindrome"<<endl;
  16.      else 
  17.      cout<<"Sorry No Palindrome"<<endl;
  18.  
  19.     cout << endl;   
  20.     system("pause");   
  21. }
  22.  
im stuck in the place to show wheter it is palindrome or not!!
In your while loop, you are popping the characters of the stack out and outputting them until the stack is empty. Then, you try and assign str2 to a.pop(). Not only will your stack say it is empty and not be able to pop, but even if it did, you are trying to return a char and assign it to a string. Maybe you should say:

Expand|Select|Wrap|Line Numbers
  1. str2 = "" + a.pop();
which would add the return value of pop() to the string. Of course, you should use the += operator in order to continue getting these characters to build the reverse of str.
Nov 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lorin Leone | last post by:
Can anyone help me modify the program so that it recognizes strings like "Anna" as palindromes. To make the program "case-insensitive." using the built-in C++ function "toupper". and so that it...
23
by: Amar Prakash Tripaithi | last post by:
Dan Hoey, who had recently graduated, wrote a C program to look for and construct the following beauty: A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa,...
32
by: ramakrishnadeepak | last post by:
HI Everybody, I 've to submit a program on c.Can any one help me plz.........The problem is like this:: Write a program which computes the largest palindrome substring of a string. Input:...
0
by: Kesha | last post by:
THE PALINDROME INVESTIGATOR A palindrome is a word, phrase, verse, or sentence that reads the same backward or forward. For example: A man, a plan, a canal, Panama! You are required to develop a...
3
by: colinNeedsJavaHelp | last post by:
I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start. A word or phrase in...
2
by: Synapse | last post by:
aloha people! I need help in my java palindrome program. It's a 5-digit palindrome checker. The code below is running good but i got a few problems on it. If I enter 33633, 11211, 45554, it will...
20
by: Wabz | last post by:
Hello mates, Does anyone know how to write a function that tests if an integer is a palindrome in C language?
4
by: vicestner | last post by:
Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and...
2
by: bigtd08 | last post by:
help writing this palindrome program for my c++ class. HERE WHAT THE CODE SHOULD BE LIKE. Write a program that takes a line of input from the keyboard and check to see if that line is a palindrome....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.