answersLogoWhite

0

//Program on Stack ADT Using Arrays

#include<iostream.h>

#include<conio.h>

#define maxSize 10

#include<stdlib.h>

class stack

{

public:

stack(); // constructor call the display function

void pop(); //used to pop the value as per user demand

void push(); //used for push the value as per user demand

int empty(); //used to check the stack

int full(); //used to check the stack whether it is full as max limit is 80

void display(); //used to display menu for operations

void stackDisplay(); //used to display whole stack items

void operation(); //used to enter the user choice

private:

int top;

int item[maxSize];

};

stack::stack()

{

top = 0;

display();

}

void stack :: display()

{

cout << "STACK MAIN MENU GIVEN BELOW" << endl;

cout << "PRESS 1 FOR PUSH THE ITEM ON STACK" << endl;

cout << "PRESS 2 FOR POP THE ITEM ON STACK" << endl;

cout << "PRESS 3 FOR DISPLAY THE WHOLE STACK" << endl;

cout << "PRESS 4 FOR EXIT THE PROGRAM" << endl;

cout<<"ENTER YOUR CHOICE" << endl;

operation();

}

void stack :: operation()

{

int choice;

cin >> choice;

switch(choice)

{

case 1:

push();

break;

case 2:

pop();

break;

case 3:

stackDisplay();

break;

case 4:

exit(4);

default:

cout << "PLZ ENTER VALID NUMBER" <<endl;

operation();

}

}

int stack::empty()

{

if( top 0)

{

cout<<"THE STACK IS EMPTY UNDERFLOW" << endl;

cin.get();

}

else

{

char ch;

cout<<"AS THE LAST ELEMENT IN STACK IS "<<item[top] << endl;

top = top-1;

cout<<"WANT TO POP OUT ANOTHER ELEMENT y/n" << endl;

cin>>ch;

if(ch=='y')

pop();

cin.get();

}

cout<<"PRESS ENTER TO GO TO MAIN MENU " << endl;

cin.get();

clrscr();

display();

}

void stack::stackDisplay()

{

cout<<"THE ELEMENTS IN STACK IS"<<endl;

for(int i = 1;i <= top; i++)

{

cout << item[i] << endl;

}

cin.get();

cout<<"PRESS ENTER FOR MAIN MENU " << endl;

cin.get();

clrscr();

display();

}

void main()

{

clrscr();

gotoxy(15,10);

cout<<"WELCOME TO THE PROGRAM OF STACK MADE BY SAURABH " << endl;

gotoxy(15,11);

cout<<"________________________________________________" << endl;

cin.get();

clrscr();

stack obj;

getch();

}

BY. SAURABH (GNDU RC JAL CSE 2nd YEAR)

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Are arrays in C created on the stack or the heap?

That depends on where you define them. Arrays defined inside functions are declared on the stack (like other variables defined in functions). Arrays defined outside of any function, or using the static keyword inside a function are allocated in the static data area of the program. Other arrays may be allocated using malloc() (or "new" in C++); these are allocated on the heap.


Write a program to read your name and reverse it using arrays?

abdulrahman


Write a program to convert stack into queue using c language?

In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.


What is the purpose of using arrays in C language?

The purpose of using arrays in C is to store multiple values in one variable. Then you can make programs that use arrays like lists, printing values from multiple arrays into one line. It take memory in continues block then we can know memory location easily. We can retrieve data quickly.


Write a flowchart to find the sum of maximum and minimum o N natural numbers without using arrays?

huh?


What you 'll do using programming language?

Write computer-programs, I suppose.


What is the way by which you can make the user defined the size of the arrays?

By using the library function #define A[] we can define the size of arrays


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....


What should you write in?

Write in whatever you want so long as it's not someone else's book! You can write in a notebook, a journal, or just a legal pad or stack of blank paper. You can even write using your computer or tablet.


Write a program using iostreams to take as input two multi-dimensional arrays and print their sum as output Matrix Addition in Matrix format?

http://www.assignmentsclub.com/


When did the damage stop using the stack?

The damage from using the stack stopped when the company implemented new safety measures.


What is memory leakage in terms of arrays?

leakage in arrays occur when you declare an array with big size and using only very few bytes.