locked
i cant remove the error...plz help

    Question

  • #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    using namespace std;
    class stack
    {
    private:
    {
    int element[10];
    int tos;
    }
    public:
        {
        stack(void);
        void push(int);
        int poop(void);
        int peep(void);
        }
    };
    stack::stack(void)
    {
        tos=0;
    }
    void stack::push(int temp)
    (
     if(tos==10)
         (
         cout<<"stack overflow occur"<<endl;
         )
     else
     (
     element[tos]=temp;
    tos++;
     )
    }
    int::pop(void)
    (
     if(tos==0)
     {
     cout<<"stack underflow"<<endl;
     }
     else
     {
     tos--;
     return element[tos];
     }
     }
     int stack::peep(void)
     {
         if(tos==0)
         {
         cout<<"stack underflow"<<endl;
         }
         else
         {
         int temp=element[--tos;
         toss++;
         }
         return temp;
     }


    int _tmain(int argc, _TCHAR* argv[])
    {
        stack s;
        s.push(10);
        s.push(20);
        s.push(30);
        cout<<s.pop();
        cout<<s.peep();
       
        s.push(40);
        cout<<s.peep();
        getch();
        return 0;
    }

    Friday, March 25, 2011 2:54 PM

Answers

  • You want the C++ developer forums, found here:

    http://social.msdn.microsoft.com/Forums/en-US/category/visualc

    However, I have attempted to correct all the typos in your code so that it will compile:

    //#include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    using namespace std;
    class stack
    {
    private:
    
    int element[10];
    int tos;
    
    public:
      
      stack(void);
      void push(int);
      int poop(void);
      int peep(void);
      
    };
    stack::stack(void)
    {
      tos=0;
    }
    void stack::push(int temp)
    {
     if(tos==10)
     {
       cout<<"stack overflow occur"<<endl;
     }
     else
     {
     element[tos]=temp;
    tos++;
     }
    }
    int stack::poop(void)
    {
     if(tos==0)
     {
     cout<<"stack underflow"<<endl;
     }
     else
     {
     tos--;
     return element[tos];
     }
     }
     int stack::peep(void)
     {
       if(tos==0)
       {
       cout<<"stack underflow"<<endl;
       }
       else
       {
       int temp=element[--tos];
       tos++;
       }
       return tos;
     }
    
    
    //int _tmain(int argc, _TCHAR* argv[])
    
    int main(int argc, char* argv[])
    {
      stack s;
      s.push(10);
      s.push(20);
      s.push(30);
      cout<<s.poop();
      cout<<s.peep();
      
      s.push(40);
      cout<<s.peep();
      getch();
      return 0;
    }
    
    
    
    
    • Marked as answer by fahad.rzwn Friday, March 25, 2011 4:27 PM
    Friday, March 25, 2011 3:27 PM

All replies

  • would help if you told us the error you're getting...?  Also this is a C# forum, not C++.

     


    James Michael Hare

    Blog: http://www.geekswithblogs.net/BlackRabbitCoder

    Twitter: @BlkRabbitCoder

    There are 10 kinds of people in the world: those who know binary and those who don't...


    Friday, March 25, 2011 3:03 PM
  • You want the C++ developer forums, found here:

    http://social.msdn.microsoft.com/Forums/en-US/category/visualc

    However, I have attempted to correct all the typos in your code so that it will compile:

    //#include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    using namespace std;
    class stack
    {
    private:
    
    int element[10];
    int tos;
    
    public:
      
      stack(void);
      void push(int);
      int poop(void);
      int peep(void);
      
    };
    stack::stack(void)
    {
      tos=0;
    }
    void stack::push(int temp)
    {
     if(tos==10)
     {
       cout<<"stack overflow occur"<<endl;
     }
     else
     {
     element[tos]=temp;
    tos++;
     }
    }
    int stack::poop(void)
    {
     if(tos==0)
     {
     cout<<"stack underflow"<<endl;
     }
     else
     {
     tos--;
     return element[tos];
     }
     }
     int stack::peep(void)
     {
       if(tos==0)
       {
       cout<<"stack underflow"<<endl;
       }
       else
       {
       int temp=element[--tos];
       tos++;
       }
       return tos;
     }
    
    
    //int _tmain(int argc, _TCHAR* argv[])
    
    int main(int argc, char* argv[])
    {
      stack s;
      s.push(10);
      s.push(20);
      s.push(30);
      cout<<s.poop();
      cout<<s.peep();
      
      s.push(40);
      cout<<s.peep();
      getch();
      return 0;
    }
    
    
    
    
    • Marked as answer by fahad.rzwn Friday, March 25, 2011 4:27 PM
    Friday, March 25, 2011 3:27 PM