Monday 25 April 2011

program stack dengan animasi dengan menu (push, pop, clear, exit) di c++


//nama: I Wayan Agus Gerdian
#include<iostream.h>
#include<conio.h>

char stack[10];
int tdc,i;
char answer,tmp,e;
void speed();


void push1()
{
   for(i=0;i<=17; i++)
    {
        gotoxy(22+i,7);cout<<" ";
        gotoxy(23+i,7); cout<<tmp; speed();
    }
     for(i=1;i<=(14-tdc);i++)
     {
          speed();
          gotoxy(40,6+i); cout<<" ";
          gotoxy(40,7+i); cout<<tmp;
     }
}

void pop1(char temp)
{
    for(i=1;i<=(14-tdc);i++)
     {
          speed();
          gotoxy(40,22-i-tdc); cout<<" ";
          gotoxy(40,21-i-tdc); cout<<tmp;
     }
     for(i=1;i<=19;i++)
     {
          speed();
          gotoxy(38+i,7); cout<<" ";
          gotoxy(39+i,7); cout<<tmp; speed();
     }
     gotoxy(58,7);cout<<" ";
}

void push(char e)
{
     tdc=tdc+1;
     stack[tdc]=e;
     push1();
}
void pop(char e)
{
     if(tdc !=0)
     {
          gotoxy(1,7); cout<<"              "<<endl;
          e=stack[tdc]; pop1(e);
          tdc=tdc-1;
     }
     else
     {
          gotoxy(1,7); cout<<"stack kosong!"<<endl;
          gotoxy(1,7);
     }
}

void main()
{
   clrscr();
    cout<<"program stack dengan animasi"<<endl;
    cout<<"1.push--> memasukkan data"<<endl;
    cout<<"2.pop---> mengambil data"<<endl;
    cout<<"3.clear-> membersihkan data"<<endl;
    cout<<"4.exit--> keluar"<<endl;
   //cout<<"pilih [1/2/3/4] ="<<endl;


   clear:
      gotoxy(59,6); cout<<"-";
      gotoxy(59,9); cout<<"_";
      gotoxy(37,10); cout<<"||   ||";
      for(i=1;i<=11;i++)
      {
        gotoxy(38,10+i);
       if(i==11)
       cout<<"|___|";
       else
       cout<<"|   |";
      }
   tdc=0;
   do
   {
       input:
       gotoxy(1,6);
       cout<<"masukkan pilihan anda[1/2/3/4] : ";
       answer=getche();
       if(int(answer)==27 || answer=='4')
       break;
       else if(answer=='1')
         {
      if(tdc != 7)
      {
            gotoxy(1,7); cout<<"masukkan suatu huruf : ";
            cin>>tmp;
            push(tmp);
            gotoxy(1,7); cout<<"                    ";
      }
      else
      {
           gotoxy(1,7); cout<<"stack penuh!";
           getch();
           gotoxy(1,7); cout<<" ";
         }
    }
   else if(answer=='2')
   pop(tmp);
   else if(answer=='3')
   goto clear;
   else
   goto input;
   }
   while(1);

 getch();
}

void speed()
{
     for(int y=1;y<77;y++)
     for(int x=1;x<77;x++)
     for(int p=1;p<77;p++)
     cout<<"";
}



4 comments:

  1. Bagus bener materinya.. nyambung nicchh ama study nya

    ReplyDelete
  2. Gan if(int(answer)==27||answer=='4') itu maksudnya apa mohon pencerahannya. Terima kasih

    ReplyDelete
  3. This is a topic that's near to my heart... Best wishes! Where are your contact details though?

    ReplyDelete

Komentar sobat akan saya hapus jika:

- Mengandung unsur SPAM
- LINK hidup
- tidak sesuai dengan topik

NB:
jika ingin menyisipkan LINK ,silahkan pilih Name/URL pada option profil !