™[]Sumber Pembuat,Author,Created,dll sudah ada Di dalam Rarnya[]™

™[]Klik Judul postingan untuk melihat Isi selengkapnya!![]™

Kamis, 17 November 2011

0 Contoh program Animasi Stack C++


#include <iostream.h>
#include <conio.h>
 #include <stdlib.h>

 int top,i;
 char key,temp,e;
char stack[10];
 void delay();

 void pushanim()
{
for(i=0;i<=17; i++)
 {
gotoxy(22+i,7);cout<<" ";
gotoxy(23+i,7); cout<<temp; delay();

}
for(i=1;i<=(14-top);i++)
{
delay();
gotoxy(40,7+i); cout<<" ";
 gotoxy(40,21); cout<<temp;
}
}

void popanim(char temp)
{
for(i=1;i<=(14-top);i++)
{
delay();
 gotoxy(40,22-i-top); cout<<” “;
gotoxy(40,21-i-top); cout<<temp;
}
for(i=1;i<=19;i++)
{
delay();
gotoxy(38+i,7); cout<<” “;
gotoxy(39+i,7); cout<<temp; delay();
}
gotoxy(58,7);cout<<” “;
}

void push(char e)
{
top=top+1;
stack[top]=e;
pushanim();
}
void pop(char e)
{
if(top !=0)
{
e=stack[top]; popanim(e);
top=top-1;
}
else
{
gotoxy(1,7);  cout<<”stack telah kosong”<<endl;
gotoxy(1,7);
}
}

Void main()
{
Clrscr();
Cout<<”animasi stack”<<endl;
Cout<<”1.push”<<endl;
Cout<<”2.pop”<<endl;
Cout<<”3.quit”<<endl;
//cout<<”pilih [1/2/3]=”<<endl;
gotoxy(59,6); cout<<”=”;
gotoxy(59,8);  cout<<”=”;
gotoxy(37,9); cout<<”||  ||”;
for(i=1;i<=11;i++)
{
gotoxy(38,10+i);
if(i==11)
cout<<”|__|;
else
cout<<”|  |”;
}
top=0;
do
{
Input:
gotoxy(1,5);
cout<<”masukan pilihan anda[1/2/3] : “;
key=getche();
if(int(key)==27 | | key==’3’)
break;
else if(key==’1’)
{
If(top !=10)
{
Gotoxy(1,7); cout<<”masukan suatu huruf : “;
Cin>>temp;
Push(temp);
Gotoxy(1,7); cout<<”          “;
}
else
{
gotoxy(1,7); cout<<”stack penuh”;
getch();
gotoxy(1,7); cout<<”  “;
}
}
else if(key==’2’)
pop(temp);
else
goto input;
}while(1);

getch();
}

Void delay()
{
For(int y=1;y<100;y++)
For(int x=1;x<100;x++)
For(int p=1; p<100;p++)
Cout<<””;
}

0 komentar:

Posting Komentar