Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,111 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,732 people online right now. Registration is fast and FREE... Join Now!




check if a word is a palindrome

 
Reply to this topicStart new topic

check if a word is a palindrome, this is how far i have gone am stuck on the client file

chocho
15 Apr, 2007 - 10:15 AM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2007
Posts: 11


My Contributions
CODE
#include  <iostream>
# include  "queue.h"
#include <string>
#include "stack.h"
using namespace std;
  int main()
{
    queue Q;
    stack S;
string str;
int i;
char ch;
cout<< "Enter a string: ";
getline(cin, str, '\n');;

for (i = 0; i < str.length(); i++)
{
ch = str [i];
Q.EnQueue(ch);
S.Push(ch);
}

while(!Empty() && charactersAreEqual)
{
Q.Front();
S.Top();

if(Q.Front ==S.Top)
{
Q.DeQueue();
S.Pop();
return true
cout<<" ‘ " <<str << " ‘ is a Palindrome" <<endl;
}
else
{
    return false;
cout << " ‘ " << str << " ‘ is not a palindrome" <<endl;
}
return 0;


}
[i][b]this is my stach.h code[/b][/i]

#include "singlist.h"
#ifndef STACK_H
# define STACK_H

template <class dataType>
class stack : public singlist <dataType>
{
public:
void Push(dataType item);
dataType Pop();
bool Empty();
void clear();
dataType Top();
};

template <class dataType>
void stack<dataType>::Push(dataType item)
{
Add1(item);
}

template <class dataType>
bool stack<dataType>::Empty()
{
   return Head= = NULL;
}


template <class dataType>
dataType stack<dataType>::Top()
{
try
{ if (Head !=NULL)
   return Head->data;
else
throw "****Empty Stack****";
}
catch (char *str)
{
cout<<"caught Stack exception:" <<str;
}
}
template <class dataType>
dataType stack<dataType>::Pop()
{
dataType temp;
try
{ if (!Empty() )
   {temp = Top();
Remove (temp);
return temp;
}
else
throw "****Error Empty Stack****";

}//end of try
catch (char *str)
{
cout<<"caught Stack exception:" <<str;
}// end of catch function
}// end of function

template <class dataType>
void stack<dataType>::clear ()
{
dataType trash;
if (!Empty())
while(Head=!NULL)
trash = Pop();
else
cout <<"***Cant Clear Empty Stack***" <<endl;
}
#endif



my queue code

#include "stack.h"
#ifndef QUEUE_H
#define QUEUE_H
template <class dataType>
class queue: public stack<dataType>
{
public:
void EnQueue(dataType item);
dataType DeQueue();
dataType  Front();
};

template <class dataType>
void queue<dataType>::EnQueue(dataType item)
{
Add2(item);
}

template <class dataType>
dataType queue<dataType>::DeQueue()
{
try
{ if (Head !=NULL)
   return Pop();
else
throw "****Empty Queue****";

}
catch (char *str)
{
cout<<"caught queue exception:" <<str;
}
}

template <class dataType>
dataType queue<dataType>::Front()
{
try
{ if (Head !=NULL)
   return Top();
else
throw "****Empty Queue****";
}
catch (char *str)
{
cout<<"caught queue exception:" <<str;
}
}
#endif

crazy.gif
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Check If A Word Is A Palindrome
15 Apr, 2007 - 10:23 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Can you specify the problem you are encountering, along with any error messages being generated?
User is offlineProfile CardPM
+Quote Post

chocho
RE: Check If A Word Is A Palindrome
17 Apr, 2007 - 02:40 PM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2007
Posts: 11


My Contributions
These are a few errors that am getting so far

error C2133: 'Q' : unknown size
error C2133: 'S' : unknown size
error C2262: 'Q' : cannot be destroyed
error C2262: 'S' : cannot be destroyed
'queue' : no appropriate default constructor available
error C2662: 'queue<dataType>::EnQueue' : cannot convert 'this' pointer from 'queue' to 'queue<dataType> &'
error C2662: 'stack<dataType>::Empty' : cannot convert 'this' pointer from 'stack' to 'stack<dataType> &'
error C2662: 'stack<dataType>::Push' : cannot convert 'this' pointer from 'stack' to 'stack<dataType> &'
error C2955: 'queue' : use of class template requires template argument list


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:39PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month