Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class STACK
  5. {
  6.     static int count; //new
  7.     int num[5];
  8.     int top;
  9. public:
  10.     int push(int);
  11.     void print();
  12.     STACK();
  13.     static int get_count(); //new
  14. };
  15. STACK::STACK(){
  16.     count++; //new
  17.     top=-1;
  18. }
  19.  
  20. int STACK::count = 0; //new
  21.  
  22.  
  23. int STACK::push(int n){
  24.     ++top;
  25.     num[top]=n;
  26.     return n;
  27. }
  28.  
  29. void STACK::print(){
  30.     cout<<"STACK is: ";
  31.     for(int i=(top); i>=0; i--)
  32.         cout<<num[i]<<" ";
  33.     cout<<endl;
  34. }
  35.  
  36.  
  37. int STACK::get_count() {
  38.     return count;
  39. }
  40.  
  41. int main() {
  42.     int n, val;
  43.     int r=0;
  44.     while (r<2) {
  45.         STACK stk;
  46.         cout<<"Enter quantity of numbers:"<<endl;
  47.         cin>>n;
  48.         for(int i=0; i<n; i++) {
  49.             cout<<"Enter value to be pushed:"<<endl;
  50.             cin>>val;
  51.             stk.push(val);
  52.         }
  53.         stk.print();
  54.         cout<<"----------------------"<<endl;
  55.         r++;
  56.     }
  57.    
  58.     cout << STACK::get_count() << endl; //new
  59.    
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement