Graphical representation of Stack


Published on

Published in: Education
1 Comment
1 Like
  • it gives graphic error(file not found EGA.VGA) what should i do . i run this program on turboc++
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Graphical representation of Stack

  1. 1. MINI PROJECT CSE205TOPIC:Graphical reperesntation of stackSubmitted by:SANJAY KUMAR CHAKRAVARTIROLL:A28SEC:K2R13 Submitted to: Miss.Deepika sukhija Dept. cse Lpu,phagwara
  2. 2. AcknowledgementApart from the efforts of me, the success of this project depends largely on theencouragement and guidelines of many others. I take this opportunity to expressmy gratitude to the people who have been instrumental in the successfulcompletion of this project.I would like to show my greatest appreciation to Miss. Deepika sukhija I can’t saythank you enough for his tremendous support and help. I feel motivated andencouraged every time I attend his meeting. Without his encouragement andguidance this project would not have materialized.The guidance and support received from all the team members including Mr.sanjeev kumar and Mr. Abhay kumar who contributed and are contributing to thisproject, was vital for the success of the project. I am grateful for their constantsupport and help.
  3. 3. CONTENTTOPIC PAGE NO. .1 ABSTRACT-------------------------------------------------- 042. INTRODUCTION------------------------------------------- 053.SOURCE CODE---------------------------------------------- 06-184.OUTPUTS------------------------------------------------------ 19-214.REFRENCES-------------------------------------------------- 22
  4. 4. ABSTRACTThis project was very important for me. In this project I haveshow a graphical view of stacks for better understanding. It willgives you many features as listed below: 1. Graphical view 2. Simple programming language 3. Source code contains comments line where needed 4. A best approach with graphics programming
  5. 5. INTRODUCTIONThe Stack is a Memory Area where you can store data there and can getback them again. In computer science, a stack is a last in, first out(LIFO) abstract data type and linear data structure . A stack can haveany abstract data type as an element , but is characterized by twofundamental operations, called PUSH and POP. The push operation addsa new item to the top of the stack, or initializes the stack if it is empty. Ifthe stack is full and does not contain enough space to accept the givenitem, the stack is then considered to be in an overflow state. The popoperation removes an item from the top of the stack. A pop eitherreveals previously concealed items, or results in an empty stack, but ifthe stack is empty then it goes into underflow state (It means no itemsare present in stack to be removed). A stack is a restricted datastructure , because only a small number of operations are performed onit. The nature of the pop and push operations also means that stackelements have a natural order. Elements are removed from the stack inthe reverse order to the order of their addition: therefore, the lowerelements are those that have been on the stack the longest.
  6. 6. Source code#include<iostream.h> //for cin, cout#include<conio.h> //for getche()#include<ctype.h> //for tolower() function#include<stdlib.h> //for itoa()#include<GRAPHICS.H> //to load graphics driver#include<dos.h> //for delay() function/*_________________________________________________________________________*//*_________________________________________________________________________*///These Functions prototypes are, for stack col=60 , row = 417 ,n ,x=60 , y=417 ,size=10,arr[10]={12,56,23,46,32,89,11,99,12,66} , count = 0, top = 0; //GlobalVariableschar string[45];void push( );void pop( );void stack();
  7. 7. void loadgraph();void main(){clrscr();char ch;struct fillsettingstype fillinfo;loadgraph();setbkcolor(0);setcolor(2);do{rectangle(2,2,620,410);rectangle(4,4,618,408);line(0,30,620,30);getfillsettings(&fillinfo);line(0,32,620,32);line(100,32,100,410);moveto(180,15);outtext("SANJAY KUMAR CHAKRAVARTI");// circle(300,120,110);
  8. 8. setbkcolor(12);gotoxy(37,5);cout<<"Menu";gotoxy(30,6);cout<<"Stack [s]";gotoxy(30,8);cout<<"Exit [x]";gotoxy(30,10);cout<<"Enter Option [ ]";ch=getche();ch = tolower(ch);gotoxy(30,15);if(ch==s)stack();}while(ch!=x);cleardevice();closegraph();}void loadgraph(){ clrscr(); int driver = DETECT, mode, errorcode;
  9. 9. initgraph(&driver, &mode, "c:tcbgi"); errorcode = graphresult(); if (errorcode != grOk) { cout<<"Graphics error: n"<<(grapherrormsg(errorcode)); cout<<"Press any key to halt:"; getch(); exit(1); }}void stack(){ cleardevice(); moveto(400,60); outtext("STACKS OPERATIONS"); moveto(400,80); outtext("PUSH [p]"); moveto(400,100); outtext("POP [o]"); moveto(400,120); outtext("EXIT [x]"); moveto(300,125); outtext("Top");
  10. 10. itoa(top,string,10);line(150,0,150,415);outtextxy(308,450,string);setbkcolor(3);setcolor(14);outtextxy(55,26,"NOW STACK:");line(30,40,30,440);int r=40;for(int i = 1 ;i<12 ;i++){ line(30,r,110,r); r+=40;}line(110,40,110,440);r = 55;for( i = 10 ;i>=1 ;i--){ moveto(10,r); itoa(i,string,10); outtext(string) ; r+=40;}line(165,440,210,440);
  11. 11. line(165,440,165,460); line(210,440,210,460); line(165,460,210,460); setfillstyle(0, getmaxcolor());char ch[2]; do { moveto(400,140); outtext("ENTER OPTION "); ch[0]=getche(); ch[0] = tolower(ch[0]); if(ch[0]==p) { outtext("p"); delay(500); bar(getx()-30,gety(),getx()+2,gety()+20);if(size<1) { for(int i = 0 ;i<4 ; i++){ moveto(420,170); outtext("Stack Overflow "); delay(1000); setfillstyle(0, getmaxcolor()); bar(420 ,165 ,630 ,180);
  12. 12. delay(500);} }else if( size>1) { size--; top++; push(); bar(290,440,350,479); itoa(top,string,10); outtextxy(308,447,string); }}//end of Nested if else if(ch[0]==o) { outtext("o"); delay(500); bar(getx()-30,gety(),getx()+10,gety()+20);if(size==10) { for(int i = 0 ;i<4 ; i++){
  13. 13. moveto(410,170); outtext("Stack, Underflow "); delay(1000); setfillstyle(0, getmaxcolor()); bar(330 ,165 ,630 ,180); delay(500); } } else { top--; pop(); bar(290,440,350,479); itoa(top,string,10); outtextxy(308,447,string); } }}while(ch[0]!=x);}void push(){ int a=178 , b=425 ;
  14. 14. moveto(178,447); itoa(arr[count],string,10); outtext(string); delay(10); bar(170,446,208,455); itoa(arr[count+1],string,10); moveto(178,447); outtext(string); moveto(a,b);while(gety()!=y) { setfillstyle(0, getmaxcolor()); circle(a+6,b+3,12); itoa(arr[count],string,10); outtext(string); delay(10); setfillstyle(0, getmaxcolor()); bar(170 ,gety()-20 ,200 ,gety()+14); moveto(a,b); b--; } setfillstyle(0, getmaxcolor()); circle(a+6,b+3,9);
  15. 15. outtext(string); moveto(125,b);for(int j =0 ;j<6 ; j++) { outtext("<<--"); delay(100); setfillstyle(0, getmaxcolor()); bar(getx()-3 ,gety() ,getx() ,gety()+8); delay(100); }delay(100); setfillstyle(0, getmaxcolor()); bar(getx()-48 ,gety() ,getx() ,gety()+8);delay(100); delay(200);while(getx()!=x+60) { setfillstyle(0, getmaxcolor()); circle(a+6,b+3,9); itoa(arr[count],string,10); outtext(string); delay(10); setfillstyle(0, getmaxcolor()); bar(getx()-20 ,gety()-10 ,getx()+70 ,gety()+20);
  16. 16. moveto(a,b); a--; } delay(100); moveto(60,gety()); outtext(string); count++; y = y-40;}void pop(){ int a=120, b ; y = y + 40 ; b=y ; moveto(120,y);for(int j=0 ;j<6 ; j++) { outtext("®"); delay(100); setfillstyle(0, getmaxcolor()); bar(getx()-3 ,gety() ,getx() ,gety()+8); delay(100); }
  17. 17. delay(100);setfillstyle(0, getmaxcolor());bar(getx()-48 ,gety() ,getx() ,gety()+8);delay(200);moveto(60,gety());setfillstyle(0, getmaxcolor());bar(getx()-10 ,gety()-3 ,getx()+20 ,gety()+8);delay(500);while(getx()!=178) { setfillstyle(0, getmaxcolor()); circle(a+6,b+3,12); moveto(a,gety()); itoa(arr[count-1],string,10); outtext(string); delay(10); setfillstyle(0, getmaxcolor()); bar(getx()-25 ,gety()-10 ,getx()+30 ,gety()+20); a++; }delay(500);while(gety()!=430) {
  18. 18. setfillstyle(0, getmaxcolor()); circle(a+21,b+3,7); moveto(178,b); itoa(arr[count-1],string,10); outtext(string); delay(10); setfillstyle(0, getmaxcolor()); bar(getx()-30 ,gety()-10 ,getx()+20 ,gety()+9); b++; } delay(10); moveto(178,447); bar(170,446,208,455); count--; moveto(178,447); itoa(arr[count],string,10); outtext(string); size++;}
  19. 19. OUTPUTS1.Menu list:2.Operations in stack:
  20. 20. 3.Push Operation:4.Pop Operations:
  21. 21. REFRENCES1.