Navigation

    Cyberian
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Pro Blog
    • Users
    • Groups
    • Unsolved
    • Solved
    1. Home
    2. Eshaal Khan
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 1
    • Best 0
    • Groups 0

    Eshaal Khan

    @Eshaal Khan

    0
    Reputation
    1
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Eshaal Khan Unfollow Follow

    Latest posts made by Eshaal Khan

    • RE: CS301 Assignment 1 Solution and Discussion
      /* Implementation of stack using array */
      
      #include <iostream>
      #include <conio.h>
      using namespace std;
      
      class  Stack  /* the Stack class */ 
      {
          public:
              Stack() { 
      			size = 0; 
      			current = -1;
      	 	} //constructor
      			
              int pop() { 
      			return data[current--];
      			}    	// The pop function    
              
      		void push(int x) {
      			data[++current] = x;
      			//cout<<A[current];
      		} // The push function
              
      		int top(){ 
      			return data[current];
      		}      	// The top function
              
      		int isEmpty(){
      			return ( current == -1 );
      		} // Will return true when stack is empty
              
      		int isFull(){ 
      			return ( current == size-1);
      		} // Will return true when stack is full	
      		void setStackSize(int s){
      			size = s;
      			data = new int[size];
      		}
      
           private:
             int   object;  				// The data element
             int   current; 				// Index of the array
             int   size;    				// max size of the array
             int   *data;    				// Array of 10 elements    
      };	
      
      // Main method
      int main()
      {
          int t_books= 0, size = 0;
      	int scount = 0, hcount=0, ocount=0; // For counting of book i.e software , hardware and other books. 
              
      	Stack stack; 				// creating a stack object
          
          cout<<"Set size of stack: ";
          cin>>size;
          stack.setStackSize(size);
          
          
          cout<<"How many Books you want to add into stack: ";
          cin>>t_books;
          
          int book;
          for(int i = 0; i < t_books; i++)
          {
          	cout <<"\nEnter Book identity number that you want to insert into stack: ";
              cin>>book;
              
               if(!stack.isFull()) {		// checking stack is full or not
               	
               	stack.push(book);     	// push the element at the top    
              }
               else{
                   cout<<"\n Unable to insert "<<book<<". Stack is full, can't insert more";
                   break;
               }    
          }
      
          // pop the elements at the stack
          
          int current = 0;
          
          for (int i = 0; i < t_books; i++)
          {
          	
              if(!stack.isEmpty()) {		// checking stack is empty or not
                        current = stack.pop();
                        if(current % 8 == 0){
                        	scount++;
                        	
                        }
                        else if(current % 5 == 0){
                        	hcount++;
                        }
                        else {
                        	ocount++;
                        }
      			}
                      
              else {
              
                        cout <<"\nStack is empty, sorry can't pop more";
                         getch();
                         break;
              }
          }
          
          if(scount == 0 && hcount==0 && ocount==0){
              cout<<"\nBooks not found\n";
          }
          else {    
              cout<<"\n\nTotal Software Book/Books = "<<scount;    
              cout<<"\n\nTotal Hardware Book/Books = "<<hcount;    
      		cout<<"\n\nTotal Other Book/Books = "<<ocount;    
      		
          }    
           getch();
      }
      
      
      
      posted in CS301 – Data Structures
      Eshaal Khan
      Eshaal Khan