Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class STACK
- {
- static int count; //new
- int num[5];
- int top;
- public:
- int push(int);
- void print();
- STACK();
- static int get_count(); //new
- };
- STACK::STACK(){
- count++; //new
- top=-1;
- }
- int STACK::count = 0; //new
- int STACK::push(int n){
- ++top;
- num[top]=n;
- return n;
- }
- void STACK::print(){
- cout<<"STACK is: ";
- for(int i=(top); i>=0; i--)
- cout<<num[i]<<" ";
- cout<<endl;
- }
- int STACK::get_count() {
- return count;
- }
- int main() {
- int n, val;
- int r=0;
- while (r<2) {
- STACK stk;
- cout<<"Enter quantity of numbers:"<<endl;
- cin>>n;
- for(int i=0; i<n; i++) {
- cout<<"Enter value to be pushed:"<<endl;
- cin>>val;
- stk.push(val);
- }
- stk.print();
- cout<<"----------------------"<<endl;
- r++;
- }
- cout << STACK::get_count() << endl; //new
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement