Thread: error trying to compile stack program

  1. #1
    Registered User
    Join Date
    Oct 2003

    error trying to compile stack program

    I am getting a error when I compile this. The error reads:
    24 C:\Dev-Cpp\stacks.cpp
    implicit declaration of function `int PrintStackUp(...)'
    27 C:\Dev-Cpp\stacks.cpp
    implicit declaration of function `int system(...)'

    //  File: stackao.h   Class, constant values, and type
    //  definitions for C++ static implementation of ADT stack
    //  This is the specification file for the class stack.
    #ifndef  STACKTYPE_H
    #define  STACKTYPE_H
    // application dependent size of stack
    const unsigned int MAX_NUM_ELS = 256;
    typedef  int el_t;      // type varies with application
    typedef int index_t;
    class stack
            stack();                            // stack constructor
            ~stack();                          //  stack deconstructor
            bool    StackIsEmpty(void);        // Is stack empty?        
            bool    StackIsFull(void);        // Is stack full?
            void    Push(el_t);                // push item
            void    Pop(el_t&);                //pop top item
            void    PrintStack(stack& s);      // prints all elements of stack
            void    Print2nd(stack& s);        // prints 2nd element in stack
            void    PrintBottom(stack& s);     // prints bottom element of stack
            void Palindrome(stack& s );        // deterimes if characters from a palindrome
            void    StackError(char*);        //error handler
            index_t top;                      //top index: -1 if empty
            el_t    el[MAX_NUM_ELS];         //container for elements
    //  File: stackao.cpp  Contents: C++ source code for static
    //  implementation of ADT stack.  This is the implementation file.
    #include "stackType.h"
    using namespace std;
    //Default constructor
    //Pre:  None
    //Post: The stack object is initialized to be empty
        top = -1;
    //Stack destructor
    //Pre: The stack has gone out of scope or an explicit call
    //     to ~stack has occurred.
    //Post: The stack is empty.
        top = -1;
    //Boolean function that returns TRUE if the stack is empty
    //Pre:  The stack has been initialized.
    //Post: The function returns TRUE if the stack is empty, 
    //      FALSE otherwise.
    bool stack::StackIsFull(void)
        return (top == -1 ? true : false);
    //Boolean function that returns TRUE if a stack is full
    //Pre:  The sack has been initialized.
    //Post:  The function has returned TRUE if the stack is full,
    //       FALSE otherwise.
    bool stack::StackIsFull(void)
        return (top ++ (MAX_NUM_ELS -1) ? true : false);
    //Function to push an element onto a non_full stack
    //Pre:  e is a data element of typr el_t.
    //      The stack is not full.
    //Post: If the stack was not full, e was placed on top of
    //      the stack; otherwise StackError was called.
    void stack::Push(el_t e)
        if ( StackIsFull())
            StackError("Stack is fulle\n");
            el[top] = e;
    //  Function to pop an element from a nonempty stack and
    //  store it in the refernced variable
    //  Pre:  The stack is  nonempty.
    //  Post: The top stack element has been removed and stored
    //        in e.  If the stack was empty, StackError was called.
    void stack::Pop(el_t& e)
        if (StackIsEmpty())
            StackError(" Stack is empty \n");
            e = el[top];
    //  Function to print an error message and abort the program
    //Pre:  An unrecoverable error occurred.
    //      ErrorMessage is an error message.
    //Post: ErrorMessage has been output and the program aborted.
    void stack::StackError( char* ErrorMessage)
        cerr<< ErrorMessage;
    // Function to print all elements in a stack and leave stack unchanged 
    // after printing
    //Pre: The stack is non empty
    void stack::PrintStack(stack& s)
        el-t e;
        stack temp;
        While (!s.StackIsEmpty())
    void stack::Print2nd(stack& s)
        el-t e1, e2;
    void stack::PrintBottom(stack& s )
        el_t e;
        stack temp;
    void stack::Palindrome(stack& s )
        stack u,u2;
        el_t ch, ch1;
        bool equal = true;
                While(!u2.StackIsEmpyt() && equal)
                       if (ch != ch1)
                           equal = false;
                     if (equal)
                                 cout<<"Not a Palindrome"<<endl;
    } //end of Palindrome Function
    // This is the user program.
    #include <iostream>
    //#include <stdlib.h>
    #include "stackType.h"
    int main()
      int i;
      char *subject = "Data Structures";
      stack s;
      cout<< "Characters as pushed onto the stack: ";
      i = 0;
      while (( subject[i] != '\0') && (!s.StackIsFull()))
        cout<< subject[i];
      cout<< "\nThe stack from the bottom to top:      ";
      return 0;

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    You are missing header files to be included. So the compiler thinks you are making a suggested declaration.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Did you copy and paste the code directly from your file? If you did, then you have a lot of typos that should be fixed to get rid of compiler errors. If not, then please ignore any of these suggestions that refer to a typo.

    Looking at your code, you have a couple functions inside your stack class - PrintStack, Print2nd, PrintBottom, and Palindrome that all take a stack as a parameter and work with that stack. I don't see any reason for those functions to be member functions with the way they are implemented. One solution is to keep them as member functions, but instead of having a parameter, just do the work on the "this" object. Another solution is to make those functions global or static.

    Your PrintStackUp error is because you don't have any functions called PrintStackUp. Did you change the name to PrintStack and forget to change it in the main code?

    Your system compile error is because you commented out the include of the header file that the system function can be found in. You should #include <cstdlib> to get rid of that error.

    Finally, you use some old and some new headers files in your program. You should be consistent, and you should consistently use the new headers. Everywhere you have <iostream.h>, change it to <iostream> and everywhere you have <stdlib.h>, change it to <cstdlib>.

    Good Luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help newbie compile program!
    By candysandra88 in forum C Programming
    Replies: 7
    Last Post: 12-13-2008, 10:27 PM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. C program compile but not doing the calculations
    By abs.emailverify in forum C Programming
    Replies: 8
    Last Post: 11-08-2006, 07:43 AM
  5. How To Embed Data In Program While Compile?
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2002, 10:14 AM