Question: Here is my assignment question: Download the CharStack.h and the test driver file from the class web page. You may also download the stack class
Here is my assignment question:
Download the CharStack.h and the test driver file from the class web page.
You may also download the stack class file from the class web page, but the stack class here is a
character stack and you need to change the StackElement to char. Write the implementation of
the function members of the CharStack class in a file named CharStack.cpp. (You can download
the two input files for testing.)
What I have so far:
stack.h
#ifndef STACK #define STACK #include
stack.cpp
#include "stack.h" #include
CharStack.h
#ifndef CHARSTACK #define CHARSTACK #include
CharStack.cpp
#include "CharStack.h" void CharStack::StringToStack(const string & inStr) //Purpose: reads string into its private stack //Precondition: checks if a character is a letter //Postcondition: letters of string are put in private stack { for (int i = 0; i < inStr.length(); i++) { if ((inStr[i] >= 'a'&&inStr[i] <= 'z') || (inStr[i] >= 'A' &&inStr[i] <= 'Z')) { myCharacters.push(inStr[i]); } } } CharStack CharStack::Reverse() //Purpose:empties its private stack into another stack for reversal //Precondition: private stack is not empty //Postcondition: reverses the stack { CharStack ReverseStack; Stack Temp = myCharacters; while (!Temp.empty()) { ReverseStack.myCharacters.push(Temp.top()); Temp.pop(); } return ReverseStack; } bool CharStack::IsEqual(CharStack & B) //Purpose: tests if both private stack and B's stack are the same //Precondition: neither stack is empty //Postcondition: if stack is empty, displays error otherwise sends true or false { if (myCharacters.empty() || B.myCharacters.empty()) { cerr << "Stack is empty." << endl; return false; } while (!myCharacters.empty() && !B.myCharacters.empty()) { if (tolower(myCharacters.top()) != tolower(B.myCharacters.top())) return false; myCharacters.pop(); B.myCharacters.pop(); } return myCharacters.empty() && B.myCharacters.empty(); } ostream & operator<<(ostream & out, const CharStack & CS) //Purpose: overloaded output //Precondition: stack is not empty //Postcondition: contents of stack have been output to ostream out { CharStack Temp = CS; while (!Temp.myCharacters.empty()) { out << Temp.myCharacters.top(); Temp.myCharacters.pop(); } return out; }
Main.cpp
#include
Test.txt
Yaweh. The way. Madam, I'm Adam. Lager, sir, is regal. Neil A. sees alien! Was it a rat I saw? Put Eliot's toilet up. Do geese see God? Enid and Edna dine. Never odd or even. Won ton? Not now! Not a banana baton! Ned, I am a maiden. Ma is a nun, as I am. I'm aloof; a fool am I. Too bad, I hid a boot. Todd erases a red dot. Flee to me, remote elf. He lived as a devil, eh? Poor Dan is in a droop. Rats live on no evil star. Panic in a Titanic, I nap.
But after I build and test the program all that comes up is "Stack full." What did I do wrong and need to change?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
