Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This code has syntax errors i cant figure out what is wrong please fix the error

ID: 666785 • Letter: T

Question

This code has syntax errors i cant figure out what is wrong please fix the errors and repost.

below is the errors it gives me with the code below the error messages.

Thanks in advance.

line col File Message

15   8   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' is not a template

15   18   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' was not declared in this scope

15   41   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' is not a template

15   51   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' was not declared in this scope

18   19   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' does not name a type

19   2   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' does not name a type

23   18   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' is not a template

23   28   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' was not declared in this scope

28   4   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' does not name a type

29   25   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' is not a template

29   35   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' was not declared in this scope

30   4   C:UsersJonathanDocumentsmyStack.h   [Error] explicit instantiation of non-template type 'stackType'

32   17   C:UsersJonathanDocumentsmyStack.h   [Error] expected initializer before '<' token

37   17   C:UsersJonathanDocumentsmyStack.h   [Error] expected initializer before '<' token

42   17   C:UsersJonathanDocumentsmyStack.h   [Error] expected initializer before '<' token

47   16   C:UsersJonathanDocumentsmyStack.h   [Error] expected initializer before '<' token

58   16   C:UsersJonathanDocumentsmyStack.h   [Error] expected initializer before '<' token

64   16   C:UsersJonathanDocumentsmyStack.h   [Error] expected initializer before '<' token

72   2   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' is not a template

72   42   C:UsersJonathanDocumentsmyStack.h   [Error] explicit qualification in declaration of 'stackType stackType(int)'

C:UsersJonathanDocumentsmyStack.h   In function 'stackType stackType(int)':

79   4   C:UsersJonathanDocumentsmyStack.h   [Error] 'maxStackSize' was not declared in this scope

82   7   C:UsersJonathanDocumentsmyStack.h   [Error] 'maxStackSize' was not declared in this scope

84   6   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackTop' was not declared in this scope

85   6   C:UsersJonathanDocumentsmyStack.h   [Error] 'list' was not declared in this scope

85   23   C:UsersJonathanDocumentsmyStack.h   [Error] 'maxStackSize' was not declared in this scope

C:UsersJonathanDocumentsmyStack.h   At global scope:

89   3   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' does not name a type

95   21   C:UsersJonathanDocumentsmyStack.h   [Error] 'Type' was not declared in this scope

95   11   C:UsersJonathanDocumentsmyStack.h   [Error] template-id 'stackType< >' used as a declarator

95   11   C:UsersJonathanDocumentsmyStack.h   [Error] variable or field 'stackType' declared void

95   26   C:UsersJonathanDocumentsmyStack.h   [Error] expected ';' before '::' token

108   6   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' does not name a type

116   12   C:UsersJonathanDocumentsmyStack.h   [Error] 'stackType' does not name a type

My current Code

//Header file: myStack.h

#ifndef H_StackType
#define H_StackType

#include
#include


using namespace std;
template
class stackType
{
public:
   const stackType& operator=(const stackType&);
   void initializeStack();
   bool isEmptyStack() const;
   void push (const Type& newItem) ;
   Type top () const;
   void pop ();
   bool isFullStack() const;
   stackType(int stacksize = 100);
   stackType(const stackType& otherStack);
   ~stackType();
   private:
      int maxStackSize;
      int stackTop;
      Type * list;
      void copyStack(const stackType& otherStack);
   };
   template
   void stackType::initializeStack()
   {
      stackTop = 0;
}
   template
   bool stackType::isEmptyStack() const
   {
      return (stackTop == 0);
}
    template
    bool stackType::isFullStack() const
    {
       return (stackTop == maxStackSize);
}
   template
   void stackType::push (const Type& newItem)     
   {
       if (!isFullStack())
   {
       list[stackTop] =newItem;
       stackTop++;
   }
   else
       cout <<"Cannot add to a full stack." <    }//endpush
   template
   Type stackType::top()const
   {
       assert (stackTop != 0);
       return list [stackTop - 1];
   }//end top
   template
   void stackType::pop()
   {
       if (!isEmptyStack())
           stackTop--;
       else
           cout << "Cannot remove from an empty stack." < }//endpop
   template
   stackType::stackType(int stackSize)
   {
       if (stackSize <=0)
       {
          cout << "Size of the array to hold the stack must "
               << "be positive."<            cout << "Creating an array of size 100." <            maxStackSize = 100;
   }
   else
       maxStackSize =stackSize;
      
   stackTop = 0;
   list = new Type [maxStackSize];
   }//end constructor
  
   template
       stackType::~stackType()
   {
       delete [] list;
   }//end destructor
  
   template
   void stackType::copyStack(const stackType& otherStack)
   {
       delete [] list;
       maxStackSize = otherStack.maxStackSize;
           stackTop = otherStack.stackTop;
          
           list = new Type [maxStackSize];
          
           for (int j = 0; j < stackTop; j++)
               list[j] = otherStack.list[j];
   }//end copyStack
  
   template
   stackType::stackType(const stackType& otherStack)
   {
       list = nullptr;
      
       copyStack (otherStack);
   }
  
   template
   const stackType& stackType::operator=
                               (const stackType& otherStack)
   {
       if (this != &otherStack)
           copyStack (otherStack);
           return * this;
   } //end opertor=
   #endif

Explanation / Answer

// myStack.h

#ifndef H_StackType
#define H_StackType
#include <iostream>

using namespace std;
template <class Type>
class stackType
{
public:
const stackType& operator=(const stackType&);
void initializeStack();
bool isEmptyStack() const;
void push (const Type& newItem) ;
Type top () const;
void pop ();
bool isFullStack() const;
stackType(int stacksize = 100);
stackType(const stackType& otherStack);
~stackType();
private:
int maxStackSize;
int stackTop;
Type * list;
void copyStack(const stackType& otherStack);
};

#endif

// myStack.cpp

#include "myStack.h"
#include <iostream>
#include <assert.h>

template<class Type> void stackType<Type>::initializeStack(){
stackTop = 0;
}
template<class Type> bool stackType<Type>::isEmptyStack() const{
return (stackTop == 0);
}
template<class Type> bool stackType<Type>::isFullStack() const{
return (stackTop == maxStackSize);
}
template<class Type> void stackType<Type>::push (const Type& newItem) {
if (!isFullStack()){
list[stackTop] =newItem;
stackTop++;
}
else
cout <<"Cannot add to a full stack.";
}//endpush
template<class Type> Type stackType<Type>::top()const{
assert (stackTop != 0);
return list [stackTop - 1];
}//end top
template<class Type> void stackType<Type>::pop(){
if (!isEmptyStack())
stackTop--;
else
cout << "Cannot remove from an empty stack.";
}//endpop
template<class Type> stackType<Type>::stackType(int stackSize){
if (stackSize <=0){
cout << "Size of the array to hold the stack must " << "be positive.";
cout << "Creating an array of size 100.";
maxStackSize = 100;
}
else
maxStackSize =stackSize;
  
stackTop = 0;
list = new Type [maxStackSize];
}//end constructor
  
template<class Type>
stackType<Type>::~stackType()
{
delete [] list;
}//end destructor
  
template<class Type>
void stackType<Type>::copyStack(const stackType& otherStack)
{
delete [] list;
maxStackSize = otherStack.maxStackSize;
stackTop = otherStack.stackTop;
  
list = new Type [maxStackSize];
  
for (int j = 0; j < stackTop; j++)
list[j] = otherStack.list[j];
}//end copyStack
  
template<class Type>
stackType<Type>::stackType(const stackType& otherStack)
{
list = NULL;
  
copyStack (otherStack);
}
  
template<class Type>
const stackType<Type>& stackType<Type>::operator=(const stackType& otherStack)
{
if (this != &otherStack)
copyStack (otherStack);
return * this;
} //end opertor=


int main(){

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote