Thursday, 21 May 2015

Contoh C++ pemesanan tiket

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
int i,j,jbeli[20],tjbeli=0;
char nama[20][20],kode[20];
long harga[20],diskon,totalp,gtotal=0,total[20];
puts("\t\tDAFTAR PENJUALAN TIKET");
puts("=========================================");
cout<<"Masukkan Banyaknya Data : ";cin>>j;

for(i=1;i<=j;i++)
{cout<<endl;
cout<<"Data Ke-"<<i<<endl;
cout<<"Masukkan Kode Kereta(A/B/T) : ";cin>>kode[i];
if (kode[i]=='A')
{strcpy(nama[i],"Argo Lawu");
harga[i]=300000;}
else if(kode[i]=='B')
{strcpy(nama[i],"Argo Bromo");
harga[i]=250000;}
else if (kode[i]=='T')
{strcpy(nama[i],"Taxaca");
harga[i]=200000;}
else
{strcpy(nama[i],"Kode salah");
harga[i]=0;}

cout<<"Nama Kereta : "<<nama[i]<<endl;
cout<<"Harga Tiket : "<<harga[i]<<endl;
cout<<"Jumlah Beli : ";cin>>jbeli[i];

total[i]=harga[i]*jbeli[i];
gtotal=gtotal+total[i];

tjbeli=tjbeli+jbeli[i];
}

//keluaran
clrscr();
puts("\t\tDAFTAR PENJUALAN TIKET");
puts("=========================================================");
puts("NO Kode Nama Harga Jumlah Total");
puts(" Tiket Kereta Tiket Beli");
puts("=========================================================");

for(i=1;i<=j;i++)
{

cout<<setiosflags(ios::left)<<setw(5)<<i;
cout<<setiosflags(ios::left)<<setw(10)<<kode[i];
cout<<setiosflags(ios::left)<<setw(12)<<nama[i];
cout<<setiosflags(ios::right)<<setw(8)<<harga[i];
cout<<setiosflags(ios::right)<<setw(11)<<jbeli[i];
cout<<setiosflags(ios::right)<<setw(8)<<total[i]<<endl;


}
puts("=========================================================");
cout<<"Grand Total Rp "<<gtotal<<endl;
cout<<"Total Jumlah Beli "<<tjbeli<<endl;
if(tjbeli>5)
diskon=0.1 * gtotal;
else
diskon=0;
cout<<"Diskon Rp "<<diskon<<endl;
puts("=========================================================");
totalp = gtotal-diskon;
cout<<"Total Pembayaran Rp "<<totalp;
getch() ;
}

No comments:

Post a Comment