Mar 14, 2017 at 11:41pm UTC
Doesn't look like NumStack has been defined.
Mar 14, 2017 at 11:46pm UTC
Here is my main and NumStack header file. I did define it. I tried including NumStack.hpp in Stack.hpp, but that didn't work.
main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
// This program demonstrates the MathStack class.
#include <iostream>
#include "NumStack.hpp"
int main()
{
int catchVar; // To hold values popped off the stack
// Create a MathStack object.
Stack <int > stack(5);
// Push 3 and 6 onto the stack.
std::cout << "Pushing 3\n" ;
stack.push(3);
std::cout << "Pushing 6\n" ;
stack.push(6);
// Add the two values.
stack.add();
// Pop the sum off the stack and display it.
std::cout << "The sum is " ;
stack.pop(catchVar);
std::cout << catchVar << std::endl << std::endl;
// Push 7 and 10 onto the stack
std::cout << "Pushing 7\n" ;
stack.push(7);
std::cout << "Pushing 10\n" ;
stack.push(10);
// Subtract 7 from 10.
stack.sub();
// Pop the difference off the stack and display it.
std::cout << "\nThe difference is " ;
stack.pop(catchVar);
std::cout << catchVar << std::endl;
std::cout << "\n\nPushing 5 then 10" ;
stack.push(5);
stack.push(10);
std::cout << "\nThe product is " ;
stack.mult();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 7 then 12" ;
stack.push(7);
stack.push(12);
std::cout << "\nThe product is " ;
stack.mult();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 14 and 2" ;
stack.push(14);
stack.push(2);
std::cout << "\nThe quotient is " ;
stack.div();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 24 and 12" ;
stack.push(24);
stack.push(12);
std::cout << "\nThe quotient is " ;
stack.div();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 24, 12, and 3" ;
stack.push(24);
stack.push(12);
stack.push(3);
std::cout << "\nThe sum is " ;
stack.addAll();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 44, 47, and 1" ;
stack.push(44);
stack.push(47);
stack.push(1);
std::cout << "\nThe sum is " ;
stack.addAll();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 24, 12, and 3" ;
stack.push(24);
stack.push(12);
stack.push(3);
std::cout << "\nThe product is " ;
stack.multAll();
stack.pop(catchVar);
std::cout << catchVar;
std::cout << "\n\nPushing 18, 12, and 5" ;
stack.push(18);
stack.push(12);
stack.push(5);
std::cout << "\nThe product is " ;
stack.multAll();
stack.pop(catchVar);
std::cout << catchVar;
return 0;
}
NumStack.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#ifndef NUMSTACK_HPP_INCLUDED
#define NUMSTACK_HPP_INCLUDED
#include "stack.hpp"
template <class T> class NumStack
{
private :
T *stackArray; // Pointer to the stack array
T stackSize; // The stack size
T top; // Indicates the top of the stack
public :
// Constructor
NumStack(T);
// Copy constructor
NumStack(const NumStack &);
// Destructor
~NumStack();
// Stack operations
void push(T);
void pop(T &);
bool isFull() const ;
bool isEmpty() const ;
};
#endif // NUMSTACK_HPP_INCLUDED
Last edited on Mar 14, 2017 at 11:47pm UTC
Mar 15, 2017 at 8:47am UTC
If you want Stack to inherit from NumStack you should include NumStack.hpp in Stack.hpp (not the other way around).
But I'm not sure that is what you want. NumStack sounds like it should be the one that has the arithmetic operators add, sub, mult, etc. and Stack should be the regular stack that all other stacks inherit from.