CIS-255 Home Page: http://www.c-jump.com/bcc/c255c/c255syllabus.htm

Project 1/Part 1: Stack of integers


Description

The purpose of this assignment is to create a C++ class that implements a stack of integers.

Instructions

  1. Create a class IntStack to keep a stack of integers. The initial implementation of the stack should be as an array of fixed size of 100 integers.

  2. Write member function void reset() which will reset the stack, i.e. make it empty. Write member functions, push() and pop():

    
    class IntStack
    {
        //...
        void reset();
        void push( int n );
        int pop();
        //...
    };
    
    

    Make sure these routines maintain the integrity of the object under error conditions and signal such conditions by printing error messages to cerr.

  3. Overload push() to take in an array of integers and push them onto the stack:

    
    class IntStack
    {
        //...
        void push( int a[], size_t array_size );
        //...
    };
    
    

    Push a[0] first and then a[1] and so forth until array_size.

  4. Overload pop() to return n integers in an array:

    
    class IntStack
    {
        //...
        void pop( int a[], size_t n );
        //...
    };
    
    

    So if (n == 2),
    then
    (a[0] == top of stack),
    and
    (a[1] == next element on the stack).

  5. The effect of the following code should be to reverse the integers in arr:

    
        int arr[ 5 ] = { 1, 2, 3, 4, 5}; 
        IntStack st;
        st.push( arr, 5 );   
        st.pop( arr, 5 );
    
    
  6. Write member functions

    
    class IntStack
    {
        //...
        bool is_full();
        bool is_empty();
        //...
    };
    
    

    to return if the stack is full or not, and if the stack is empty or not.

  7. Write a global function

    
        void print_stack( IntStack* pstack );
    
    

    which will print the integers on the stack to cout. Print each integer on a seperate line. Make it a friend of IntStack class, so it can access the stack without popping any elements.

  8. How to Submit
    1. Save local copy of all source files in your program.

    2. Go to CIS-255 online website. You should have already received your login and password for this website. If not, then email me at

      and I will reply back with your access credentials.

    3. On the Main Menu, follow the link to Submit Homework, select Project 1/Part 1, and upload your source files.

      • Note: the system will display an 8-digit confirmation number once the file is successfully uploaded. You can save the confirmation number for your own records, but this is not a required step and no further action is needed on your part.

    4. Let me know if you are experiencing any problems, otherwise -- good luck on your first assignment!