يوقوم هذا بإدخال ارقام أو حروف
عند التنفيذ يظهر لي مشكلة لا اعرف سببها مع العلم ان كتابة البرنامج صحيحة ومنقولة من المدرس نفسة ...
stackarr.h + Implemention + test.cpp
#ifdef stackarr.h
#define stackarr.h
#include<iostream.h>
#include <stdexcept>
using namespace std;
const int defMaxStackSize = 10; // Default maximum stack size
template < class DT >
class Stack
{
public:
// Constructor
Stack ( int maxNumber = defMaxStackSize ) throw ( bad_alloc );
// Destructor
~Stack ();
// Stack manipulation operations
void push ( const DT &newDataItem ) // Push data item
throw ( logic_error );
DT pop () // Pop data item
throw ( logic_error );
void clear (); // Clear stack
// Stack status operations
bool isEmpty () const; // Stack is empty
bool isFull () const; // Stack is full
// Output the stack structure -- used in testing/debugging
void showStructure () const;
private:
// Data members
int maxSize, // Maximum number of data items in the stack
top; // Index of the top data item
DT *dataItems; // Array containing the stack data items
};
//**********************************************
template < class DT >
Stack<DT>::Stack ( int maxNumber ) throw ( bad_alloc )
{
top = -1;
maxSize = 0;
dataItems = new DT [ maxNumber ];
}
template < class DT >
Stack<DT>::~Stack ()
{
delete [ ] dataItems;
}
template < class DT >
void Stack<DT>::push ( const DT &newDataItem )
throw ( logic_error )
{
if ( ! isFull () )
{
top++;
dataItems [ top ] = newDataItem;
}
else
cout <<" Stack is Full" << endl;
}
template < class DT >
DT Stack<DT>::pop () throw ( logic_error )
{
DT item;
if ( ! isEmpty () )
{
item = dataItems [ top ];
top--;
return item;
}
else
cout <<"Stack is Empty " << endl;
}
template < class DT >
void Stack<DT>::clear ()
{
for ( int i = 0; i < defMaxStackSize; i++ )
dataItems [ i ] = 0;
top = -1;
maxSize = 0;
}
template < class DT >
bool Stack<DT>::isFull () const
{
return ( top == ( defMaxStackSize - 1 ) );
}
template < class DT >
bool Stack<DT>::isEmpty () const
{
return ( top == -1 );
}
template < class DT >
void Stack<DT>:: showStructure () const
// Array implementation. Outputs the data items in a stack. If the
// stack is empty, outputs "Empty stack". This operation is intended
// for testing and debugging purposes only.
{
int j; // Loop counter
if ( top == -1 )
cout << "Empty stack" << endl;
else
{
cout << "top = " << top << endl;
for ( j = 0; j < maxSize; j++ )
cout << j << "\t";
cout << endl;
for ( j = 0; j <= top ; j++ )
cout << dataItems[j] << "\t";
cout << endl;
}
}
#endifوالمشكلة على ما اعتقد تكم في ملف main >> test.cpp
