|29|error: expected unqualified-id before ‘{’ token|
|27|error: new types may not be defined in a return type|
|27|note: (perhaps a semicolon is missing after the definition of ‘DynStack<T>::StackNode’)|
46|error: ‘StackNode’ does not name a type|
||In member function ‘DynStack<T>::StackNode DynStack<T>::StackNode(T, DynStack<T>::StackNode*)’:|
|40|error: ‘value’ was not declared in this scope|
||In constructor ‘DynStack<T>::DynStack()’:|
|51|error: ‘top’ was not declared in this scope|
||In member function ‘void DynStack<T>::push(T)’:|
|67|error: ‘top’ was not declared in this scope|
|67|error: expected type-specifier before ‘StackNode’|
|67|error: expected ‘;’ before ‘StackNode’|
||In member function ‘void DynStack<T>::pop(T&)’:|
|74|error: ‘temp’ was not declared in this scope|
|77|error: expected ‘;’ before ‘if’|
|82|error: ‘else’ without a previous ‘if’|
|87|error: ‘top’ was not declared in this scope|
|96|error: invalid declarator before ‘:’ token|
|144|error: expected unqualified-id before ‘;’ token|
|145|error: ‘T’ was not declared in this scope|
|145|error: template argument 1 is invalid|
||In function ‘int main()’:|
|229|error: request for member ‘enqueue’ in ‘DynStack’, which is of non-class type ‘float’|
|240|error: type ‘float’ argument given to ‘delete’, expected pointer|
|251|error: request for member ‘enqueue’ in ‘DynStack’, which is of non-class type ‘float’|
|256|error: ‘cout’ does not name a type|
|258|error: expected unqualified-id before ‘while’|
|266|error: ‘cout’ does not name a type|
|267|error: expected constructor, destructor, or type conversion before ‘(’ token|
|268|error: expected unqualified-id before ‘return’|
|269|error: expected declaration before ‘}’ token|
||=== Build failed: 25 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|






#include <iostream>
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;

template <class T>
//
//  BELOW TO DECLARE A CLASS NAMED DynStack.
class DynStack
{
private:
   //
   // BELOW TO DECLARE A struct NAMED StackNode.
   struct StackNode
   {
   {
   T value;
    StackNode *next;
   };
    T value;
    StackNode *next;
}

    // Constructor
    StackNode(T val, StackNode *nextP)
    {
      value = val;
      //
      // BELOW TO ASSIGN nextP TO THE StackNode POINTER.
      StackNode = nextP;

   };
   StackNode *top;
public:
   DynStack()
   {
      // BELOW TO ASSIGN NULL TO BE AT THE TOP OF THE STACK.
      top = NULL;
   }

   void push(T);
   //
   // BELOW TO DECLARE FUNCTION PROTOTYPE pop.
   // THE FUNCTION DOES NOT RETURN DATA.
   // THE FUNCTIONS RECEIVES THE CLASS TEMPLATE VARIABLE "T" PASSED BY REFERENCE.
   void pop(T &);
   bool isEmpty();
};
//
// define the "push" function
template <class T>
void DynStack<T>::push(T val)
{
    top = new  StackNode(val, top);
}
//
// define "pop" function
template <class T>
void DynStack<T>::pop(T &val)
{
    StackNode *temp
    //
    // TO DETERMINE IF THE STACK IS EMPTY.
    if(isEmpty())
    {
        cout << "The stack is empty.\n";
        return;
    }
    else        // Pop value off top of stack
    {
        //
        // TO ASSIGN THE VARIABLE val TO CONTAIN
        // THE VALUE AT THE TOP OF THE STACK.
        val = top;
        temp = top;
        top = top->next;
        delete temp;
    }
}
//
// define "isEmpty()" function
template <class T>
bool DynStack<T>:isEmpty()
{
    if (!top)
        return true;
    else return false;
}
//
// ************* End of stack structure
//
// ************* Beginning of queue structure **********
//
template <class T>
class Dynque
{
private:
    // Node to hold queue elements
    struct QueueNode
    {
      T value;
      QueueNode *next;
      QueueNode(T val, QueueNode *nextp = NULL)
      {
         value = val; next = nextp;
      }
   };
   QueueNode *front;
   QueueNode *rear;
   int numItems;
public:
   Dynque();
   ~Dynque();
   void enqueue(T);
   void dequeue(T &);
   bool isEmpty();
   bool isFull();
   void clear();
};
//
// define constructor
template <class T>
Dynque<T>::Dynque()
{
   front = NULL;
   rear = NULL;
   numItems = 0;
}
//
// define destructor
template <class T>;
Dynque<T>::~Dynque()
{
   clear();
}
//
// define "enqueue" function
template <class T>
void Dynque<T>::enqueue(T val)
{
   if (isEmpty())
    front = rear = new QueueNode(val);
   else
   {
    rear->next =  new QueueNode(val);
    //
    // BELOW TO ASSIGN THE NEXT VALUE AT THE REAR TO NEW REAR.
   rear = rear ->next;
   }
   numItems++;
}
//
// define "dequeue" function
template <class T>
void Dynque<T>::dequeue(T &val)
{
    QueueNode *temp;
    //
    if (isEmpty())
    {
         cout << "The queue is empty.\n";
         exit(1);
      }
    else
    {
       val = front->value;
       temp = front;
       //
       // BELOW TO ASSIGN THE NEXT VALUE AT THE FRONT TO NEW FRONT.
       front = front ->next;
       delete temp;
       numItems--;
     }
}
//
// define "isEmpty" function
template <class T>
bool Dynque<T>::isEmpty()
{
   if (numItems)
     return false;
   else
     return true;
}
//
// define "clear" function
template <class T>
void Dynque<T>::clear()
{
   T value;        // Dummy variable for dequeue
   while(!isEmpty())
    dequeue(value);
}
// ********* End of queue structure *************
//
int main()
{
    // BELOW TO DECLARE A STACK NAMED DynStack TO CONTAIN
    // float VALUES.
    float DynStack;
    Dynque<float> queue;
    float catchVar;
    float numbers = 0.0;
    int count = 1;
    // Demonstrate the stack
    //
    cout << "USING A DYNAMIC STACK.\n\n";
    //
    cout << "Input three numbers in a stack.\n\n";
    while (count <= 3);
    {
          cout << "Enter a number " << count << ": ";
          cin >> numbers;
          //
          // BELOW TO ADD THE NUMBER ENTERED TO THE STACK.
          DynStack.enqueue(numbers);
          count = count + 1;
          }
     //
     cout << "\nRemoving the numbers from the stack.\n\n";
     count = 1;
    //
    while(count <=3)
    {
        //
        //  BELOW TO REMOVE A NUMBER FROM THE STACK.
        delete numbers;
        cout << catchVar << endl;
        count = count + 1;
}
     //
     cout << "\n\nUSING A DYNAMIC QUEUE.\n\n";
    //
    count = 1;

          //
          // BELOW TO ADD THE NUMBER ENTERED TO THE QUEUE.
          DynStack.enqueue(numbers);
          count = count + 1;
          }

    //
     cout << "\nRemoving the numbers from the queue.\n\n";
   //
    while (!queue.isEmpty())
    {
        // BELOW TO REMOVE A NUMBER FROM THE QUEUE.
      DynStack.dequeue(numbers);
        //
        // BELOW TO OUTPUT THE NUMBER THAT WAS REMOVED.
      cout<< deque(numbers);
     }
    cout << "\n\n";
    system("pause");
    return 0;
}

I get 27 errors. I'm not sure if I'm doing it right.

Umm, errors mean you didn't do something right. Most of your errors appear to be syntax related. for instance you have:

bool DynStack<T>:isEmpty()

Instead of

bool DynStack<T>::isEmpty()

As you fix each error do a new build, since the way compilers read source code one syntax error can multiply and throw the expected syntax out for other statements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.