sub_menu

Minggu, 13 Januari 2013

contoh contoh program borland c++ 1

contoh program program borland c++ 
di jamin benar:

1. nested if ,goto.

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{ char kode,waktu,jawab,nama_film[20],nama_pen[15];
float harga,beli,bayar,pot,ppn,total,u_byr,u_kmb;
film:
clrscr ();
gotoxy(17,1);printf("******THeaTHeR FiLM ABC******");
gotoxy(15,4);printf("Nama Penonton : ");scanf("%s",&nama_pen);
gotoxy(15,5);printf("Kode Theater [1/2/3] : ");scanf("%s",&kode);
gotoxy(15,7);cout<<"Waktu Tayang [P/S/M] : ";cin>>waktu;

if(kode=='1')
{ strcpy(nama_film,"Tusuk Jaelangkung");

if(waktu=='p'||waktu=='P')
harga=17500;
else if(waktu=='s'|| waktu=='S')
harga=20000;
else
harga=22500;
}
else if(kode=='2')
{ strcpy(nama_film,"The Matrix");

if(waktu=='p'||waktu=='P')
harga=18000;
else if(waktu=='s'|| waktu=='S')
harga=20000;
else
harga=25000;
}
else
{ strcpy(nama_film,"Spiderman");

if(waktu=='p'||waktu=='P')
harga=20000;
else if(waktu=='s'|| waktu=='S')
harga=22500;
else
harga=25000;
}

gotoxy(15,6);printf("Nama Film : %s",nama_film);
gotoxy(15,8);printf("Harga Tiket : %.0f",harga);
gotoxy(15,9);printf("Jumlah Pembelian Tiket : ");scanf("%f",&beli);
gotoxy(15,10);printf("********************************");

bayar=harga*beli;

if(beli>=5)
pot=0.10*bayar;
else
pot=0;

ppn=0.5*bayar;
total=(bayar-pot)+ppn;

gotoxy(15,11);printf("Pembayaran : %.0f",bayar);
gotoxy(15,12);printf("Potongan : %.0f",pot);
gotoxy(15,13);printf("PPN : %.0f",ppn);
gotoxy(15,14);printf("Total Bayar : %.0f",total);
gotoxy(15,15);printf("********************************");
lagi:

gotoxy(15,16);printf("Uang Bayar : ");cin>>u_byr;

if (u_byr<total)

{goto lagi;
u_byr=0 ;
printf("%d",u_byr) ;
}
else

u_kmb=u_byr-total;
gotoxy(15,17);printf("Uang Kembali : %.0f",u_kmb);
gotoxy(13,19);printf("TeRiMa KaSiH AnDa TeLaH DaTaNG Ke CouNTeR KaMi");

gotoxy(15,22);printf("Input Data Lagi [Y/T] :");jawab=getche();
if(jawab=='Y'||jawab=='y')
goto film ;
getche();

}

 2.  array,if else, case and break.
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>


char nama[25],kt[15][20],lg,tj[5][15],kls[5][15],tgl_pmb[25];
int bt,i,kk[15],harga[15],sub_total[15],hargai[15],jt[10],ub,kmb,total;

garis()
{cout<<"\n--------------------------------------------------------------\n";}

main()
{
atas:
clrscr();
cout<<"\t\t ***PENJUALAN TIKET BUS***"<<endl;
garis();
cout<<"Kode Tujuan :  Tujuan    : Kode Kelas :  Kelas    :  Harga"<<endl;
garis();
cout<<"   BDG      :  BANDUNG   :     1      : Eksekutif : RP.100.000"<<endl;
cout<<"            :            :     2      : Bisnis    : RP. 80.OOO"<<endl;
cout<<"            :            :     3      : Ekonomi   : RP. 50.000"<<endl;
garis();
cout<<"   SMG      :  SEMARANG  :     1      : Eksekutif : RP.150.000"<<endl;
cout<<"            :                               :     2      : Bisnis    : RP.100.OOO"<<endl;
cout<<"            :                               :     3      : Ekonomi   : RP. 80.000"<<endl;
garis();
cout<<"   SDJ   :  SIDOARJO  :     1      : Eksekutif : RP.200.000"<<endl;
cout<<"            :            :     2      : Bisnis    : RP.150.OOO"<<endl;
cout<<"            :            :     3      : Ekonomi   : RP.100.000"<<endl;
garis();
cout<<"\n\t\t>Tanggal Pembelian:";gets(tgl_pmb);
cout<<"\n\t\t>Nama Pembeli     :";gets(nama);
cout<<"\n\t\t>Banyak Tujuan    :";cin>>bt;
cout<<"\n\t\t--------------------------------";
for (i=1;i<=bt;i++)
{
cout<<"\n\t\t>Tujuan Ke -"<<i<<endl;
cout<<"\n\t\t>Kode Tujuan      :";cin>>kt[i];
cout<<"\n\t\t>Kode Kelas       :";cin>>kk[i];
if (strcmpi(kt[i],"BDG")==0)
switch (kk[i])
{
case 1:strcpy(tj[i],"BANDUNG");strcpy(kls[i],"Eksekutif");harga[i]=100000;break;
case 2:strcpy(tj[i],"BANDUNG");strcpy(kls[i],"Bisnis");harga[i]=80000;break;
case 3:strcpy(tj[i],"BANDUNG");strcpy(kls[i],"Ekonomi");harga[i]=50000;break;
default:strcpy(tj[i],"Kode Salah");strcpy(kls[i],"Kode Salah");harga[i]=0;break;
}
else
if (strcmpi(kt[i],"SMG")==0)
switch (kk[i])
{
case 1:strcpy(tj[i],"SEMARANG");strcpy(kls[i],"Eksekutif");harga[i]=150000;break;
case 2:strcpy(tj[i],"SEMARANG");strcpy(kls[i],"Bisnis");harga[i]=100000;break;
case 3:strcpy(tj[i],"SEMARANG");strcpy(kls[i],"Ekonomi");harga[i]=80000;break;
default:strcpy(tj[i],"Kode Salah");strcpy(kls[i],"Kode Salah");harga[i]=0;break;
}
else
if (strcmpi(kt[i],"SDJ")==0)
switch (kk[i])
{
case 1:strcpy(tj[i],"SIDOARJO");strcpy(kls[i],"Eksekutif");harga[i]=200000;break;
case 2:strcpy(tj[i],"SIDOARJO");strcpy(kls[i],"Bisnis");harga[i]=150000;break;
case 3:strcpy(tj[i],"SIDOARJO");strcpy(kls[i],"Ekonomi");harga[i]=100000;break;
default:strcpy(tj[i],"Kode Salah");strcpy(kls[i],"Kode Salah");harga[i]=0;break;
}
else
strcpy(tj[i],"Kode Salah");
cout<<"\n\t\tJumlah Tiket      :";cin>>jt[i];
sub_total[i]=(harga[i]*jt[i]);
total=total+sub_total[i];
}
cout<<endl;
cout<<endl;
cout<<"\t\t === STRUK PEMBAYARAN BUS ==="<<endl;
cout<<"\n>Tanggal Pembelian:"<<tgl_pmb<<endl;
cout<<"\n>Nama Pembeli     :"<<nama<<endl;
cout<<"\n\n";
garis();
cout<<"No :Tujuan      :Kelas       :Harga Satuan:Tiket  :Subtotal"<<endl;
garis();
for (i=1;i<=bt;i++)
{
cout<<setiosflags(ios::left)<<setw(3)<<i;
cout<<setiosflags(ios::left)<<":"<<setw(12)<<tj[i];
cout<<setiosflags(ios::left)<<":"<<setw(12)<<kls[i];
cout<<setiosflags(ios::left)<<setprecision(15)<<":"<<"RP."<<setw(9)<<harga[i];
cout<<setiosflags(ios::left)<<setprecision(15)<<":"<<setw(7)<<jt[i];
cout<<setiosflags(ios::left)<<setprecision(15)<<":"<<"RP."<<setw(9)<<sub_total[i]<<endl;
}
garis();
cout<<"\n\t\t\t\t\tTotal     :RP."<<total;
cout<<"\n\t\t\t\t\tUang Bayar:RP.";cin>>ub;
kmb=ub-total;
cout<<"\n\t\t\t\t\t\t______________-";
cout<<"\n\t\t\t\t\tKembali   :RP."<<kmb;
cout<<endl;
cout<<"\n\t\t\t***TERIMA KASIH***";
cout<<"\n\tIngin Melakukan Penjualan Tiket Bus Lagi[Y/N]=";cin>>lg;
if (lg=='Y'||lg=='y')
goto atas;
else
getch();
}
3. fungsi, array,struct.
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
garis()
{
cout<<""<<endl;
}
main()
{
struct
{
char nm[20];
float kdmenu,h,jb,th;
}menu[10] ;
int i,j;
clrscr();
cout<<"\t\tDAFTAR MENU MAKANAN"<<endl;
cout<<"\t\t1. Soto Ceker "<<endl;
cout<<"\t\t2. Mie Aceh"<<endl;
cout<<"\t\t3. Bakso Solo"<<endl;garis();
cout<<"\t\tMasukan Jumlah Data : ";cin>>j;
garis();
for (i=1;i<=j;i++)
{
cout<<"Data Ke - : "<<i<<endl;
cout<<"Pilih Menu [1/2/3] : ";cin>>menu[i].kdmenu;
cout<<"Jumlah Beli : ";cin>>menu[i].jb;
if (menu[i].kdmenu==1)
{
strcpy(menu[i].nm,"Soto Ceker");
menu[i].h=11000;
}
else if (menu[i].kdmenu==2)
{
strcpy(menu[i].nm,"Mie Aceh");
menu[i].h=12000;
}
else
{
strcpy(menu[i].nm,"Bakso Solo");
menu[i].h=13000;
}
menu[i].th=menu[i].jb*menu[i].h;
}
cout<<endl;
cout<<"\t\tRESTO QT@ - QT@"<<endl;
garis();
cout<<"No. Nama      Harga/       Jumlah       Total "<<endl;
cout<<" Makanan      Porsi        Beli         Harga "<<endl;
garis();
for (i=1;i<=j;i++)
{
cout<<setiosflags(ios::left)<<setw(2)<<i;
cout<<setprecision(5)<<" "<<menu[i].nm;
cout<<setprecision(5)<<" "<<"Rp"<<ends<<menu[i].h;
cout<<setprecision(5)<<" "<<menu[i].jb;
cout<<setprecision(5)<<" "<<"Rp"<<ends<<menu[i].th;
cout<<endl;
}
getch();
}
yang lainnya silahkan tunggu



Tidak ada komentar:

Poskan Komentar

silahkan masukan komentar