Advertisement
elektryk798

klasy_c++

Jan 5th, 2016
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class stos
  5. {
  6.     public:
  7.         void push(int element);
  8.         int pop();
  9.  
  10.     private:
  11.         int s[10];
  12.         int n=0;
  13. };
  14. void stos::push(int element)
  15. {
  16.     if (n<10)
  17.         s[n++]=element;
  18.     else
  19.         cout <<"Stos jest pelny";
  20. };
  21.  
  22. int stos::pop()
  23. {
  24.     if (n>0)
  25.         return s[--n];
  26.     cout <<"Stos jest pusty";
  27.     return 0;
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33.     stos *stoz;
  34.     stoz=new stos;
  35.     int co=0,ile=0;
  36.     char what='c';
  37.     while (what!='x')
  38.     {
  39.         cout <<"Co chcesz zrobic?"<<endl;
  40.         cin >>what;
  41.         switch (what)
  42.         {
  43.             case'a':
  44.                 ile++;
  45.                 cin>>co;
  46.                 stoz->push(co);
  47.             break;
  48.             case'b':
  49.                 stoz->pop();
  50.             break;
  51.             default:
  52.             break;
  53.         }
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement