Here is the complete corrected code:
stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
main.cpp
#include "stdafx.h"
#include <iostream>
#include "SeqStack.h"
#define maxsize_seq 50
#define end_tail 10000
using namespace std;
int main(int argc, char* argv[])
{
SeqStack<int> SeqStack1(maxsize_seq);
int Push_Numbers_Int, Pop_Size, Pop_Number, Stack_Size;
cout<<"Push the Stack! Stopped by 10000!"<<endl;
while (1)
{
cin>>Push_Numbers_Int;
if (Push_Numbers_Int!=end_tail)
{
SeqStack1.Push(Push_Numbers_Int);
}
else
break;
}
cout<<"Pop the Stack! Input the number of Poping out!"<<endl;
cin>>Pop_Size;
for (int i=0;i<Pop_Size;i++)
{
if (SeqStack1.Pop(Pop_Number))
{
cout<<Pop_Number<<endl;
}
else
break;
}
cout<<"Head of the Stack:"<<endl;
if (SeqStack1.Get_Top(Pop_Number))
{
cout<<Pop_Number<<endl;
}
else
cout<<"Error!"<<endl;
cout<<"The size of the Stack is:"<<endl;
Stack_Size=SeqStack1.Get_Size();
cout<<Stack_Size;
return 0;
}
Stack.h
#if !defined(AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_)
#define AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
template<class T>
class Stack
{
public:
virtual void Push(const T &x)=0;
virtual bool Pop(T &x)=0;
virtual bool Get_Top(T &x) const=0;
virtual bool Is_Empty() const=0;
virtual bool Is_Full() const=0;
virtual int Get_Size() const=0;
};
#endif // !defined(AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_)
Stack.cpp
#include "stdafx.h"
#include "Stack.h"
SeqStack.h
#if !defined(AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_)
#define AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <assert.h>
#include "Stack.h"
#define Stackincreament 20
template<class T>
class SeqStack : public Stack<T>
{
public:
SeqStack(int len);
virtual void Push(const T &x);
virtual bool Pop(T &x);
virtual bool Get_Top(T &x) const;
virtual bool Is_Empty() const;
virtual bool Is_Full() const;
virtual int Get_Size() const;
virtual ~SeqStack();
private:
T *elements;
int top;
int maxsize;
void Overflow_Process();
};
template<class T>
SeqStack<T>::SeqStack(int len)
{
top=-1;
maxsize=len;
T *elements=new T[maxsize];
assert(elements!=NULL);
}
template<class T>
void SeqStack<T>::Overflow_Process()
{
T *NewArray=new T[maxsize+Stackincreament];
if (NewArray==NULL)
{
cout<<"Error!!!"<<endl;
exit(1);
}
maxsize=maxsize+Stackincreament;
delete []elements;
elements=NewArray;
}
template<class T>
void SeqStack<T>::Push(const T &x)
{
if (Is_Full()==true)
{
Overflow_Process();
}
elements[++top]=x;
}
template<class T>
bool SeqStack<T>::Pop(T &x)
{
if (Is_Empty()==true)
{
return false;
}
x=elements[top--];
return true;
}
template<class T>
bool SeqStack<T>::Get_Top(T &x) const
{
if (Is_Empty()==true)
{
cerr<<"Error!!!"<<endl;
return false;
}
x=elements[top];
return true;
}
template<class T>
int SeqStack<T>::Get_Size() const
{
int Size_SeqStack;
Size_SeqStack=top+1;
return Size_SeqStack;
}
template<class T>
bool SeqStack<T>::Is_Full() const
{
if (top==maxsize-1)
{
return true;
}
else
return false;
}
template<class T>
bool SeqStack<T>::Is_Empty() const
{
if (top!=maxsize-1)
{
return true;
}
else
return false;
}
template<class T>
SeqStack<T>::~SeqStack()
{
delete []elements;
}
#endif // !defined(AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_)
SeqStack.cpp
#include "stdafx.h"
#include "SeqStack.h"