Nah ini Merupakan Salah satu contoh program C++ ,jalankan program ini kedalam Borland C++ atau turbo dll.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
void tunggu(void)
{
long int i;
for(i=0; i<6e7; i++);
}
main()
{
int x,y,bil;
int A[5];
char jwb;
char tmbl;
clrscr();
awal:
textcolor(15);
cprintf("Jalur yang dilalui mobil");cout<<endl;
cout<<endl<<endl;
cout<<setw(29)<<"depan"<<"\n"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(45)<<"_______________| |_______________"<<endl;
cout<<setw(30)<<endl;
cout<<setw(51)<<"kiri X kanan"<<endl;
cout<<setw(45)<<"_______________ _______________"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl<<endl;
cout<<setw(30)<<"belakang"<<"\n"<<endl;
cout<<endl;
textcolor(90);
cprintf("Keterangan : X = posisi awal mobil");cout<<endl;
cout<<endl;
cprintf("tekan huruf [n/N] untuk melanjutkan....");
cin>>tmbl;
clrscr();
if(tmbl=='n' || tmbl=='N')
goto next;
else
cout<<"error!!!";
goto keluar;
next:
textcolor(15);
cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");cout<<endl;
textcolor(15);
cprintf("ketik 0x dahulu kemudian masukan salah satu karakter yang ada di bawah ini");cout<<endl;
cprintf("(hanya boleh memasukan satu digit)dari data yang ada");cout<<endl;
cprintf("Silahkan memilih angka/huruf yang anda inginkan:");cout<<"\n"<<endl;
cprintf(" 0");cout<<endl;
cprintf(" 1");cout<<endl;
cprintf(" 2");cout<<endl;
cprintf(" 3");cout<<endl;
cprintf(" 4");cout<<endl;
cprintf(" 5");cout<<endl;
cprintf(" 6");cout<<endl;
cprintf(" 7");cout<<endl;
cprintf(" 8");cout<<endl;
cprintf(" 9");cout<<endl;
cprintf(" a/A");cout<<endl;
cprintf(" b/B");cout<<endl;
cprintf(" c/C");cout<<endl;
cprintf(" d/D");cout<<endl;
cprintf(" e/E");cout<<endl;
cprintf(" f/F");cout<<endl;
cout<<"\nSilahkan ketikan 0x lalu ketikan karakter.Contoh(0xf)!!!"<<endl;
cin>>bil;
if(bil>7 && bil<=15 )
{
bil=bil-8;
A[1]=1;
}
else
{
A[1]=0;
}
if(bil>3 && bil<=7 )
{
bil=bil-4;
A[2]=1;
}
else
{
A[2]=0;
}
if(bil>1 && bil<=3)
{
bil=bil-2;
A[3]=1;
}
else
{
A[3]=0;
}
if(bil>0 && bil<=1)
{
bil=bil-1;
A[4]=1;
}
else
{
A[4]=0;
}
clrscr();
textcolor(30);
cprintf("Arah gerak mobil adalah : ");cout<<endl<<endl;
cprintf("**************************");
cout<<"\n\n";
cout<<setw(29)<<"depan"<<"\n"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(45)<<"_______________| |_______________"<<endl;
cout<<setw(30)<<endl;
cout<<setw(52)<<"kiri kanan"<<endl;
cout<<setw(45)<<"_______________ _______________"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl<<endl;
cout<<setw(30)<<"belakang"<<"\n"<<endl;
int i;
//A[1]=depan
if(A[1]==1)
{
i=0;
do
{
x=27; y=16-i;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27; y=16-i;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<10);
}
else
{
cout<<"";
}
//A[2]=belakang
if(A[2]==1)
{
i=0;
do
{
x=27; y=16+i;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27; y=16+i;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<10);
}
else
{
cout<<"";
}
//A[3]=kiri
if(A[3]==1)
{
i=0;
do
{
x=27-i; y=16;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27-i; y=16;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<19);
}
else
{
cout<<"";
}
//A[4]=kanan
if(A[4]==1)
{
i=0;
do
{
x=27+i; y=16;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27+i; y=16;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<19);
}
else
{
cout<<"";
}
x=1;
y=25;
gotoxy(x,y);
textcolor(13);
cout<<endl;
cprintf("********************************************************************");cout<<endl;
textcolor(13);
cprintf("apakah anda ingin mencoba lagi [y/t]??? ");
cin>>jwb;
cout<<endl;
textcolor(13);
cprintf("*********************************************************************");
clrscr();
if(jwb=='y' || jwb=='Y')
goto awal;
keluar:
getch();
}
Selamat Mencoba !!