I am receiving error messages for this palindrome problem. I am reading in a file and outputting the results if it is a palindrome or not using stacks. Any ideas as to why I am receiving error messages below.
include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <cstdlib>
//____________________________________________________________________________________
using namespace std;
//____________________________________________________________________________________
class CommandLineException
{
public:
CommandLineException(int max, int actual)
{
cout << " Too many command line arguments. " << endl;
}
};
//____________________________________________________________________________________
class FileException
{
public:
FileException(char* fn)
{
cout << " File " << fn << " could not be opened. " << endl;
}
};
//____________________________________________________________________________________
class Stack_Empty_Exception
{
public:
Stack_Empty_Exception(char* a)
{
cout << " I am . " << a <<" empty" << endl;
}
};
//____________________________________________________________________________________
class Stack_Full_Exception
{
public:
Stack_Full_Exception(char* fn)
{
cout << " I am " << fn << " full. " << endl;
}
};
//____________________________________________________________________________________
class Stack
{
public:
Stack(int);
~Stack();
bool isFull(void); // check less than size
bool isEmpty(void);
void Push(char v);
char Pop(void);
private:
int size;
int top_of_stack;
char* s;
};
//____________________________________________________________________________________
Stack::Stack()
{
int sz = 100;
size = sz;
top_of_stack = -1;
s = new char[size];
}
//____________________________________________________________________________________
Stack::~Stack()
{
if(s)
{
delete[]s;
}
}
//____________________________________________________________________________________
bool Stack::isFull(void)
{
return top_of_stack >= size - 1;
}
//____________________________________________________________________________________
bool Stack::isEmpty(void)
{
return top_of_stack < 0;
}
//____________________________________________________________________________________
void Stack::Push( char v)
{
if (isFull())
throw Stack_Full_Exception();
s[++top_of_stack] = v;
}
//____________________________________________________________________________________
char Stack::Pop(void)
{
if (isEmpty())
throw Stack_Empty_Exception();
return s[top_of_stack--];
}
//____________________________________________________________________________________
int main(int argc, char * argv[])
{
try
{
char infile[100]; // input file
char outfile[100]; // output file
if (argc == 1)
{
cout << " Enter the input file name. " << endl;
cin >> infile;
cout << " Enter the output file name. " << endl;
cin >> outfile;
cout << endl;
}
else if (argc == 2)
{
strcpy(infile, argv[1]);
cout << " Enter the output file name. " << endl;
cin >> outfile;
cout << endl;
}
else if ( argc == 3)
{
strcpy(infile, argv[1]);
strcpy(outfile, argv[2]);
}
else
{
throw CommandLineException(2,argc -1);
}
ifstream i(infile);
if(!i)
throw FileException(infile);
ofstream o(outfile);
if(!o)
throw FileException(outfile);
o.close();
i.close();
} catch(...)
{
cout << " Program Terminated. " << endl;
exit(EXIT_FAILURE);
}
void is_Palindrome(isstream& i, ostream& o)
{
for(;;)
{
string word;
i >> word;
if ( i.eof())
break;
o << endl;
o << word << " is a palindrome. " << endl;
} // end of for loop
} // end of is_Palindrome function.
bool check_Palindrome( string& word)
{
Stack reverse;
for ( int i = 0; i < word.length(); i++)
{
reverse.push(word[i]);
}
for ( int j = 0; j < word.length(); j++)
{
if (word[j] != reverse.pop())
return false;
else
return true;
}
} // end of check_palindrome
return 0;
}
error messages:
mpiling...
p02.cpp
D:\MSDev98\CS2613\p02\p02.cpp(79) : error C2511: 'Stack::Stack' : overloaded member function 'void (void)' not found in 'Stack'
D:\MSDev98\CS2613\p02\p02.cpp(59) : see declaration of 'Stack'
D:\MSDev98\CS2613\p02\p02.cpp(111) : error C2512: 'Stack_Full_Exception::Stack_Full_Exception' : no appropriate default constructor available
D:\MSDev98\CS2613\p02\p02.cpp(118) : error C2512: 'Stack_Empty_Exception::Stack_Empty_Exception' : no appropriate default constructor available
D:\MSDev98\CS2613\p02\p02.cpp(178) : error C2065: 'isstream' : undeclared identifier
D:\MSDev98\CS2613\p02\p02.cpp(178) : error C2065: 'i' : undeclared identifier
D:\MSDev98\CS2613\p02\p02.cpp(178) : error C2065: 'o' : undeclared identifier
D:\MSDev98\CS2613\p02\p02.cpp(178) : error C2275: 'ostream' : illegal use of this type as an expression
d:\vc98\include\iosfwd(257) : see declaration of 'ostream'
D:\MSDev98\CS2613\p02\p02.cpp(179) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
D:\MSDev98\CS2613\p02\p02.cpp(183) : error C2065: 'word' : undeclared identifier
D:\MSDev98\CS2613\p02\p02.cpp(183) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
D:\MSDev98\CS2613\p02\p02.cpp(184) : error C2228: left of '.eof' must have class/struct/union type
D:\MSDev98\CS2613\p02\p02.cpp(186) : error C2563: mismatch in formal parameter list
D:\MSDev98\CS2613\p02\p02.cpp(186) : error C2568: '<<' : unable to resolve function overload
could be 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)'
d:\vc98\include\ostream(377) : see declaration of 'endl'
or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)'
d:\vc98\include\ostream(372) : see declaration of 'endl'
or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)'
d:\vc98\include\ostream(367) : see declaration of 'endl'
D:\MSDev98\CS2613\p02\p02.cpp(187) : error C2297: '<<' : illegal, right operand has type 'char [19]'
D:\MSDev98\CS2613\p02\p02.cpp(192) : error C2601: 'check_Palindrome' : local function definitions are illegal
Error executing cl.exe.
p02.obj - 14 error(s), 1 warning(s)