/** File "StringClient10.cpp", by KWR for CSE250, Fall 2009.
    In Fall 2010---to work on during Week 3 recitations.
    Example of translating Java quasi-verbatim into C++.
    Later we will write C++ code "the C++ way", using fewer pointers.
 */

#include <iostream>
#include <vector>       
#include <string>    //not needed on timberlake, *is* needed in Visual C++

using namespace std;

class StringStack {
   int top; 
   //static const int maxSize = 101;        //AOK, but not what Java did
   const int maxSize;                       //initialized by constructor

   vector<string>* elements;

   //CLASS INV:

 public:

   /** Create empty stack
    */
   StringStack() : top(0), maxSize(101),
                   elements(new vector<string>(maxSize)) { }

   virtual void push(string c) {
      elements->at(top++) = c;
   }
   virtual string pop() {
      if (top == 0) {
         cerr << "Attempt to pop from empty stack." << endl;
         return "";
      } else {
         return elements->at(--top);
      }
   }
   virtual int size() { return top; }
};

/** Test-driving code for StringStacks.
 */
int main() {
   StringStack* testStack = new StringStack();
   cout << "Pushing \"AAA\" ... ";     //use cout << ...
   testStack->push("AAA");
   cout << "Pushing \"BBB\" ... " << endl;   //this tacks on ...<< endl;
   testStack->push("BBB");
   cout << "Size is now " << testStack->size() << endl;
   testStack->pop();               // ^ chain with "<<" instead in C++
   cout << "Pop---size is now " << testStack->size();
   string c = testStack->pop();
   cout << "I popped the string \"";
   cout << c << "\", size now " << testStack->size() << endl;
   cout << "Can I pop again?" << endl;
   string d = testStack->pop();
   cout << "Oops!  I got: \"" << d << "\"" << endl;

   return (0);
}
   

