Wednesday, January 23, 2013
Contoh Listing Fungsi Garis dan Hitung pada C++
#
#
#
#
//membuat fungsi garis
garis()
{
cout<<"-----------------------------------------"<<endl;
}
//membuat fungsi hitung
float hitung(float a, float b)
{
return(a*b);
}
//membuat fungsi bayar
float bayar(float a, float b)
{
return(a+b);
}
//program utama
main()
{
char np[20], *nk[30], kd[30], lagi;
float hrg[30], jml[30], byr[30], tb=0;
int i, j;
awal:
clrscr();
cout<<" TOKO KUE \"WUEENAK\""<<endl;
cout<<"JL. Kalibata Timur No.37 telp (021) 7901074"<<endl;
garis();
cout<<"Masukan Nama Pembeli : ";cin>>np;
cout<<"Masukan Jumlah Data : ";cin>>j;
cout<<endl;
for(i=1;i<=j;i++)
{
cout<<"Data ke- "<<endl;
cout<<"Kode Kue : ";cin>>kd[i];
if(kd[i]=='A'||kd[i]=='a')
{
nk[i]="Brownies";
hrg[i]=15000;
}
else if(kd[i]=='B'||kd[i]=='b')
{
nk[i]="Cake";
hrg[i]=25000;
}
else if(kd[i]=='C'||kd[i]=='c')
{
nk[i]="Keju";
hrg[i]=20000;
}
else
{
cout<<"\tkode yang anda masukan salah!!!, input [A/B/C]! "<<endl;
cout<<endl<<endl;
cout<<"\tMau input data lagi [Y/T] = ";cin>>lagi;
if(lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
}
cout<<" Nama Kue : "<<nk[i]<<endl;
cout<<" Harga Kue : "<<hrg[i]<<endl;
cout<<" Jumlah Beli : ";cin>>jml[i];
byr[i]= hitung(jml[i],hrg[i]); //deklarasi fungsi hitung
cout<<" Jumlah Bayar : "<<byr[i]<<endl;
tb=bayar(byr[i],tb); //deklarasi fungsi bayar
}
clrscr();
cout<<endl<<endl;
cout<<" LAPORAN PENJUALAN TOKO KUE \"WUEENAAK\""<<endl;
cout<<" JL. Cileduk Raya No.168 telp (021) 7901074"<<endl;
cout<<endl;
cout<<" Nama Pembeli : "<<np<<endl;
cout<<" ================================================"<<endl;
cout<<" No. Kode Nama Harga Jumlah Jumlah "<<endl;
cout<<" Kue Kue Kue Beli Bayar "<<endl;
cout<<" ================================================"<<endl;
for(i=1;i<=j;i++)
{
cout<<setiosflags(ios::left)<<setw(5)<<i;
cout<<setiosflags(ios::left)<<setw(6)<<kd[i];
cout<<setiosflags(ios::left)<<setw(10)<<nk[i];
cout<<setiosflags(ios::left)<<setw(12)<<hrg[i];
cout<<setiosflags(ios::left)<<setw(6)<<jml[i];
cout<<setiosflags(ios::left)<<setw(10)<<byr[i]<<endl;
}
cout<<"================================================="<<endl;
cout<<" Total Bayar : "<<tb<<endl;
cout<<endl<<endl;
cout<<"\tMau input data lagi [Y/T] = ";cin>>lagi;
if(lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
akhir:
clrscr();
cout<<endl;
cout<<"TERIMA KASIH ATAS KEDATANGANNYA";
getch();
}
Silakan Download Disini :
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment