Answer to Question #268663 in C++ for zain

Question #268663

ABS assignment

your mother asked you to stack up all your books in a book rack. A book rack can not hold more than 25 books. so create an ADT called book that stores the name, author, and the number of pages in a book. use this ADT to create an array based stack called "bookrack" of books. your implementation must be abstraction based containing:

1. Accessors

2. Mutators,

3. push

4. pop

5. peek

6. smart_search

7. display stack

8. isEmpty

9. isFull

10. delete


remember that you are implementing a stack which is a variation of a linked list in which operations can be performed only at the head. So for operations such as search, display and delete, you will have to be very careful about 1. conform to the rules of the stack i.e work with the top item only, 2. maintain the order of the stack.


1
Expert's answer
2021-11-19T14:43:09-0500


#include<stdio.h>
#include<iostream>
using namespace std;


class Stack
{
int top;
int arr[25];
string name;
int num;
string author;


public:
    Stack()
{
       top=-1;
}


    void push();
    void smart_search();
    //int delete();
    void pop();
    void view();
    int isEmpty();
    int isFull();
};


int Stack::isEmpty()
{
    return (top==(-1)?1:0);
}


int Stack::isFull()
{
    return ( top == 50 ? 1 : 0 );
}
void Stack::smart_search(){
	
}


void Stack::push()
{
    if(isFull())
    {
        cout<<"\nSTACK IS FULL OVERFLOW ";
    }
    else
    {
        int x;
        cout<<"\nEnter an element :: ";
        cin>>x;
        ++top;
        arr[top]=x;
        cout<<"\nInsertion successful.\n";
    }
}


void Stack::pop()
{
    int num;
    if(isEmpty())
    {
            cout<<"\n STACK IS EMPTY [ UNDERFLOW ] ";
    }
    else
    {
    cout<<"\nDeleted item is : "<<arr[top]<<"\n";
    top--;
    }
}


void Stack::view()
{
    if(isEmpty())
    {
            cout<<"\n STACK IS EMPTY [ UNDERFLOW ] ";
    }
    else
    {
    cout<<"\nSTACK :\n";
    for(int i=top;i>=0;i--)
    {
            cout<<arr[i]<<"\n";
    }
    }
}




int main()
{
    Stack s;
    int option;
    option=0;
    


    while(option!=4)
    {
        cout<<"\n1. Push\n";
        cout<<"2. Pop\n";
        cout<<"3. Display\n";
        cout<<"4. Quit\n";
        cout<<"\nEnter your Choice :: ";
        cin>>option;


        if(option==1){
                s.push();}


        else if(option==2){
                s.pop();
                }


        else if(option==3){
                s.view();
              }


        else if(option==4){
                cout<<"\nPress any key .. ";
               }


        else{
                cout<<"\nWrong Choice!! \n";
                }
        }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS