#include
#include
#include
#define MAXSIZE 50
int a[MAXSIZE];
int top=-1;
void main()
{
int choice;
void push();
int pop();
void display();
clrscr();
do
{
printf("\nYou can do following operations on stack\n");
printf("\n1. Push");
printf("\n2. Pop");
printf("\n3. Display");
printf("\n4. Exit");
printf("\n Enter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: break;
default: printf("\n Wrong input");
}
}while(choice!=4);
getch();
}
void push()
{
int value;
if(top==MAXSIZE-1)
{
printf("\n Stack is overflow");
}
else
{
printf("\n Enter the value which you want to insert");
scanf("%d",&value);
top++;
a[top]=value;
}
}
int pop()
{
int value;
if(top==-1)
{
printf("\nStack is underflow");
return(0);
}
else
{
value=a[top];
top--;
}
return value;
}
void display()
{
int i;
if(top==-1)
{
printf("\n Stack is underflow");
}
else
{
for(i=top;i>=0;i--)
{
printf("\n%d",a[i]);
}
}
}
#include < stdio.h >
#include < conio.h >
#define MAX 10
int stack[MAX],top;
void main()
{
char ch;
int choice,item;
void display();
int pop();
void push(int);
clrscr();
top=-1;
do
{
printf("1.Insertion");
printf("\n2.Deletion");
printf("\n3.Display");
printf("\nEnter your choice(1-3):");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\nEnter the item to be inserted:");
scanf("%d",&item);
push(item);
display();
break;
case 2: item=pop();
printf("\nThe item deleted is %d",item);
display();
break;
case 3: display();
break;
default:printf("Wrong choice");
break;
}
printf("\nDo you want to continue(y/n):");
fflush(stdin);
scanf("%c",&ch);
}while(ch=='y' ch=='Y');
getch();
}
void push(int item)
{
if(top==MAX-1)
{
printf("Stack Overflow");
return;
}
top=top+1;
stack[top]=item;
}
int pop()
{
int t;
if(top==-1)
{
printf("Stack Underflow");
return -1;
}
t=stack[top];
top=top-1;
return t;
}
void display()
{
int i;
printf("\nThe Stack elements are:");
for(i=0;i < =top;i++)
printf("%5d",stack[i]);
}
Chat with our AI personalities
You can find the source code of the menu driven graphics program here: http://www.start2code.com/Cresources/menu-driven-graphics-program-c.html
Menu-driven simply means you execute the application's commands by selecting them from a menu, as opposed to command-driven whereby you enter (type) the commands manually.
Develop a menu driven proramming in C++ on Examination System ?
To write the algorithm for a menu-driven C program, start by defining a loop that displays the menu options to the user. Use a switch-case structure to handle user input, allowing each case to correspond to a different option. Inside each case, implement the functionality for that option, and include a break statement to exit the case. Finally, provide an exit option to terminate the program cleanly when the user selects it.
Menu-driven interfaces continue to be popular because they are easier to figure out and work with than command-line interfaces, with frequently cryptic and hard to recall commands and option selections.