728x90 AdSpace

Latest Article



C C++ Program Code Stack push pop with Graphics




C C++ Program Code Implement Stack push pop with Graphics with Menu



#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
int const MAX=6;
void tree(int x,int y);
void inputtower(int,int);
void del(int num,int);
class stack
{
    int list[MAX];
    int top;
  public:
    void init();
    void push ();
    void pop();
    void display();
};
void stack::init()
{
  top=-1;
  for(int i=0;i<MAX;i++)
  list[i]=0;
}
void stack::push()
{
 int num,i,j;
 textcolor(11);
 if(top!=MAX-1)
   {
     for(i=0,j=26;i<MAX;i++,j-=3)
       {
if(list[i]==0)
   {
    gotoxy(59,j);
    cout<<"\xdb\xdb";
   }
else
   {
    gotoxy(59,j);
    cout<<list[i];
   }
}
   do
   {
     gotoxy(2,8);
     cout<<"ENTER A NUMBER:";
     gotoxy(18,8);
     cin>>num;
     gotoxy(18,8);
     cout<<"   ";
     if(num>=100||num<=0)
      {
gotoxy(2,12);
cout<<"NUMBER MUST BE 1-99 RANGE:";
      }
    }while(num>=100||num<=0);
    list[++top]=num;
    switch(top)
    {
     case 0:
   inputtower(num,26);
   break;
     case 1:
   inputtower(num,23);
   break;
     case 2:
   inputtower(num,20);
   break;
     case 3:
   inputtower(num,17);
   break;
     case 4:
   inputtower(num,14);
   break;
     case 5:
   inputtower(num,11);
   break;
     }
   }
   else
    {
      gotoxy(2,8);
      cout<<"FULL TOWER             ";
      for(i=0,j=26;i<MAX;i++,j-=3)
       {
gotoxy(59,j);
cout<<list[i];
       }
    }
}
void stack::pop()
{
  int i ,j;
  for(i=MAX-1,j=0;i>0;i--,j=j+3)
  {
   if(list[i]==0)
    {
     gotoxy(59,11+j);
     cout<<"\xdb\xdb";
    }
  }
  if(top==-1)
   {
    gotoxy(4,10);
    cout<<"STACK IS EMPTY";
   }
  else
   {

    switch(top)
    {
       case 0:
    del(list[top--],26);
    gotoxy(59,26);
    cout<<"\xdb\xdb";
    break;
       case 1:
    gotoxy(59,26);
    cout<<list[0];
    del(list[top--],23);
    gotoxy(59,23);
    cout<<"\xdb\xdb";
    break;
      case 2:
    gotoxy(59,26);
    cout<<list[0];
    gotoxy(59,23);
    cout<<list[1];
    del(list[top--],20);
    gotoxy(59,20);
    cout<<"\xdb\xdb";
    break;
      case 3:
    gotoxy(59,26);
    cout<<list[0];
    gotoxy(59,23);
    cout<<list[1];
    gotoxy(59,20);
    cout<<list[2];
    del(list[top--],17);
    gotoxy(59,17);
    cout<<"\xdb\xdb";
    break;
      case 4:
    gotoxy(59,26);
    cout<<list[0];
    gotoxy(59,23);
    cout<<list[1];
    gotoxy(59,20);
    cout<<list[2];
    gotoxy(59,17);
    cout<<list[3];
    del(list[top--],14);
    gotoxy(59,17);
    cout<<"\xdb\xdb";
    break;
      case 5:
    gotoxy(59,26);
    cout<<list[0];
    gotoxy(59,23);
    cout<<list[1];
    gotoxy(59,20);
    cout<<list[2];
    gotoxy(59,17);
    cout<<list[3];
    gotoxy(59,14);
    cout<<list[4];
    del(list[top--],11);
    gotoxy(59,11);
    cout<<"\xdb\xdb";
    break;
      }
      list[top+1]=0;
    }
}
void stack::display()
{
  int i,j;
  for(i=0,j=26;i<MAX;i++,j-=3)
    {
      if(list[i]==0)
       {
gotoxy(59,j);
cout<<"\xdb\xdb";
       }
       else
       {
gotoxy(59,j);
cout<<list[i];
       }
    }
}
  //////////////////////////MAIN FUNCTION /////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
void main(void)
{
  stack s1;
  int chmain,x,y,j,i;
  s1.init();
  clrscr();
  do
  {
   clrscr();
   gotoxy(23,10);
   cout<<"<*/|\\*> STACK MENU <*/|\\*>";
   gotoxy(32,14);
   cout<<"1.PUSH";
   gotoxy(32,16);
   cout<<"2.POP";
   gotoxy(32,18);
   cout<<"3.DISPLAY";
   gotoxy(32,20);
   cout<<"4.EXIT";
   gotoxy(27,24);
   cout<<"Enter choice [   ]";
   gotoxy(42,24);
   cin>>chmain;
   clrscr();
   switch(chmain)
   {
    case 1:
 for(x=0,y=25,j=15;x<11;x+=2,y-=3,j--)
  {
    textcolor(j);
    tree( x, y);
  }
 s1.push();
 getch();
 break;
    case 2:
 for(x=0,y=25,j=15;x<11;x+=2,y-=3,j--)
  {
    textcolor(j);
    tree( x, y);
  }
 s1.pop();
 getch();
 break;
    case 3:
 for(x=0,y=25,j=15;x<11;x+=2,y-=3,j--)
  {
     textcolor(j);
     tree( x, y);
  }
 s1.display();
 getch();
 break;
    case 4:
 exit(0);
   }
  }while(chmain<4);
getch();
}
  /////////////////////////////END MAIN///////////////////////////////
  ///////////////////////////////////////////////////////////////////////
void tree(int x,int y)
{
 for(int i=47+x;i<72-x;i++)
   {
     gotoxy(i,y);
     cprintf("\xdb");
     gotoxy(i,y+1);
     cprintf("\xdb");
     gotoxy(i,y+2);
     cprintf("\xdb");
   }
}
void inputtower(int num,int pos)
{
  int x,y,j,i;
  for( i=20;i<58;i++)
  {
   delay(50);
   gotoxy(i,9);
   cprintf("\x03");
   cprintf("%d",num);
  }
  gotoxy(58,9);
  cout<<"\x03\x03";
  for( i=10;i<pos;i++)
   {
    delay(50);
    gotoxy(59,i);
    cout<<"\x03";
    gotoxy(59,i+1);
    cout<<num;
    gotoxy(60,i);
    cout<<"\xdb";
   }
  for( i=20;i<59;i++)
   {
    gotoxy(i,9);
    cout<<"  ";
   }
  for( i=10;i<pos;i++)
   {
    gotoxy(59,i);
    cout<<"\xdb\xdb";
  }
} /////////////////////////////////////
void del(int num,int pos)
{
 int i,x,y,j;
 for(i=15;i<19;i++)
  {
   gotoxy(10,i);
   cout<<"ÛÛÛÛÛÛÛÛÛ";
  }
 textcolor(2);
 gotoxy(11,16);
 cprintf("RECYCLE");
 gotoxy(13,17);
 cprintf("BIN");
 textcolor(15);
 for( i=pos;i>10;i--)
  {
   delay(50);
   gotoxy(59,i);
   cout<<"\x03";
   gotoxy(59,i-1);
   cout<<num;
   gotoxy(60,i);
   cout<<"\xdb";
  }
 gotoxy(60,8);
 cout<<"  ";
 gotoxy(59,10);
 cout<<"\x03\xdb";
 for( i=57;i>13;i--)
  {
   delay(50);
   gotoxy(i,9);
   cprintf("%d",num);
   cprintf("\x03");
  }
 gotoxy(14,9);
 cout<<"\x03\x03";
 for( i=10;i<14;i++)
  {
   delay(50);
   gotoxy(14,i);
   cout<<"\x03";
   gotoxy(14,i+1);
   cout<<num;
   gotoxy(15,i);
   cout<<"  ";
  }
 for( i=pos;i>9;i--)
  {
    gotoxy(59,i);
    cout<<"\xdb";
    gotoxy(60,i);
    cout<<"\xdb";
  }
 for( i=58;i>13;i--)
  {
   gotoxy(i,9);
   cprintf("  ");
  }
 for( i=10;i<15;i++)
  {
   gotoxy(14,i);
   cout<<"  ";
   gotoxy(15,i);
   cout<<"  ";
  }
}

no image
  • Title : C C++ Program Code Stack push pop with Graphics
  • Posted by :
  • Date : 04:18
  • Labels :






  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment