Guest User

Untitled

a guest
Sep 11th, 2011
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. //Files originally from the book files, I have modified it for the assignment
  2. //Program to test the various operations of a stack
  3.  
  4. #include <iostream>
  5. #include "myStack.h"
  6.  
  7. using namespace std;
  8.  
  9. void testCopyConstructor(stackType<int> otherStack);
  10.  
  11. int main()
  12. {
  13.     stackType<int> stack(50);
  14.     stackType<int> copyStack(50);
  15.     stackType<int> dummyStack(100);
  16.  
  17.     stack.initializeStack();
  18.     stack.push(23);
  19.     stack.push(45);
  20.     stack.push(38);
  21.     copyStack = stack;  //copy stack into copyStack
  22.  
  23.     cout << "The elements of copyStack: ";
  24.     while (!copyStack.isEmptyStack())  //print copyStack
  25.     {
  26.         cout << copyStack.top() << " ";
  27.         copyStack.pop();
  28.     }
  29.     cout << endl;
  30.  
  31.     copyStack = stack;
  32.     testCopyConstructor(stack);  //test the copy constructor
  33.  
  34.     if (!stack.isEmptyStack())
  35.         cout << "The original stack is not empty." << endl
  36.              << "The top element of the original stack: "
  37.              << copyStack.top() << endl;
  38.  
  39.     dummyStack = stack;  //copy stack into dummyStack
  40.  
  41.     cout << "The elements of dummyStack: ";
  42.     while (!dummyStack.isEmptyStack())  //print dummyStack
  43.     {
  44.         cout << dummyStack.top() << " ";
  45.         dummyStack.pop();
  46.     }
  47.     cout << endl;
  48.    
  49. //start of my code *************************************
  50.     cout << endl << "--START OF MY CODE--" << endl;
  51.    
  52.     stackType<int> stackOne(20);
  53.     stackType<int> stackTwo(20);
  54.     stackType<int> stackThree(30);
  55.    
  56.     stackOne.push(4);
  57.     stackOne.push(20);
  58.     stackOne.push(80);
  59.     stackOne.push(100);
  60.     stackOne.push(42);
  61.    
  62.     stackTwo.push(4);
  63.     stackTwo.push(20);
  64.     stackTwo.push(80);
  65.     stackTwo.push(100);
  66.     stackTwo.push(42);
  67.    
  68.     stackThree.push(75);
  69.     stackThree.push(60);
  70.    
  71.     cout << stackOne.top() << " " << stackTwo.top() << endl;
  72.    
  73.     if(stackOne == stackTwo)
  74.     {   cout << "stackOne is equal to stackTwo" << endl;}
  75.     else
  76.     {   cout << "stackOne is NOT equal to stackTwo" << endl;}
  77.    
  78.     if (stackOne == stackThree)
  79.     {   cout << "stackOne is equal to stackThree" << endl;}
  80.     else
  81.     {   cout << "stackOne is NOT equal to stackThree" << endl;}
  82.    
  83.     cout << "20 has been pushed onto stackOne" << endl;
  84.     stackOne.push(20);
  85.    
  86.     if(stackOne == stackTwo)
  87.     {   cout << "stackOne is equal to stackTwo" << endl;}
  88.     else
  89.     {   cout << "stackOne is NOT equal to stackTwo" << endl;}
  90.    
  91.    
  92.  
  93.  
  94.  
  95.     cout << endl << "--END OF MY CODE--" << endl;
  96. //end of my code ***************************************
  97.  
  98.     return 0;
  99. }
  100.  
  101. void testCopyConstructor(stackType<int> otherStack)
  102. {
  103.     if (!otherStack.isEmptyStack())
  104.         cout << "otherStack is not empty." << endl
  105.              << "The top element of otherStack: "
  106.              << otherStack.top() << endl;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment