Need Help (Stack)

+1 Homayoun Azizi · October 28, 2015
 HI . I am New in c++ programming and I need some help to complete my assignment. I have no idea how to begin and what to do . Please somebody explain it to me . I am not asking for complete solution just some hint. Thanks for your help in advanced.

the head file stack.h describes the data type STACK as follows: 

class STACK{
    int  *const  elems;   
    const  int   max;      
    int   top;                                             
      STACK(int m);                 
      STACK(const STACK&s);                              
      virtual int  size ( ) const;                                   
      virtual operator int ( ) const;                           
      virtual int operator[ ] (int x) const;     
      virtual STACK& operator<<(int e);    
      virtual STACK& operator>>(int &e);  
      virtual STACK& operator=(const STACK&s); 
      virtual void print( ) const;                               
      virtual ~STACK( );                                                         


Post a Reply


Oldest  Newest  Rating
0 c student · November 2, 2015
how well do you know stacks?
0 Homayoun Azizi · November 1, 2015
Thanks .
He just Gave us this on paper and ask us to write the functions on  Stack.cpp file.
0 Homayoun Azizi · November 1, 2015
Hi . I will send you the assignment to see . Thats all he gave us ....

1.    Problem description
An integer stack is a LIFO (last in, first out) data type that serves as a collection of integer elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the last element that was added. The data type STACK can be implemented with a linear data structure by using an integer pointer which is allocated a piece of memory that can store at most max elements. The head file stack.h describes the data type STACK as follows:

class STACK{
    int  *const  elems;      //memory allocated to store elements
    const  int   max;         //maximum number of elements the stack can contain
    int   top;                      //top indicator or number of elements in current stack
    STACK(int m);                                      //create a stack which can store at most m elements
    STACK(const STACK &s);                    //deep-copy constructor of stack s
    virtual int  size ( ) const;                        //get maximum number max
    virtual operator int ( ) const;                //get top indicator top
    virtual int operator[ ] (int x) const;      //get element at location x in the stack
    virtual STACK& operator<<(int e);     //push e into the stack
    virtual STACK& operator>>(int &e);  //pop an element to e from the stack
    virtual STACK& operator=(const STACK&s);           //deep-copy assignment of stacks
    virtual void print( ) const;                                 //print out the stack
    virtual ~STACK( );                                                          //destroy the stack
0 Homayoun Azizi · November 1, 2015
0 Scott Walker · October 28, 2015
Could you explain your assignment?
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator