Sponsored
Recent Updates
  • cs301 assignment solutio 2020
    #include<iostream>
    using namespace std;
    class MYBooks
    {
    private :
    int current;
    int books;
    int size;
    int *stack;
    public :
    MYBooks(int s, int b)
    {size=s;
    stack= new int[size];
    books=b;
    current=-1;
    }
    void push(int x)
    {
    // -1 +1=0
    stack[++current]=x;
    }
    int pop()
    {
    return stack[current--];
    }
    int top()
    {
    return stack[current];
    }
    int isEmpty()
    {
    return (current==-1);
    }
    int isFull()
    {
    //5 4
    return (current==size-1);
    }

    };

    main()
    {

    int s, b, id;
    int s_books=0, h_books=0, o_books=0;
    cout<<"set the size of stack : ";
    cin>>s;
    cout<<endl;
    cout<<"Number of books you want to add in stack : ";
    cin>>b;
    MYBooks book(s,b);
    //b =5
    for(int i=0; i<b; i++)
    {
    if(!book.isFull())
    {
    cout<<endl;
    cout<<"Enter book id number that you want to insert into stack :";
    cin>>id;
    book.push(id);
    }
    }

    for(int i=0; i<b; i++)
    {
    if(!book.isEmpty())
    {
    int idd=book.pop();

    if(idd%8==0)
    {
    s_books++;
    }
    else if (idd%5==0)
    {
    h_books++;
    }
    else
    {
    o_books++;
    }
    }
    }
    if(b>0)
    {
    cout<<endl;
    cout<<"Total Software Books : "<<s_books;
    cout<<endl;
    cout<<"Total Hardware Books : "<<h_books;
    cout<<endl;
    cout<<"Total Other Books : "<<o_books;
    }
    else
    {
    cout<<endl;
    cout<<"Books not found";
    }
    }
    cs301 assignment solutio 2020 #include<iostream> using namespace std; class MYBooks { private : int current; int books; int size; int *stack; public : MYBooks(int s, int b) {size=s; stack= new int[size]; books=b; current=-1; } void push(int x) { // -1 +1=0 stack[++current]=x; } int pop() { return stack[current--]; } int top() { return stack[current]; } int isEmpty() { return (current==-1); } int isFull() { //5 4 return (current==size-1); } }; main() { int s, b, id; int s_books=0, h_books=0, o_books=0; cout<<"set the size of stack : "; cin>>s; cout<<endl; cout<<"Number of books you want to add in stack : "; cin>>b; MYBooks book(s,b); //b =5 for(int i=0; i<b; i++) { if(!book.isFull()) { cout<<endl; cout<<"Enter book id number that you want to insert into stack :"; cin>>id; book.push(id); } } for(int i=0; i<b; i++) { if(!book.isEmpty()) { int idd=book.pop(); if(idd%8==0) { s_books++; } else if (idd%5==0) { h_books++; } else { o_books++; } } } if(b>0) { cout<<endl; cout<<"Total Software Books : "<<s_books; cout<<endl; cout<<"Total Hardware Books : "<<h_books; cout<<endl; cout<<"Total Other Books : "<<o_books; } else { cout<<endl; cout<<"Books not found"; } }
    Love
    1
    0 Comments 0 Shares 15 Views 0 Reviews
  • #every end has a new start.
    #every end has a new start.
    0 Comments 0 Shares 12 Views 0 Reviews
  • Like
    1
    0 Comments 0 Shares 11 Views 0 Reviews
More Stories