I'm trying to do a palindrome check from a text file that reads each line separately and tells whether or not the line is a palindrome and outputs that information to a new file, from the driver program, after creating the stack class using a vector instead of an array. My understanding of this seems to be halted, and I've searched up and down without being able to pick up on this. If my vector is in private data member of the Stack class, should I be passing my inFile through the class or still in the driver? Do my member functions look alright using vector functions to implement them? Is it possible to even make the palindrome check in the driver?
Assignment: Write a driver program to do palindrome check. In your driver program, you are required to use the Stack class that you create in this lab to do the string processing. Your program need to be able to read our provided text file, find which line is palindrome and which line is not, and output all of palindromes line by line to a new file.
Hint: You may consider to use a string(initialized as empty) and your Stack class in your program that reads a line of sentence from the file, one character at a time, pushing only each letter character/number character(not special sign, etc.) onto a stack as it is read and simultaneously append it to the string. Then empty out the stack and put all of the letters/numbers to a second string, which is used to hold the reversed string. Next compare the first string and the second string to see if both are the same.
header file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <vector>
usingnamespace std;
template <class T>
class Stack{
private:
vector<T> data;
public:
bool Empty(); //checks if stack is empty
void Push(T item); //adds item to stack
T Top(); //returns item at top of stack
void Pop(); //removes item at top of stack
friend ostream& operator<<(ostream&out, const Stack &s); //overloaded output operator
};